CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

how to stop timer0

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
deepakomanna



Joined: 06 Mar 2007
Posts: 92
Location: Pune,India

View user's profile Send private message AIM Address Yahoo Messenger

how to stop timer0
PostPosted: Tue Aug 28, 2007 12:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Aug 28, 2007 12:25 am     Reply with quote

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

View user's profile Send private message AIM Address Yahoo Messenger

how to stop timer0
PostPosted: Tue Aug 28, 2007 12:47 am     Reply with quote

Then if want to stop timer0 then how it is possible
_________________
Thank You,
With Best Regards,
Deepak.
RossJ



Joined: 25 Aug 2004
Posts: 66

View user's profile Send private message

PostPosted: Tue Aug 28, 2007 1:13 am     Reply with quote

Turn off the power or hold the PIC in reset with MCLR. I guess neither solution is satisfactory Very Happy

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

View user's profile Send private message AIM Address Yahoo Messenger

how to stop timer0
PostPosted: Tue Aug 28, 2007 1:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Aug 28, 2007 1:43 am     Reply with quote

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







PostPosted: Tue Aug 28, 2007 2:52 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group