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

how to back up to program?

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



Joined: 30 Mar 2013
Posts: 17

View user's profile Send private message Send e-mail

how to back up to program?
PostPosted: Mon May 20, 2013 5:31 pm     Reply with quote

Please help me !
I want that program execute the same instruction after cutting current and back to the last routine when it was !
thank you
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 20, 2013 5:34 pm     Reply with quote

Post a small program that shows us what you want to do.
mohamed2040



Joined: 30 Mar 2013
Posts: 17

View user's profile Send private message Send e-mail

PostPosted: Mon May 20, 2013 5:50 pm     Reply with quote

it is nothing to the program!
I have a long program.
it execute many instructions!
instruction 1
instruction 2
instruction 3
.
.
.instruction n

I want if i make the power Off and i make it On the program back up to the last instruction executed!

instruction 1
instruction 2
instruction 3
POWER OFF
.
.
.
.
POWER ON
instruction 4
instruction 5
.
.
.
Instruction n
tks
mohamed2040



Joined: 30 Mar 2013
Posts: 17

View user's profile Send private message Send e-mail

PostPosted: Mon May 20, 2013 5:59 pm     Reply with quote

HELLLLLPPPPPPPPPPPPPP Confused Crying or Very sad
temtronic



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

View user's profile Send private message

PostPosted: Mon May 20, 2013 6:15 pm     Reply with quote

There are about 10-12 different ways to do it.
Depending on the PIC...
...one way is to write to say 'eeprom' the number of the next instruction to be executed. Should power fail your program reads the eeprom and starts from the 'instruction number' you previously stored.
this is similar to the way POST cards work.
Personally I store the number into battery backed RAM(like in a DS1307 RTC chip) as too many writes to the eeprom will destroy the PIC...
..it's also easier and faster.

hth
jay
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon May 20, 2013 7:54 pm     Reply with quote

Quote:

3:31 pm Please help me !
3:50 pm it is nothing to the program
3:59 pm HELLLLLPPPPPPPPPPPPPP

Tell us your PIC and your CCS compiler version.
mohamed2040



Joined: 30 Mar 2013
Posts: 17

View user's profile Send private message Send e-mail

PostPosted: Tue May 21, 2013 4:18 pm     Reply with quote

temtronic thank you Smile i use 16F877 PIC i see that to stock the number of the next instruction to be executed is effective ! but how can i get it ? from which reg ? please , can you send my a schema on ISIS ? and an example code ? :( I'm I'm stuck :(
thanks again

PCM programmer my pic is 16F877
mohamed2040



Joined: 30 Mar 2013
Posts: 17

View user's profile Send private message Send e-mail

PostPosted: Wed May 22, 2013 8:53 pm     Reply with quote

so ! no solution ? helllllp !!! Question Exclamation Confused Shocked
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed May 22, 2013 9:46 pm     Reply with quote

I don't know how to power-down the PIC and then start it up at the
exact same line in the Assembly language listing file.

This program shows how you could save the status of the number of
times a button has been pushed. Maybe it will help.
http://www.ccsinfo.com/forum/viewtopic.php?t=22109&start=17
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Thu May 23, 2013 12:31 am     Reply with quote

On the 877, it is close to impossible to do what is asked here. On the PIC18 chips it could be done.
The reason for the difference, is the lack of a 'pop' instruction for the stack.

On the PIC18, you'd have to have a 'power fail' interrupt triggered by external hardware, and capacitors on the supply rail to ensure the PIC remains powered for a few tens of mSec after this triggers. Then in the interrupt handler, 'pop' the stack contents, and store these in a non volatile store like FRAM, and then store the contents of every RAM location to this as well, and set a flag in this to say the data is now valid. Then push back the values popped, and wait. If the power fail disappears without the chip ever stopping, a return will then continue as if nothing has happened.
On boot, check the flag. If this is set, load the RAM from the FRAM, then the stack from the FRAM, and execute a return to restart from the location that called the interrupt.

Now, simply restarting from the same location, won't work, unless all the RAM is also restored. You would need an external memory that can store all this data, and store it quite quickly (so battery backed RAM, or FRAM). On the PIC16, I don't think this could be done without a lot of external hardware (it could be done, by using the ICD abilities of the chip, and an external controller, but big work....).

Simpler, to actually have your code running in effectively a 'state machine', so 'job1', 'job2' etc., and record which 'job' you are in. Then add storage of essential variables, and the restart could be done using an approach similar to the code PCM programmer refers to.

Best Wishes
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu May 23, 2013 5:55 am     Reply with quote

Would it do to simply stop the clock on power fail and use a backup battery to retain the processor state? The CPU would simply stop and restart without any knowledge of lost time. It would require a good external clock circuit. You could not use a PLL and any UART data or A/D conversions would be corrupted.

Without the use of any low power modes the static power drain on the battery may be a problem.
_________________
The search for better is endless. Instead simply find very good and get the job done.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu May 23, 2013 6:44 am     Reply with quote

Hi,

It's seems to me that the whole premise of this thread is flawed - that you need to design a system that will resume operation after the *next instruction* in the event of a power failure! Can you tell us the reason for this requirement? What is the application?

I've designed lots of systems - primarily building automation controllers - that store pertinent data (temperature setpoints, lighting states, etc.) in non-volatile memory so that these controllers can restart in the same condition as when power was lost, but it's not necessary to resume at the next instruction! If the application was that critical (medical, aerospace, etc.), you'd use battery back-up and multi-processor redundancy instead of the scheme you are proposing.

It seems to me that you desire a system with a level of hyper-complexity that is almost certainly *not* required in the real world!

John
mohamed2040



Joined: 30 Mar 2013
Posts: 17

View user's profile Send private message Send e-mail

PostPosted: Wed May 29, 2013 6:28 pm     Reply with quote

thank you for your answers! I am very happy because there are beautiful brothers like you Smile
ezflyr:
so my application is a medical machine as the dialysis machine Smile
among the routine! I run a routine where I made a disinfection phase during x minutes.
So if there is a power failure! I need a backup of context. and if the current continues the execution of the task as has nothing happened.
Ttelmah: thank you so much! I bought another PIC 18F452 I'll use the push and pop instructions of strack! purpose can you send me an example of an external circuit based on a battery? and thank you again. Embarassed
gpsmikey



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

View user's profile Send private message

PostPosted: Wed May 29, 2013 8:13 pm     Reply with quote

If this is a real project, you should look into what is required for medical control software certification. I know it is similar to flight critical software in avionics and the amount of documentation and testing of the code is tremendous and very expensive. If this is simply a class type project, then my comments do not apply here, but should be mentioned in any writeup you do for the project (I used to work on embedded software for level-A boxes here in the US for commercial aircraft and the hoops we had to jump through to get FAA certification are many and complex ). On the other hand, a bluescreen is probably not appreciated by pilots on final approach in the dark :-)

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
mohamed2040



Joined: 30 Mar 2013
Posts: 17

View user's profile Send private message Send e-mail

PostPosted: Thu May 30, 2013 1:41 pm     Reply with quote

yes Smile
But i must use the back up :(
Now ! i just wanna know how can i use push and pop instructions of stack! and find an external circuit.
Thank you one more time.
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