View previous topic :: View next topic |
Author |
Message |
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
how to stop timer0 |
Posted: Tue Aug 28, 2007 12:12 am |
|
|
Dear Sir,
here i am using 12f629, MPLAB 7.5 Ver. & CCS PCM C Compiler, Version 3.249, 34534.
if i want to stop timer 1 i have statement like this
SETUP_TIMER_1(T1_DISABLED);
Then if i want to stop timer 0 ,what i have to do?
i checked 12f629.h file i found only
#define T1_DISABLED 0
plz reply _________________ Thank You,
With Best Regards,
Deepak. |
|
|
RossJ
Joined: 25 Aug 2004 Posts: 66
|
|
Posted: Tue Aug 28, 2007 12:25 am |
|
|
Timer 0 on most (all?) PICs prior to 18 series doesn't have the option to stop. You can check the datasheet for your PIC to confirm this. Obviously the compiler can't stop the timer if the PIC itself doesn't support doing so.
The main reason for stopping a timer is for power conservation reasons. Perhapt this is why the option was added to PIC18. |
|
|
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
how to stop timer0 |
Posted: Tue Aug 28, 2007 12:47 am |
|
|
Then if want to stop timer0 then how it is possible _________________ Thank You,
With Best Regards,
Deepak. |
|
|
RossJ
Joined: 25 Aug 2004 Posts: 66
|
|
Posted: Tue Aug 28, 2007 1:13 am |
|
|
Turn off the power or hold the PIC in reset with MCLR. I guess neither solution is satisfactory
What is the actual reason you wish to stop the timer? Perhaps there is another way to solve that problem. |
|
|
deepakomanna
Joined: 06 Mar 2007 Posts: 92 Location: Pune,India
|
how to stop timer0 |
Posted: Tue Aug 28, 2007 1:29 am |
|
|
here i sensing to pulses at GPIO 0 & GPIO 1,like this.
while(INPUT(PIN_A0)); // 1 st pulse
while(INPUT(PIN_A1)); // 2nd pulse
so whenever 2nd pulse comes i have to keep GPIO 5 low for 1.35 msec.
So by using delay i done this,but i don't want to waste time,
OUTPUT_LOW(PIN_A5);
DELAY_US(1300);
OUTPUT_HIGH(PIN_A5);
so i want to use timer0,& timer1 is used for another purpose.
whenever 2nd pulse comes i want to start timer0 & GPIO 5 low.
SETUP_TIMER_0(RTCC_INTERNAL|RTCC_DIV_128);
OUTPUT_LOW(PIN_A5);
And in interrupt routine i want to make GPIO 5 high & stop timer0 _________________ Thank You,
With Best Regards,
Deepak. |
|
|
RossJ
Joined: 25 Aug 2004 Posts: 66
|
|
Posted: Tue Aug 28, 2007 1:43 am |
|
|
Okay, that's pretty straight forward...
You don't actually need to stop the timer, just ignore it (as it will keep rolling over periodically).
1. Setup the timer at some convenient place (only needs to be done once).
2. After you output_low, use set_timer0() to set an appropriate starting value. The timer will continue counting up from that value.
3. Enable the timer0 interrupt.
4. When the timer rolls over the interrupt is generated and you disable timer0 interrupt and output_high (within the interrupt service routine).
5. The timer continues counting but since you have disabled the interrupt and so long as you don't read the timer's value, you will never notice.
6. Repeat from 2 as required. |
|
|
Ttelmah Guest
|
|
Posted: Tue Aug 28, 2007 2:52 am |
|
|
Add one thing to the above.
After setting the timer, clear the interrupt, before enabling it. The problem is that the timer _will_have rolled over in the period between when it was last used, so the interrupt flag _will_ already be set.
Best Wishes |
|
|
|