View previous topic :: View next topic |
Author |
Message |
jruibarroso
Joined: 07 Jan 2006 Posts: 64 Location: Braga
|
HELP !! pic16f84A timer0 don't work |
Posted: Mon Dec 17, 2007 1:04 pm |
|
|
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
|
|
Posted: Mon Dec 17, 2007 1:55 pm |
|
|
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
|
|
Posted: Mon Dec 17, 2007 1:56 pm |
|
|
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
|
|
Posted: Mon Dec 17, 2007 2:06 pm |
|
|
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... |
|
|
|