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 CCS Technical Support

Sleep in 16F877A

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



Joined: 06 Sep 2005
Posts: 13

View user's profile Send private message

Sleep in 16F877A
PostPosted: Tue Sep 06, 2005 5:55 pm     Reply with quote

I'm having trouble "Sleeping". What should be a timer that wakes every 2304ms to produce a 10ms pulse is acting like a free-running mutivibrator. What I see at power-on is an immediate 10ms high followed by a 22.5ms low....repeating endlessly. See code attached; I've cut out a lot of irrelevant operations. But I need to use 19.2kHz PWM, and I need a 65ms tick timer for other operations.

I'm obviously getting truncated sleep mode, but I can't figure out why. Is my setup for the other Timers upsetting the WDT timeout? Is there a workaround?


What am I missing?

[#include "16F877A.h"
#device ADC=10
#fuses HS, WDT, NOLVP, NOPROTECT
#use delay (clock=20000000)

void main()
{
setup_adc_ports(AN0_AN1_AN2_AN3_AN4);
setup_adc(ADC_CLOCK_INTERNAL);
setup_wdt(WDT_2304MS);
setup_psp(PSP_DISABLED);
setup_spi(FALSE);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_timer_2(T2_DIV_BY_1,255,1);
enable_interrupts(GLOBAL);

while (TRUE)
{
disable_interrupts(GLOBAL);
output_high (PIN_C1);
delay_ms(10);
output_low(PIN_C1);
restart_wdt();
enable_interrupts(GLOBAL);
sleep();

} /*end WHILE TRUE*/

} /*end MAIN*/
][/code]
Ttelmah
Guest







PostPosted: Wed Sep 07, 2005 3:07 am     Reply with quote

The other timers should not interfere with the sleep, since their oscillators will stop when the chip is asleep. However there is a problem if an interrupt has occurred in the period between disabling and enabling the interrupt, when the 'sleep' instruction will be prefetched, and the interrupt immediately serviced (I am assuming you have got interrupt service routines present - you do not show these, otherwise enabling an interrupt without the routine will result in chaos!). I'd try pausing for a moment between enabling the interrupts and trying to enable sleep. I have always used the 'setup_counters' control, rather than the setup_wdt, so:
setup_counters(RTCC_INTERNAL,WDT_2304MS);

The three functions 'setup_wdt', 'setup-countrs', and 'setup_timer_0', all sort of 'overlap' in functionality, with 'setup_counters', doing in one statement, what the other two functions do together. I wonder if the call to 'setup_timer_0', is overriding the earlier wachdog setup. Try using the 'combined' version and see if it helps.

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