MSP430FR5594 用库函数实现定时器触发AD问题请教
<p>我用的芯片是MSP430FR5994,使用的是库函数<br />我AD用软件触发没有问题,能进入中断<br />
但是我用定时器触发就不行了<br />
定时器单独跑也没有问题,PWM信号 IO脚也出来了<br />
但是AD 用定时器触发就是不行</p>
<p>//*****************************************************************************<br />
// * main.c<br />
// ******************************************************************************<br />
int main(void)<br />
{<br />
WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer<br />
<br />
PMM_unlockLPM5();<br />
CS_init();<br />
IO_Init();<br />
Timer_Init();<br />
Ad_init();</p>
<p> while(1)<br />
{</p>
<p>// ADC12_B_startConversion(ADC12_B_BASE, ADC12_B_MEMORY_0, ADC12_B_SINGLECHANNEL);</p>
<p> //LPM0, ADC12_A_ISR will force exit<br />
__bis_SR_register(LPM0_bits + GIE);<br />
//for Debugger<br />
__no_operation();</p>
<p><br />
GPIO_setOutputLowOnPin(GPIO_PORT_P2,GPIO_PIN0);</p>
<p> GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0);<br />
}</p>
<p> return 0;</p>
<p>}</p>
<p>//*****************************************************************************<br />
// * main.c<br />
// ******************************************************************************<br />
void CS_init()<br />
{<br />
// Set PJ.4 and PJ.5 as Secondary Module Function Input, LFXT.<br />
/* Initializes Clock System DCO = 8MHz */</p>
<p><br />
CS_setDCOFreq(CS_DCORSEL_0, CS_DCOFSEL_3);<br />
CS_initClockSignal(CS_MCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2);<br />
CS_initClockSignal(CS_SMCLK, CS_DCOCLK_SELECT, CS_CLOCK_DIVIDER_2 );<br />
CS_initClockSignal(CS_ACLK, CS_VLOCLK_SELECT, CS_CLOCK_DIVIDER_1);</p>
<p>}</p>
<p>//*****************************************************************************<br />
// * main.c<br />
// ******************************************************************************</p>
<p>void Ad_init(void)<br />
{<br />
ADC12_B_initParam param1 = {0};<br />
ADC12_B_configureMemoryParam param = {0};</p>
<p> GPIO_setAsPeripheralModuleFunctionOutputPin(<br />
GPIO_PORT_P3,<br />
GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3,<br />
GPIO_TERNARY_MODULE_FUNCTION<br />
);</p>
<p><br />
// param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_SC;<br />
param1.sampleHoldSignalSourceSelect=ADC12_B_SAMPLEHOLDSOURCE_1;<br />
param1.clockSourceSelect=ADC12_B_CLOCKSOURCE_MCLK;<br />
param1.clockSourceDivider=ADC12_B_CLOCKDIVIDER_1;<br />
param1.clockSourcePredivider=ADC12_B_CLOCKPREDIVIDER__1;<br />
param1.internalChannelMap=ADC12_B_NOINTCH;</p>
<p> ADC12_B_init(ADC12_B_BASE,&param1);</p>
<p> ADC12_B_setupSamplingTimer(ADC12_B_BASE,<br />
ADC12_B_CYCLEHOLD_64_CYCLES,<br />
ADC12_B_CYCLEHOLD_4_CYCLES,<br />
ADC12_B_MULTIPLESAMPLESENABLE);</p>
<p><br />
param.memoryBufferControlIndex = ADC12_B_MEMORY_0;<br />
param.inputSourceSelect = ADC12_B_INPUT_A12;<br />
param.refVoltageSourceSelect = ADC12_B_VREFPOS_AVCC_VREFNEG_VSS;<br />
param.endOfSequence = ADC12_B_NOTENDOFSEQUENCE;<br />
param.windowComparatorSelect = ADC12_B_WINDOW_COMPARATOR_DISABLE;<br />
param.differentialModeSelect = ADC12_B_DIFFERENTIAL_MODE_DISABLE;<br />
ADC12_B_configureMemory(ADC12_B_BASE ,&param);</p>
<p><br />
ADC12_B_clearInterrupt(ADC12_B_BASE,ADC12IFG0,0);<br />
ADC12_B_enableInterrupt(ADC12_B_BASE, ADC12IE0,0,0);</p>
<p> ADC12_B_enable(ADC12_B_BASE);</p>
<p>}</p>
<p>//*****************************************************************************<br />
// * main.c<br />
// ******************************************************************************<br />
void Timer_Init(void)<br />
{<br />
/*<br />
Timer_A_initUpModeParam htim = {0};<br />
htim.clockSource = TIMER_A_CLOCKSOURCE_SMCLK; //<br />
// htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_2; //<br />
htim.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32; //<br />
htim.timerPeriod = TIMER_PERIOD - 1; //<br />
htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE; //<br />
// htim.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE; //<br />
htim.captureCompareInterruptEnable_CCR0_CCIE = TIMER_A_CCIE_CCR0_INTERRUPT_DISABLE;<br />
// htim.timerClear = TIMER_A_DO_CLEAR; //<br />
htim.timerClear = TIMER_A_SKIP_CLEAR; //<br />
htim.startTimer = false; //</p>
<p><br />
Timer_A_initUpMode(TIMER_A0_BASE, &htim);<br />
*/<br />
/*<br />
Timer_A_initContinuousModeParam initContParam = {0};</p>
<p> Timer_A_initUpModeParam Param={0};</p>
<p> initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;<br />
initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;<br />
initContParam.timerInterruptEnable_TAIE=TIMER_A_TAIE_INTERRUPT_ENABLE;<br />
initContParam.timerClear=TIMER_A_DO_CLEAR;<br />
initContParam.startTimer = true;</p>
<p> Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam);<br />
*/</p>
<p><br />
/*<br />
//Start timer in continuous mode sourced by SMCLK<br />
Timer_A_initContinuousModeParam initContParam = {0};<br />
initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;<br />
initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;<br />
initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_DISABLE;<br />
initContParam.timerClear = TIMER_A_DO_CLEAR;<br />
initContParam.startTimer = false;<br />
Timer_A_initContinuousMode(TIMER_A1_BASE, &initContParam);</p>
<p> //Initiaze compare mode<br />
Timer_A_clearCaptureCompareInterrupt(TIMER_A1_BASE,<br />
TIMER_A_CAPTURECOMPARE_REGISTER_0<br />
);<br />
*/<br />
/*<br />
Timer_A_initCompareModeParam initCompParam = {0};<br />
initCompParam.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;<br />
initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;<br />
// initCompParam.compareInterruptEnable = TIMER_A_CAPTURECOMPARE_INTERRUPT_DISABLE;<br />
initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_TOGGLE;<br />
// initCompParam.compareOutputMode = TIMER_A_OUTPUTMODE_SET_RESET;<br />
initCompParam.compareValue = 10;<br />
Timer_A_initCompareMode(TIMER_A0_BASE, &initCompParam);<br />
*/</p>
<p> Timer_A_outputPWMParam htim1 = {0};</p>
<p> htim1.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;</p>
<p> htim1.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_32;</p>
<p> htim1.timerPeriod = TIMER_PERIOD - 1;</p>
<p> htim1.compareRegister = TIMER_A_CAPTURECOMPARE_REGISTER_1;</p>
<p> htim1.compareOutputMode = TIMER_A_OUTPUTMODE_RESET_SET;</p>
<p> htim1.dutyCycle = TIMER_PERIOD / 2 ;</p>
<p> Timer_A_outputPWM(TIMER_A0_BASE, &htim1);</p>
<p><br />
// Timer_A_startCounter( TIMER_A0_BASE, TIMER_A_UP_MODE );</p>
<p><br />
}</p>
<p>//*****************************************************************************<br />
// * main.c<br />
// ******************************************************************************<br />
void IO_Init(void)<br />
{</p>
<p><br />
GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);<br />
GPIO_setAsOutputPin(GPIO_PORT_P2,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);<br />
GPIO_setAsOutputPin(GPIO_PORT_P3,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);<br />
GPIO_setAsOutputPin(GPIO_PORT_P4,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);</p>
<p> // GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN0);<br />
GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);<br />
GPIO_setOutputHighOnPin(GPIO_PORT_P2,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);<br />
GPIO_setOutputHighOnPin(GPIO_PORT_P3,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);<br />
GPIO_setOutputHighOnPin(GPIO_PORT_P4,GPIO_PIN0+GPIO_PIN1+GPIO_PIN2+GPIO_PIN3+GPIO_PIN4+GPIO_PIN5+GPIO_PIN6+GPIO_PIN7);</p>
<p><br />
// GPIO_setAsInputPin(GPIO_PORT_P1,GPIO_PIN0);<br />
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P1,GPIO_PIN0,GPIO_PRIMARY_MODULE_FUNCTION);</p>
<p>}<br />
</p>
<p><br />
//*****************************************************************************<br />
// * main.c<br />
// ******************************************************************************<br />
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)<br />
#pragma vector=ADC12_VECTOR<br />
__interrupt<br />
#elif defined(__GNUC__)<br />
__attribute__((interrupt(ADC12_VECTOR)))<br />
#endif<br />
void ADC12_ISR(void)<br />
{<br />
switch(__even_in_range(ADC12IV,12))<br />
{<br />
case 0: break; // Vector 0: No interrupt<br />
case 2: break; // Vector 2: ADC12BMEMx Overflow<br />
case 4: break; // Vector 4: Conversion time overflow<br />
case 6: break; // Vector 6: ADC12BHI<br />
case 8: break; // Vector 8: ADC12BLO<br />
case 10: break; // Vector 10: ADC12BIN<br />
case 12:<br />
// Vector 12: ADC12BMEM0 Interrupt<br />
g_usAdcData= ADC12_B_getResults(ADC12_B_BASE, ADC12_B_MEMORY_0);<br />
__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU<br />
break; // Clear CPUOFF bit from 0(SR)<br />
case 14: break; // Vector 14: ADC12BMEM1<br />
case 16: break; // Vector 16: ADC12BMEM2<br />
case 18: break; // Vector 18: ADC12BMEM3<br />
case 20: break; // Vector 20: ADC12BMEM4<br />
case 22: break; // Vector 22: ADC12BMEM5<br />
case 24: break; // Vector 24: ADC12BMEM6<br />
case 26: break; // Vector 26: ADC12BMEM7<br />
case 28: break; // Vector 28: ADC12BMEM8<br />
case 30: break; // Vector 30: ADC12BMEM9<br />
case 32: break; // Vector 32: ADC12BMEM10<br />
case 34: break; // Vector 34: ADC12BMEM11<br />
case 36: break; // Vector 36: ADC12BMEM12<br />
case 38: break; // Vector 38: ADC12BMEM13<br />
case 40: break; // Vector 40: ADC12BMEM14<br />
case 42: break; // Vector 42: ADC12BMEM15<br />
case 44: break; // Vector 44: ADC12BMEM16<br />
case 46: break; // Vector 46: ADC12BMEM17<br />
case 48: break; // Vector 48: ADC12BMEM18<br />
case 50: break; // Vector 50: ADC12BMEM19<br />
case 52: break; // Vector 52: ADC12BMEM20<br />
case 54: break; // Vector 54: ADC12BMEM21<br />
case 56: break; // Vector 56: ADC12BMEM22<br />
case 58: break; // Vector 58: ADC12BMEM23<br />
case 60: break; // Vector 60: ADC12BMEM24<br />
case 62: break; // Vector 62: ADC12BMEM25<br />
case 64: break; // Vector 64: ADC12BMEM26<br />
case 66: break; // Vector 66: ADC12BMEM27<br />
case 68: break; // Vector 68: ADC12BMEM28<br />
case 70: break; // Vector 70: ADC12BMEM29<br />
case 72: break; // Vector 72: ADC12BMEM30<br />
case 74: break; // Vector 74: ADC12BMEM31<br />
case 76: break; // Vector 76: ADC12BRDY<br />
default: break;<br />
}<br />
}</p>
<p>//******************************************************************************<br />
//<br />
//This is the TIMER1_A3 interrupt vector service routine.<br />
//<br />
//******************************************************************************</p>
<p>#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)<br />
#pragma vector=TIMER0_A1_VECTOR<br />
__interrupt<br />
#elif defined(__GNUC__)<br />
__attribute__((interrupt(TIMER0_A1_VECTOR)))<br />
#endif<br />
void TIMER0_A1_ISR (void)<br />
{<br />
switch(TA0IV)<br />
{<br />
case TA0IV_NONE:<br />
break;<br />
case TA0IV_TACCR1:<br />
GPIO_toggleOutputOnPin(<br />
GPIO_PORT_P2,<br />
GPIO_PIN1<br />
);<br />
break;<br />
case TA0IV_TACCR2:<br />
break;<br />
case TA0IV_5:<br />
break;<br />
case TA0IV_6:<br />
break;<br />
case TA0IV_TAIFG:</p>
<p> //Toggle P1.0<br />
GPIO_toggleOutputOnPin(<br />
GPIO_PORT_P2,<br />
GPIO_PIN1<br />
);</p>
<p> break;<br />
default:<br />
break;<br />
}</p>
<p>}<br />
</p>
<p>这个应该是寄存器设置的问题,你应该看TI的事例代码。MSP430FR5994的代码如下。</p>
<p>https://www.ti.com.cn/tool/cn/download/SLAC710</p>
<p>下来后看readme.txt 里面有关于ADC方面的例程。</p>
<p>msp430fr599x_active_01.c Active mode test<br />
msp430fr599x_active_02.c Active Mode Test with 100% CHR<br />
msp430fr599x_adc12_01.c ADC12, Sample A1, Avcc Ref, Set P1.0 if A1 > 0.5*AVcc<br />
msp430fr599x_adc12_02.c ADC12, Using the Internal Reference<br />
msp430fr599x_adc12_03.c ADC12, Sample A2-A3 Differential,Set P1.0 if i/p> 1V<br />
msp430fr599x_adc12_05.c ADC12, Using an External Reference<br />
msp430fr599x_adc12_10.c ADC12, Sample A10 Temp and Convert to oC and oF<br />
msp430fr599x_adc12_11.c ADC12, Sample A1, T0A1 Trig, Ultra-Low Pwr<br />
msp430fr599x_adc12_21.c ADC12, Window Comparator, 2.5V ref<br />
msp430fr599x_adc12_22.c ADC12, Window Comparator, 2.5V ref, 2's Complement</p>
tagetage 发表于 2024-3-22 22:04
这个应该是寄存器设置的问题,你应该看TI的事例代码。MSP430FR5994的代码如下。
https://www.ti.com.cn/ ...
<p>好的,我看一下,谢谢!</p>
页:
[1]