View previous topic :: View next topic |
Author |
Message |
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
PIC12F683 problem with WDT and Timer0? |
Posted: Thu Dec 20, 2007 12:38 pm |
|
|
I am trying to run a simple program that fires a output after a set time interval. I am using int_rtcc to count seconds, which is code that i have used else where inother pics with good succes. For some reaston it seems that if the Wdt is enabled, the timer0 does not work. if i turn it off, it times but not correctly. It has to be something in the set up, but i can not find what it is. Does anyone have suggestions? Thanks
V4.062
Code: |
#include <12F683.h>
#device adc=10
#use delay(clock=2000000,RESTART_WDT)
#fuses WDT,INTRC_IO, PUT, MCLR, NOBROWNOUT, NOCPD, NOPROTECT
#include <math.h>
#use fast_io(A)
#define GPIO1 PIN_A0
#define LED2 PIN_A1
#define time_in PIN_A2
//#define time_in PIN_A3
#define trn PIN_A4
#define lbo PIN_A5
#define INTS_PER_SECOND 976
////////////////////////////////////////////////////////////////////////////////
char int_count,loop;
long time1,time2,time3,seconds,voltage,hour,day,minute;
////////////////////////////////////////////////////////////////////////////////
#int_rtcc
void clock_isr(void)
{
if(--int_count==0) //decrement counter until 0
{
++seconds; //count up seconds
int_count=INTS_PER_SECOND; //reset counter
if (seconds>=65000)
seconds=65000;
}
}
////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void main()
{
setup_oscillator(osc_2mhz);
//setup_adc_ports(sAN2);
//setup_adc(ADC_CLOCK_DIV_16);
setup_wdt(WDT_ON);
//setup_wdt(WDT_72MS | WDT_ON);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_2);
set_rtcc(0);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
//setup_timer_1(T1_DISABLED);
set_tris_a(0b00101111);
output_low(trn); //shut off solenoid
int_count=INTS_PER_SECOND; //used for timer
seconds=0; //clear out variable
hour=0; //clear low volage counter for seconds
day=0; //clear out day counter
minute=0;
time1=20; //counter for time
loop=1;
voltage=0;
//set_adc_channel(2);
//delay_ms(1000);
while (TRUE)
{
//voltage=read_adc();
while(loop=1)
{
/*if(voltage>=1010)
{
output_high(trn);
delay_ms(100);
output_low(trn);
}*/
if(seconds>=time1)
{
output_high(trn);
delay_ms(100);
restart_wdt();
output_low(trn);
loop=0;
//seconds=0;
}
}
while (loop==0)
{
delay_ms(100);
output_low(trn);
}
}
} |
|
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 20, 2007 12:46 pm |
|
|
Quote: | #define INTS_PER_SECOND 976
char int_count, loop;
int_count = INTS_PER_SECOND |
You're loading a 'char' with a value greater than 255. |
|
![](templates/subSilver/images/spacer.gif) |
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Thu Dec 20, 2007 1:08 pm |
|
|
Thanks for catching that. Still something seems to be conflicting with the wdt. if it is off, i seem to be able to run close to where i want. with it on, it does not work at all. |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Dec 20, 2007 1:24 pm |
|
|
The WDT has a 16-bit prescaler. In addition to that, there is another
divider that can optionally be assigned as a WDT post-scaler or as
a pre-scaler for Timer0.
I don't have time to figure out the correct setup right now. I have to
do things at work. Maybe later. |
|
![](templates/subSilver/images/spacer.gif) |
nmeyer
Joined: 09 Jul 2004 Posts: 70
|
|
Posted: Thu Dec 20, 2007 2:00 pm |
|
|
Yes, that is what i was pursuing. I have not found the correct set up yet, but i am testing with the wdt off now and it seems to be running ok. I will look into it some more. Thanks |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Dec 23, 2007 4:18 pm |
|
|
I had some more time to work on this today. I made a test program
that does RTCC interrupts at 976 Hz, and it also runs the Watchdog timer
at a period of 69 ms. I didn't put in any code to restart the WDT because
I wanted it to do a reset, so I could measure the rate.
Code: |
#include <12F683.h>
#fuses INTRC_IO, NOWDT, MCLR, PUT, BROWNOUT
#use delay(clock=2000000)
#int_rtcc
void rtcc_isr(void)
{
// Create a short pulse so we can see the RTCC
// interrupt frequency on Pin A2 on a scope.
output_high(PIN_A2);
delay_us(10);
output_low(PIN_A2);
}
//=============================
void main()
{
// Create a short pulse so we can see the WDT
// restart frequency on Pin A5, on a scope.
output_high(PIN_A5);
delay_ms(1);
output_low(PIN_A5);
setup_wdt(WDT_ON | WDT_TIMES_4);
setup_timer_0(RTCC_INTERNAL | RTCC_DIV_2);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
while(1);
} |
|
|
![](templates/subSilver/images/spacer.gif) |
|