View previous topic :: View next topic |
Author |
Message |
mojsa2000
Joined: 18 May 2010 Posts: 78
|
a simple question |
Posted: Mon Dec 13, 2010 1:39 am |
|
|
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: 19510
|
|
Posted: Mon Dec 13, 2010 2:58 am |
|
|
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
|
|
Posted: Mon Dec 13, 2010 3:38 am |
|
|
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
|
|
Posted: Mon Dec 13, 2010 3:38 am |
|
|
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: 19510
|
|
Posted: Mon Dec 13, 2010 3:58 am |
|
|
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: 9226 Location: Greensville,Ontario
|
|
Posted: Mon Dec 13, 2010 6:12 am |
|
|
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
|
|
Posted: Mon Dec 13, 2010 10:18 am |
|
|
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
|
|
Posted: Mon Dec 13, 2010 2:20 pm |
|
|
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. |
|
|
|