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

restart_cause() always return zero.

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







restart_cause() always return zero.
PostPosted: Sat May 26, 2007 12:58 pm     Reply with quote

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







PostPosted: Sat May 26, 2007 2:42 pm     Reply with quote

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
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