Part Number:MSP430F5529
在设置TA 2定时器捕获的时候,同时使能了TA2CCR1和TA2CCR2捕获中断,但设置断点检查isr 中TA2CCR2的中断始终进不去,只能进CCR1,即使单独使能CCR2捕获中断也不能进,二者使用的是完全相同的driverlib库函数进行配置,在使用TB0.5和TB0.6的时候也遇到了相同的问题,只有前者能够进入中断,请问是什么原因呢?
Susan Yang:
Lin Le 说:即使单独使能CCR2捕获中断也不能进,
是不是您的中断向量没有设置正确?若是可以,请给出单独使用TA2CCR2的相关代码
,
Lin Le:
void TimerA2_Init() { //Set 2.5 to capture input directionGPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,GPIO_PIN5);//Start timer in continuous mode sourced by SMCLK=1.048MHzTimer_A_clearTimerInterrupt(TIMER_A2_BASE);Timer_A_initContinuousModeParam initContParam = {0};initContParam.clockSource = TIMER_A_CLOCKSOURCE_SMCLK;initContParam.clockSourceDivider = TIMER_A_CLOCKSOURCE_DIVIDER_1;initContParam.timerInterruptEnable_TAIE = TIMER_A_TAIE_INTERRUPT_ENABLE;initContParam.timerClear = TIMER_A_DO_CLEAR;initContParam.startTimer = false;Timer_A_initContinuousMode(TIMER_A2_BASE, &initContParam);//Initiate capture mode--TA2.2Timer_A_initCaptureModeParam initCapParam1 = {0};initCapParam1.captureRegister=TIMER_A_CAPTURECOMPARE_REGISTER_2;//根据管脚选择initCapParam1.captureMode=TIMER_A_CAPTUREMODE_RISING_EDGE;initCapParam1.captureInputSelect=TIMER_A_CAPTURE_INPUTSELECT_CCIxA;initCapParam1.synchronizeCaptureSource=TIMER_A_CAPTURE_SYNCHRONOUS;initCapParam1.captureInterruptEnable=TIMER_A_CAPTURECOMPARE_INTERRUPT_ENABLE;initCapParam1.captureOutputMode=TIMER_A_OUTPUTMODE_OUTBITVALUE;Timer_A_initCaptureMode(TIMER_A2_BASE, &initCapParam1);Timer_A_enableCaptureCompareInterrupt(TIMER_A2_BASE,TIMER_A_CAPTURECOMPARE_REGISTER_2);Timer_A_startCounter( TIMER_A2_BASE,TIMER_A_CONTINUOUS_MODE);}// Timer A2 interrupt service routine #pragma vector=TIMER2_A1_VECTOR __interrupt void TIMER2_A1_ISR (void) {switch(__even_in_range(TA2IV,14)){case TA2IV_TA2CCR1://捕获中断if(getspeed_L){if(!flag_cap_A2){caphead_A2=TA2CCR1;flag_cap_A2=1;TA2CCTL1&=~0x03;//COV和标志位清零break;}if(flag_cap_A2){captail_A2=TA2CCR1;capgap_A2=captail_A2-caphead_A2;flag_cap_A2=0;capfinished_A2=1;TA2CCTL1&=~0x03;//COV和标志位清零break;}}TA2CCTL1&=~0x03;//COV和标志位清零break;case TA2IV_TA2CCR2://捕获中断//count_impulse++;if(getspeed_R){if(!flag_cap_A2){caphead_A2=TA2CCR2;flag_cap_A2=1;TA2CCTL2&=~0x03;//COV和标志位清零break;}if(flag_cap_A2){captail_A2=TA2CCR2;capgap_A2=captail_A2-caphead_A2;flag_cap_A2=0;capfinished_A2=1;TA2CCTL2&=~0x03;//COV和标志位清零break;}}TA2CCTL2&=~0x03;//COV和标志位清零break;case TA2IV_TAIFG://溢出中断if(flag_cap_A2)ovcount_A2++;break;default: break;} }单独使用的代码如上
,
Susan Yang:
就您目前给出的代码,并没有发现什么问题。您是在launchpad上测试的吗?
若是可以,能否给出/私信一下工程?我在开发板上测试一下
,
Lin Le:
testCCR.rar
当前测试工程如上,使用的是msp4305529launchpad开发板,刚刚测试还是相同的问题,同时检查发现P2.5(即TA2.2)始终为接地状态,导致无法触发捕获中断(已排除外部电路连接)
,
Susan Yang:
目前我是使用寄存器的例程来修改的,您可以在开发板上连接 P2.2 和 P2.4
因为目前对MSP430,我还是比较习惯寄存器例程
代码如下,请您对照一下相关配置
#include <msp430.h>volatile unsigned int counter; volatile unsigned int prev_counter; unsigned int difference;int main(void) {WDTCTL = WDTPW | WDTHOLD;// CAPTURE INPUTP2DIR &= ~BIT4;P2SEL |= BIT4;//PWM OUTPUTP2DIR |= BIT0+BIT1;// P2.0 and P2.1 outputP2SEL |= BIT0+BIT1;// P2.0 and P2.1 options selectTA1CCR0 = 512-1;// PWM PeriodTA1CCTL1 = OUTMOD_7;// CCR1 reset/setTA1CCR1 = 384;// CCR1 PWM duty cycleTA1CCTL2 = OUTMOD_7;// CCR2 reset/setTA1CCR2 = 128;// CCR2 PWM duty cycleTA1CTL = TASSEL_2 + MC_1 + TACLR;// SMCLK, up mode, clear TAR//capture configTA2CTL = TASSEL_2 + MC_2;TA2CCTL1 = CM_3+SCS+CAP+CCIS_0+CCIE;while(1) {__bis_SR_register(LPM0_bits + GIE);__no_operation();// break point heredifference = counter - prev_counter;if(TA2CCTL1 & COV) {TA2CCTL1 &= ~COV;}}}#pragma vector = TIMER2_A1_VECTOR __interrupt void TIMER2_A1_ISR (void) {switch(__even_in_range(TA2IV,14)){case TA2IV_NONE: break;case TA2IV_TACCR1:prev_counter = counter;counter = TA2CCR1;__bic_SR_register_on_exit(LPM0_bits + GIE);break;case TA2IV_TACCR2: break;case TA2IV_5: break;case TA2IV_6: break;case TA2IV_TAIFG: break;default: break;} }
,
Lin Le:
感谢您的帮助,问题已经解决,更换开发板之后发现能够正常工作,应该是原先的板子引脚损坏的原因
,
Susan Yang:
很高兴您能解决问题!