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

looping forever

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



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

looping forever
PostPosted: Sun Dec 18, 2011 10:07 am     Reply with quote

Dear Friends,

I am making a program which has a looping (while (1)) in the main function. Is it good to have this type of programming or it is not "healthy" for the PIC?

In case that one uses sleep() command, what is the command to return back in case of interrupt?

I am using PIC16F687 with a 4MHz crystal
drolleman



Joined: 03 Feb 2011
Posts: 116

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 11:02 am     Reply with quote

The compiler is going to give you a warning, but it's just because your loop will never break out, which is what you want. As for the health of the pic it doesn't mind at all.
Battery David



Joined: 01 Feb 2010
Posts: 25

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 11:07 am     Reply with quote

When you get an interrupt, the code returns to the statement after the sleep(). This is an easy way to save lots of power.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 3:17 pm     Reply with quote

If you have an interrupt enabled, on a hardware peripheral that does not use the clock, and do not have the global interrupts enabled, then when the interrupt triggers, the next instruction is executed, and you don't need an interrupt handler.
If you have both the interrupt enabled, and the global interrupts enabled, then the chip will wake up, and call the interrupt handler _which must be present_, then return to the code after the sleep.
You can only wake on peripherals that keep working when you are asleep.
On some latter chips, you can leave the clock oscillator running and feeding the peripherals, while the CPU itself sleeps. On these you can wake up from peripherals that do use the clock.

Best Wishes
aaronik19



Joined: 25 Apr 2011
Posts: 297

View user's profile Send private message

PostPosted: Sun Dec 18, 2011 4:30 pm     Reply with quote

Thanks for your reply. On the datasheet I've read that during sleep mode, the MCU will have no clock cycles, so the timer 1 will not be running. Please correct me if I am wrong. On the other hand, if I use the internal oscillator instead of an external crystal, I will solve the problem?
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Mon Dec 19, 2011 2:30 am     Reply with quote

The 687 does not support having the CPU clock running during sleep mode.
The internal oscillator will stop.
What it does allow is you to run Timer1, off _it's own external crystal_. Normally 32768Hz, which draws very little power.
You need to have a crystal between the OSC1, and OSC2 pins of Timer1 (with suitable loading capacitors), and setup timer1 with:

setup_timer_1(T1_EXTERNAL|T1_CLK_OUT|T1_DIV_BY_1);

Then timer1, will stay running when the processor sleeps.

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