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

HELP !! pic16f84A timer0 don't work

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



Joined: 07 Jan 2006
Posts: 64
Location: Braga

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

HELP !! pic16f84A timer0 don't work
PostPosted: Mon Dec 17, 2007 1:04 pm     Reply with quote

any one could see where is the error please
TIMER0 don't work , doesn't count and PULSE_LED don't pulse

#include <16F84A.h>

#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading

#use delay(clock=8388608)

#define INTS_PER_SECOND 16 // (8.388.608/4*256*256)) one second each overflow
#define PULSE_LED PIN_B4
#define RELE1 PIN_A1
#define RELE2 PIN_A0
#define RELE3 PIN_B6

#define ON PIN_A2


int int_count;
int sec,min,hrs;

#int_RTCC

void RTCC_isr()
{

output_low(PULSE_LED);

if(--int_count==0)
{
output_high(PULSE_LED);

++sec;
if (sec>59){++min;sec=0;}
if (min>59){++hrs;min=0;}
if (hrs>23){hrs=0;}
int_count=INTS_PER_SECOND;
}
}





void main()
{
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);




while(true){

my code ~~~~~~~~
~~~~~~~~
~~~~~~~~

}

}

THANK YOU ALL
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 1:55 pm     Reply with quote

Quote:
#define INTS_PER_SECOND 16 // (8.388.608/4*256*256))

setup_timer_0(RTCC_INTERNAL | RTCC_DIV_1);

Your #define statement says you are using "div by 256", but your
setup_timer_0() statement uses "div by 1". That's a mistake.


Also, you need to initialize the 'int_count' variable in main(), before
you enable interrupts. Initialize it to "INTS_PER_SECOND".
PICdawg



Joined: 13 Dec 2007
Posts: 17

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 1:56 pm     Reply with quote

Keep in mind the following...

Timer0 is an 8 bit timer/counter. Your code says use the internal clock with no prescaler. That means the RTCC is incrementing every 0.4768us. (this time comes from 1/(8388608/4)) That means your rollover occurs every 122us, not every 1/16th of a sec like your code expects. (rollover occurs every 0.4768us * 256 counts per rollover = 122us)

Therefore, with your prescaler set to one, you need to preset a counter to 8192 and begin decrementing from there. (8192 rollovers * 122us per rollover = 1sec)

Make sense?
PICdawg



Joined: 13 Dec 2007
Posts: 17

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 2:06 pm     Reply with quote

If you go ahead and use the prescaler set to 256, then your counter needs to be initialized to 32. (8192/256=32). As PCM programmer indicated, you are missing this initialization line...
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