Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Chicken and eggs Problem

Status
Not open for further replies.

asimov_18

Member level 2
Member level 2
Joined
Sep 25, 2006
Messages
45
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Location
London---UK
Visit site
Activity points
1,816
Greeting!!!
The problem i am facing is something many product designers would have faced and solved. So any one can help me look at it in a better would would help me come up with a understandable solution. Please I am not looking for anyone to give out codes and spoon feed ...its boring then.

I am making a device that has a micro controller(could be any one) this device is going to run a code for the function I implement.
Also this device has a power button like most commercial devices have. When I press the power button if the device is ON(functioning)
it turn itself off(or goes to sleep mode). and If off(in sleep mode) it turn itself on.

Ideally this could be done easily using interrupt where we have a flag that toggles state and this flag is check to call the sleep instruction.

the c code for this could be like

ISR routine:
Code:
              {
                 if (system_status_flag == 'ON')
                     {
                        system_status_flag = 'OFF';
                        sleep_routine();
                      }
                else
                   {
                      system_status_flag = 'ON'
                    }
           }   // end of ISR routine

main routine:
Code:
             void main(){

                                 do_initialization();
                                 
                                 while(1)
                                   {
                                     do_processing();
                                     .
                                     .
                                     .
                                    }
                            }
//end main functionality

The problem comes when I want to reset my system on power on(or waking up from sleep) so that the SP(stack pointer), PC(program counter) Status_flag and other critical register take the default value and program execution begins from the beginning or atleast to the
user it appears to be doing so.

It like when you press your TV remote button to turn TV off it goes to stand by and pressing power button puts the
TV back in action as if it has just started.

there is an option of using GOTO and making the program jump to the first line but as far as I understand GOTO jumps have
a scope of jumping to some line in very function where GOTO is present and cant make your program jump to main from ISR routine
also if it was possible would jumping from ISR to first line on main would the SP and other registers will not refresh to have the default values!!!!

I hope I have put the problem in simplest possible words with code example to help it.
 
Last edited by a moderator:

I used c, wrote functons for various task like initializing microcontroller, lcd, ports, read current value, on off of lcd, signal to PSU
on butten press call functions required, this way you can reset ports, and re-initialise microcontroller reseting similar to power off and then on.

Code:
function_init {
init micro..initiliasation,
....

}


function_on-off {
on ....
off...
led , lcd, power..
}
 
Last edited by a moderator:

could you try to store the actual values when the Off command received. Then when the ON command received just read them from the memory. So to the user it seem like nothing change and the device will be at the state that the user left it. Just add something like that
int array[5];

and before sleep rotuine
array[1]=critical value 1
.
.
.
array[5]=critical value 5
and then when the on command received
critical value 1 = array[1]
.
.
.
and at the end display them to the user.
The goto command has a lot of problem when used with interrupts.
 

Thanks for every one for replying!!!

-- As far as using the init routine goes yes it can be used to bring back the peripherals to default state
but how about PC(program counter),SP(stack pointer ) and status register?

--Well when we put the microcontroller to sleep the content of the RAM and registers are left as they are
so saving them and then and restoring them serves no meaningful purpose does it?
 

Sounds like you could do something like the PIC 'sleep' instruction with an interrupt on pin change to wake it up. On all but the 10F (smallest) PICs it simply carries on from where it was put to sleep without losing any data. Alternatively, you could preserve your current working state in EEPROM so you can perform a normal reset and recover the state by reading it back again.

Brian.
 

Well to be honest I am working with AVRs and Atmega8 in particular. Well It does have eeprom and one can put the default settings in it.
But I see it as defeating the purpose.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top