I'm not sure where you see that in the datasheet - it appears to me that in the Sleep state all clocks are disabled (TABLE 19-1: POWER-MANAGED MODES) - this is typical for PIC's.M3GAPL3X said:... but the spec sheet says that only Timer0 is disabled and Timer1 can be used during sleep mode.
The clock speed you need is dependent on how much time you need to complete your task. That's going to be based on how much code has to be executed for you app and the timer it takes to "check" your voltages.M3GAPL3X said:... Also, do you think a 1 Mhz clock is suitable for this task? I can go even lower?
//LFINTOSC will turn on automatically if WDT is on. In our case, WDTEN = 0 and WDTCON.SWDTEN = 1
#include <p18f14k50.h>
//pragma codes
#pragma config FOSC = IRC //enable Internal Oscillator
#pragma config WDTEN = OFF //watchdog timer will be software controlled
#pragma config WDTPS = 256//1:128 postscalar for the watchdog timer
void main()
{
TRISC = 0x00; //set all C ports as outputs
while(1)
{
WDTCONbits.SWDTEN = 1; //enable watchdog timer
Sleep(); //CPU sleep. Wakeup when Watchdog overlfows
LATC ^= 0xff; //when watchdog timer overflows, light up all LED's
WDTCONbits.SWDTEN = 0; //turn off watchdog timer
}
}
//LFINTOSC will turn on automatically if WDT is on. In our case, WDTEN = 0 and WDTCON.SWDTEN = 1
#include <p18f14k50.h>
//pragma codes
#pragma config FOSC = IRC //enable Internal Oscillator
#pragma config WDTEN = OFF //watchdog timer will be software controlled
#pragma config WDTPS = 256//1:256 postscalar for watchdog, this will give around a 1 second delay
void main()
{
unsigned int x = 0;
TRISC = 0x00; //set all C ports as outputs
while (1)
{
WDTCONbits.SWDTEN = 1; //enable watchdog timer
Sleep(); //sleep for 1 second
x++; //increment variable x
//check to see if variable x is under 15
if (x <= 15)
{
LATC = x;
}
else //if over 15, reset LATC and variable x and start over
{
LATC = 0;
x = 0;
}
WDTCONbits.SWDTEN = 0; //disable watchdog timer
}
}
The WDT counter and postscaler are cleared, but the WDT is not disabled. That just means you have 10mS From the time you awake until it firesM3GAPL3X said:It sounds like that the WDT clears itself automatically when the SLEEP () instruction occurs. This is what it says in the spec sheet:
The WDT and postscaler are cleared when any of the following events occur: a SLEEP or CLRWDT instruction is executed
YesM3GAPL3X said:Another quick question, I also want to do some ADC when PIC is sleeping. Can I run the WDT timer clock and the ADC clock (Frc) during sleep mode at the same time??
void AtoD(void)
{
//1. Configure Port
//disable output pin driver for RC0, RC1 and RC3
TRISC = 0b00001011;
//configure pins as analog
ANSEL = 0b10110000; //RC3, RC1 and RC0 set as analog pins
//configure voltage references
//(positive voltage reference will come from VREF+ pin) - set to 01
ADCON1bits.PVCFG1 = 0;
ADCON1bits.PVCFG1 = 1;
//negative voltage reference will come from VREF- pin - set to 01
ADCON1bits.NVCFG1 = 0;
ADCON1bits.NVCFG1 = 1;
//select ADC conversion channel
ADCON0bits.CHS3 =0; //select RC3 bit first (0111)
ADCON0bits.CHS2 =1;
ADCON0bits.CHS1 =1;
ADCON0bits.CHS0 =1;
//select result format
ADCON2bits.ADFM = 0; //left justified
//select acquisition delay (16 tads - 110)
ADCON2bits.ACQT2 = 1;
ADCON2bits.ACQT2 = 1;
ADCON2bits.ACQT2 = 0;
//turn on ADC module
ADCON0bits.ADON = 1;
//5. Start conversion by setting the GO/DONE bit
ADCON0bits.GO_DONE = 1; //NOTE: bit is automatically cleared by hardware when the conversion is done
if(ADCON0bits.GO_DONE = 0) //poll GODONE flag to see if conversion is done for RC3
{
//CHECK TO SEE IF RESULT IS GREATER THAN A CERTAIN AMOUNT
}
ADCON0bits.ADON = 0;
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?