pic selection help

Status
Not open for further replies.
If you look at a pic data sheet (one with timer 2), you can work out what to set the two register to in order to get a 1mS period. With a 4MHz clock, the timers are clocked at 1MHz and so you need to rollover every 1000 instructions. This can be done by setting the prescaler (T2CON) to 4, the period (PR2) to 250 and the postscaler to 1.

In C that would be,
Code:
    T2CON=0b00000101;       //Pre=4, post=1 and timer2=on
    PR2=249;                //1 less than period
To find out when it has rolled over you can check the TMR2IF bit in PIR1.
Code:
    while(PIR1.TMR2IF==0);  //wait for rollover
    PIR1.TMR2IF=0;          //reset flag
    Count_mS++;             //increment count

Have fun.

Mike.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…