Hi, all~
To parse IR signal, use Timer 3 as timer and Timer 4 channel 0 as input capture channel. P1_0 is a input pin.
the problem is that program can enter into timer 3 interrupt but not to timer 4 interrupt. That's why? The folling is the major code:
void main(void){ RegisterInit(); Timer4Init(); Timer3Init(); while(1) { asm("nop"); }}void RegisterInit(void){ //init clock and tick frequency CLKCONCMD &= ~0x7f; //tick speed: 32M, clock speed: 32M while(CLKCONSTA & 0x40); //wait for crystal //init TIMIF TIMIF = 0x00; //timer4 alternative 1 PERCFG &= ~0x10; //init P1_0 P1SEL |= 0x01; //P1_0 peripheral I/O P1DIR &= ~0x01; //P1_0 input //init variable timerIntCount = 0; captureIntCount = 0; //open global interrupts EA = 1;}void Timer3Init(void){ T3CTL = 0x00; //default T3CTL |= 0xA0; //tick speed / 32 = 1MHz T3CTL |= 0x08; //timer4 overflow interrupt T3CTL |= 0x04; //clear counter T3CTL |= 0x01; //down mode T3CC0 = 0xFA; //250us interrupt T3IE = 1; T3CTL |= 0x10; //Timer4 start}void Timer4Init(void){ T4CTL = 0x00; //default T4CCTL0 = 0x00; //capture mode T4CCTL0 |= 0x40; //open capture/compare interrupt T4CCTL0 |= 0x02; //capture on failing edge}#pragma vector = T3_VECTOR__interrupt void T3_ISR(void){
T3OVFIF = 0;
timerIntCount++; T3CTL |= 0x10; T3CC0 = 0xFA;
}#pragma vector = T4_VECTOR__interrupt void T4_ISR(void){
captureIntCount++; //parse IR signal}
Thanks everybody
As far as I can see from the code, you neither enable the Timer 4 interrupt (T4IE = 1) nor start Timer 4. You do enable the Timer 3 interrupt and start Timer 3, though, which is why you are seeing only that one.
Thank you for your reply.
add " T4IE = 1 ", it is uesless.
add " T4CTL |= 0x10", start Timer4. Then, TIMIF.T4OVFIF = 1, but TIMIF.T4CH0IF is still 0. Therefore, progrom can enter into Timer4 interrupt because of T4OVFIF , not T4CH0IF.
You have set up Timer 4 channel 0 in capture mode, so in order to observe a Ch 0 interrupt, you have to have a falling edge on the channel 0 input line (P1.0).
i have set it.
//init P1_0 P1SEL |= 0x01; //P1_0 peripheral I/O P1DIR &= ~0x01; //P1_0 input
Yes, but is there any external activity on the pin P1.0? If not, you will of course not get any interrupt.
Yes, i have tested. There is a external activity.
I can capture P0_7 external activity with timer 1 channel 3.
P1_0 is neithrer pull-up nor pull down. Is external activity not capture because of it?
The lack of pull on P1.0 will only be an issue if the line is not driven externally. If your external driver switches between tri-state and GND, P1.0 will probably not be able to detect the change, while P0.7 will. In this case, you will need to add an external pull-up. If your external driver switches between VDD and GND, P1.0 should work fine in capturing the event.
I tested your code after having added T4IE = 1; and T4CTL |= 0x10; in Timer4Init(), and it works fine. When I have a falling edge on P1.0, I get the interrupt.
Thanks a lot. I will try.