Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
10/09/09 11:20
Read: times


 
#169567 - Timer Capture 2 ISR Execution.
hi all,
I am working with P89V664 micro controller on sdcc. My aim is to use the Timer 2 to capture the H to L pulses at T2EX pin and update a variable of 16 bits. The Source of H to L transitions is an IR sensor which works as given in the link:

http://www.sbprojects.com/knowledge/ir/sharp.htm

Now, I am able to capture the Negitive transitions, generate
interrupts.

I am failing to update the variable with 1 and 0;

I have to implement this in the ISR of timer2 only(I was happy polling!). I am compiling this code for large model.
I am posting you the ISR I have used with minimal modifications.

/* Capture the negitive edges and update the queue with the number
 * received. */
void zk_timer2_capture_isr() __interrupt 7
{
        static long int ovf;    /* Timer overflow counter */
        static uint16_t word;
        static uint8_t bits_recvd; /* count the number of bits received. */
        idata char word_buf[17] = "----------------";/* a buffer to print on LCD*/

        uint16_t timer_val;     /* hold the timer capture value */
        uint32_t lag_edge;
        static uint32_t lead_edge; /* the previous negitive edge needs
                                    * to be preserved. */
        int32_t diff;

        if (TF2 == 1) {         /* check overflow */
                ovf++;
                TF2 = 0;
                P3_4 = !P3_4;   //for debugging, buzzer beeps
        }
        if (EXF2 == 1) {
                /* Capture Interrupt is not disabled! So keep ISR
                 * small! */
                timer_val = RCAP2H;
                timer_val <<= 8;
                timer_val |= RCAP2L;
                EXF2 = 0;       /* clear the flags */

                P1_4 = !P1_4; //for debugging, led toggles

                lag_edge = timer_val;

                if (lead_edge == 0) { /* for the first pulse only */
                        lead_edge = lag_edge;
                        ovf = 0;
                }
                else {
                        diff =  lag_edge - lead_edge + (ovf * 0xFFFF);
                        /* Consider the timer overflow */
                        ovf = 0;

                        if (diff <= CLK_6_1MS) /* received 0 */ {
                                word |= 0x0000;
                                word_buf[bits_recvd] = '0';
                                /* check each bit received, for
                                 * debugging only. */
                                bits_recvd++;
                        }
                        else {
                                if (diff <= CLK_6_2MS) { /* received 1 */
                                        word |= 0x8000;
                                        word_buf[bits_recvd] = '1';
                                }
                                else
                                        word_buf[bits_recvd] = 'X';     /* FIXME:This should
                                                                         * not happen. */
                                bits_recvd++;
                        }

                        word >>= 1;

                        if (bits_recvd == (MAX_NUM_BITS - 1)) {
                                /* 15 -bits received. Update the buffer. */
                                lead_edge = 0;
                                bits_recvd = 0;
                                word = word >> 1;
                                /* update the buffer here. */
                                lcd_printl(0, word_buf);
                                sprintf(word_buf, "received %d bits.", bits_recvd);
                                lcd_printl(1, word_buf);
                                word = 0;
                        }
                        else
                                lead_edge = lag_edge;
                }
        }
}


The initiation of Timer2 is as done here:

http://www.8052.com/forum/read/169319

The Observations made are:
1. LED toggles and the buzzer beep, indicating that the ISR is entered.
2. The number of bits received is always (bits_recvd)1.
3. The word received is always 0.

Any suggestions would be greatly appreciated.

Regards,
Sarma.


List of 7 messages in thread
TopicAuthorDate
Timer Capture 2 ISR Execution.            01/01/70 00:00      
   Why the Large model?            01/01/70 00:00      
      Large Model on SDCC            01/01/70 00:00      
   WHICH variable            01/01/70 00:00      
      Variable            01/01/70 00:00      
         That is a *really* bad name for a variable!            01/01/70 00:00      
            word |= 0x0000;            01/01/70 00:00      

Back to Subject List