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

12F675 WDT and SLEEP

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



Joined: 21 Nov 2014
Posts: 10

View user's profile Send private message

12F675 WDT and SLEEP
PostPosted: Fri Nov 21, 2014 1:09 am     Reply with quote

Hello.

I want to put my 12F675 to SLEEP mode and want it to wake up from times to times, do what it need to do then SLEEP again for saving maximum energy possible.

I went to its datasheet and discovered I wouldn't be able to use timers as they are disabled in SLEEP mode, so gone to WDT, which looks can do what I need.
So idea is disable WDT, do its procedures, enable WDT then sleep;

Problem is, code generated by wizard was:
Code:
setup_wdt(WDT_ON);
setup_wdt(WDT_1152MS|WDT_DIV_16);      //~1,1 s reset

But gives me errors:
Undefined identifier WDT_ON
Undefined identifier WDT_DIV_16

Looking in CCS help I found:
Code:
setup_wdt(WDT_1152MS);

Which compiles ok.
Looking for how to disable it I found in help:
Code:
setup_wdt(WDT_OFF);

Which give me error:
Undefined identifier WDT_OFF

Back again to datasheet, I found WDT really can be disabled by software (WDTE cleared), but I don't know how to have access to WDTE in CCS also, I was expecting from CCS something more advanced than assessing its direct address, making it not portable, right? (portability is not a problem in this case anyway).

So, I think I just need a way enable and disable WDT, this is the question.

Sorry if I committed any mistake here, my english is poor, I'm new to CCS, new to C and new to PIC.

Thank you very much.

PS: Compiler version is 5.008, I don't know if this information helps.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Nov 21, 2014 2:19 am     Reply with quote

You are missing some important things.

The values you can actually use for a command, are defined in the .h file for the processor. These change from chip to chip. This is because the compiler can't make the chips do things they don't have the ability to do. If you look at the entry for setup_wdt, in the .h file for this chip, you get:
Code:

// Constants used for SETUP_WDT() are:

#define WDT_18MS        8   
#define WDT_36MS        9   
#define WDT_72MS       10   
#define WDT_144MS      11   
#define WDT_288MS      12   
#define WDT_576MS      13   
#define WDT_1152MS     14   
#define WDT_2304MS     15   

No on/off.
If you look then at the data sheet, you will see that the only control for the watchdog on this chip, is the fuse (which can't be changed at run time), no software option for on/off. Many other chips do have a software option. This one doesn't.
The time specifies the divisor. If you are using 1152mSec, the /64 division is selected. Some latter chips have separate times and divisions of this. Your chip doesn't.

Not being able to disable, doesn't matter at all though. Just make sure the watchdog is reset at regular intervals in your running code.

However, 'beware' that this will not give anything approaching the times you may expect. If you look at the specifications in the data sheet. Table 12-4, Param no. 33, you will see that the 'nominal' 18mSec watchdog, can give times between 7mSec, and 33mSec, depending on voltage, temperature, and the particular chip. For the 1152mSec time (64*), this gives possible times between 448mSec, and 2.1seconds. Some of the more modern PIC's have a much more accurate watchdog time, so if you need anything approaching 'accuracy', look at one of these, or using an external clock chip to generate the wake up.

As a comment, remember that during the sleep period, you must ensure that all pins are _driven_ to the lowest power state (depends on your hardware)_, not left floating, and think about how your actual power supply is derived (things like simple voltage regulators can easily draw 50* the power the PIC needs...).

And on the Wizard. It'll allow you to put combinations in that are not available for your chip. Think of it as the 'thick', rather than as the 'wizard', and you have a better chance of getting things working. You can use the wizard, but have to actually know what the options do before selecting them. This means you might as well not use it....
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Nov 21, 2014 6:12 am     Reply with quote

Also...
since you're obviously using a battery...
1) use a bigger capacity battery.One with double the capacity(or more) only costs a couple pennies more yet you can get a LOT more operation from the project.
2) add a 'supercap'. These high Farad caps are great 'reservoirs' of electrons and really smooth the current demands of sleeping PICs.

just food for thought.

Jay
ChicoDaRave



Joined: 21 Nov 2014
Posts: 10

View user's profile Send private message

PostPosted: Fri Nov 21, 2014 2:55 pm     Reply with quote

Ttelmah:
Oh! Really!
My mistake, I forgot to check that, WDTE is a fuse!
No problem, I'm aware about the variations in WDT timer, the application is not time critical.
I was trying to avoid keeping the WDT enabled during the WAKE time, but keep reseting it will not be a big problem.
Thank you very much.

temtronic:
Yes, system with battery, to be more specific, it will be a simple solar charger controller, so I will have a "large battery" but my solar panel is small, I'm trying to save energy at maximum.

Can I ask another thing?
There is another way to make this uC wake from time to time, other than WDT?

Thank you.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 21, 2014 3:15 pm     Reply with quote

Just switch to a different 8-pin PIC that will do what you want.
Example: 12F683 has software control of Watchdog timer.

Or better: 12F1840 is a fully modern chip with many more Watchdog
features, such as time delays up to 256 seconds. Requires Pickit3
programmer.
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Fri Nov 21, 2014 3:37 pm     Reply with quote

Also, be aware that many of the later chips draw quite a bit less power. The 1840, that PCM programmer mentions has more memory, loads of peripherals etc., but draws about half the power!....
ChicoDaRave



Joined: 21 Nov 2014
Posts: 10

View user's profile Send private message

PostPosted: Sat Nov 22, 2014 1:59 am     Reply with quote

Probably I will not find or price will be not friendly, but I will search for those.
Thank you.
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