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

a simple question

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



Joined: 18 May 2010
Posts: 78

View user's profile Send private message

a simple question
PostPosted: Mon Dec 13, 2010 1:39 am     Reply with quote

Hi
I have a simple question that is very important. When I used to worked with ATMEL chips and codevision compiler,
there was a definition that saved its value if chip was turned off.
Now, I need to know what definition saves its value when micro is turned off. (in ccs c compiler)
Thanks
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 2:58 am     Reply with quote

None.
Doing this will depend on what hardware you have so there is no 'generic' solution for the PIC.
A search here will find some examples.

Best Wishes
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 3:38 am     Reply with quote

Quote:
there was a definition that saved its value if chip was turned off

I guess, it's not saved on turn-off (would require a power fail interrupt and a capacitor to keep the processor operational for several ms) but written to eeprom automatically each time the value is changed. CCS C doesn't provied a similar feature (non-volatile storage class with automatic eeprom backup).
mojsa2000



Joined: 18 May 2010
Posts: 78

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 3:38 am     Reply with quote

Dear Ttelmah
Thanks for your guidance.
My project is a system that accounts the power. Its important that when the system is turned off or reset the previous value be saved.
I don't know about it . In codevision the "flash" do it as well as.
In CCS compiler, I think I should this command:write_eeprom(address, value). Is it true?
Please help me or direct me to related posts.
Ttelmah



Joined: 11 Mar 2010
Posts: 19520

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 3:58 am     Reply with quote

It will depend on your hardware.
Basically, 'write_eeprom', allows you to write values into the non-volatile memory on the PIC (assuming you have a chip with EEPROM....). This takes (depending on the chip), something between 2, and 4mSec/byte. So the key becomes detecting that a power fail has occurred, with enough 'reservoir' capacitance present on the supply rails, to keep the supply above the minimum voltage for EEPROM writing, for however long your PIC needs to write the number of bytes required.
Now, some PIC's have a power fail interrupt, based on detecting when the 5v rail drops below a programmed point. On some others, this could be detected using a comparator. If you have a linear power supply, you could instead detect on the voltage before the regulator, to give an earlier warning, or even build a 'missing pulse' detector on the incoming AC mains.
So you need to start with 'how many bytes'. Then calculate the time needed. Then look at your supply, and work out how to detect the failure, and how to tell the PIC that this has happened. Then work out how to maintain the supply till the bytes are written. Finally (often missed) how to deal with the situation where the write is triggered, and then the supply recovers....

Best Wishes
temtronic



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

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 6:12 am     Reply with quote

Another idea to consider is an 'automatic battery backup mode'.
Basically the PIC monitors the AC power line(zero cross detector is simple) and when AC power is not seen, the program goes into 'battery mode',where depending on the size(capacity) of the battery , the PIC can shut off peripherals to save energy. At this time it could also store data into EEPROM,pulse an LED to display the mode it's in,etc.
I've done it this way for almost 30 years now in remote energy control systems.The key is to have a flawless switch from AC power to battery and to come back 'online' without 'glitches'.Properly designed hardware and software will result in a 'bullit proof' system.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 10:18 am     Reply with quote

Another consideration - if your system requires a real time clock for the power accounting, something like the DS1307 has 56 bytes of non-volatile RAM built in if you have a backup battery. Microchip also has their MCP79410 RTC that has both RAM and eeprom built in that could work for you if you are using a processor that does not have eeprom on-chip.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 13, 2010 2:20 pm     Reply with quote

Quote:

When I used to worked with ATMEL chips and codevision compiler,
there was a definition that saved its value if chip was turned off.

Post a link to the Codevision manual for Atmel which shows how to do this.
Tell us the page and the section heading in the manual.
Then we can consider if CCS has some equivalent function or data-type.
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