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 CCS Technical Support

How to clear Timer1 or Timer3 in new PIC18Fxxx0?

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



Joined: 04 Aug 2004
Posts: 238
Location: Chicago

View user's profile Send private message Send e-mail Yahoo Messenger

How to clear Timer1 or Timer3 in new PIC18Fxxx0?
PostPosted: Sat Dec 03, 2005 7:46 am     Reply with quote

There is an errata that says that we are not supposed to write to Tmr1 or Tmr3 while the timer is running, nor let an event occur between writing to tmr1h and tmr1L (also tmr3h and tmr3L).

Does anyone know if CCS implements the workaround to this errata?

If not, how then would I implement the workaround to this?

Maybe, if i want to write a value to TMR3, e.g. clear it by writing 0 to it, would I then need to disable global interrupts, stop timer3, then write the desired value, then restart timer 3?:

Code:

disable_interrupts(GLOBAL);
setup_timer3(T3_DISABLED); // This stops tmr3
set_timer3(0); // this clears timer3
setup_timer3(T3_INTERNAL | T3_DIV_BY_1); // this (re)starts tmr3 with a value of zero
enable_interrupts(GLOBAL);
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 05, 2005 3:51 pm     Reply with quote

Quote:
Does anyone know if CCS implements the workaround to this errata?

Post the PIC that you're using, and your compiler version.
valemike
Guest







PostPosted: Mon Dec 05, 2005 8:09 pm     Reply with quote

It's the PIC18F4580. But the errata applies to the PIC18F4480, 18F2420, 18F2520. And i think it applies to the 2520, 4520 as well.

I'll probably do a .lst file listing and see what's going on.

It dawned on me earlier that it is best to simply stop the clock, then write the value i want. It would be useless to write to a clock that is running.
amcfall



Joined: 20 Oct 2005
Posts: 44

View user's profile Send private message

PostPosted: Tue Dec 06, 2005 8:15 am     Reply with quote

Interesting. I'd better read through the errata, I have a project with the 2520 using timers 1 and 3. Thanks for bringing this up, I'd better read the erratas from now on!

Avery
valemike
Guest







PostPosted: Wed Dec 07, 2005 8:04 am     Reply with quote

I haven't compiled with the 18F4580 since last week, so i have no CCS assembly to show.

Some Microchip FAEs were here yesterday though, and told me the proper way to do it. It's pretty obvious:

Code:

disable_interrupts(GLOBAL);
stop timer1;
write to tmr1h and then to tmr1L;
enable_interrupts(GLOBAL);
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