|
|
View previous topic :: View next topic |
Author |
Message |
Jim Guest
|
restart_cause() always return zero. |
Posted: Sat May 26, 2007 12:58 pm |
|
|
hi,
I try to put the PIC18F722 to sleep, then wake up by WDT or by external Int. After wake up from sleep(), I call restart_cause() to read the cause of waking to find out if it is due to WDT expired or by external interrupts, but the restart_cause() will alway return zero.
I need help please. I have CCS 3.228.
Here is the code:
#fuses HS, PROTECT, PUT, WDT512, NOBROWNOUT, NOLVP, NOCPD, EMCU
#byte OSCCON = 0xFD3
#bit IDLEN = OSCCON.7
void test_power_saving(void)
{
boolean toggle_led;
uint8 resetcause;
//disable_interrupts(GLOBAL);
setup_wdt(WDT_OFF);
sensorctl_sys_led_drv(SENSORCTL_SYS_LED_OFF);
//setup_uart(FALSE);
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
//setup_spi(FALSE);
//setup_wdt(WDT_ON);
//setup_timer_0(RTCC_OFF);
//setup_timer_1(T1_DISABLED);
//setup_timer_2(T2_DISABLED,0,1);
//setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
//setup_comparator(NC_NC_NC_NC);
//setup_vref(FALSE);
//setup_low_volt_detect(FALSE);
disable_interrupts( INT_TIMER1 ); // disable Timer1 interrupt
setup_external_memory(EXTMEM_DISABLE);
output_high(PIN_J1);
output_high(PIN_J5);
sensorctl_sys_led_drv(SENSORCTL_SYS_LED_RED);
setup_wdt(WDT_ON);
SETUP_UART(UART_WAKEUP_ON_RDA);
IDLEN = 1;
sleep();
delay_cycles(1);
resetcause = restart_cause();
while (resetcause == WDT_TIMEOUT)
//while(1)
{
if (toggle_led)
{
sensorctl_sys_led_drv(SENSORCTL_SYS_LED_RED);
}
else
{
sensorctl_sys_led_drv(SENSORCTL_SYS_LED_OFF);
}
toggle_led = ~toggle_led;
restart_wdt();
IDLEN = 1;
sleep();
delay_cycles(1);
resetcause = restart_cause();
}
enable_interrupts( INT_TIMER1 ); // disable Timer1 interrupt
enable_interrupts(GLOBAL);
} |
|
|
Ttelmah Guest
|
|
Posted: Sat May 26, 2007 2:42 pm |
|
|
It is difficult to follow the posted code (read the sticky thread about how to post code here). However key thing is that you must read 'restart_cause', before calling any of the WDT 'setup' functions.
Basically, the easiest thing is to read it early in the main.
Best Wishes |
|
|
|
|
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
|