Help with rest interrupt

Hi , My arduino is running on car battery so I want to put it to sleep when its done running the ignition on code, then I want to reset it when the ignition goes hot again. I think I can use the attachinterrupt(0, ISR0, RISING), but I’m a little confused on how to implement it to do a reset. I know that part needs to go in setup, but does it need a loop to reset, like void ISRO(), and what would I put in the loop to cause a reset. Thanks, adown

Here is some info, it may not be exactly what you want. I'll be checking for "brown out" next.

http://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html

Do you want some thing to happen in your code or do you just want the board to reset. If you want the board to reset then this becomes a hardware issue. Set it up so that it only gets power for the time when the ignition is turned on and it should be working. Then just cut the power completely. When you apply power again the board will start over from the beginning.

Vaclav: Here is some info, it may not be exactly what you want. I'll be checking for "brown out" next.

http://www.nongnu.org/avr-libc/user-manual/group__avr__sleep.html

Here is the manual link with reference to brown out reset. Perhaps combination with sleep mode and / or brown out detector will do.

http://www.atmel.com/images/doc8161.pdf on page 48 or so

Delta_G, I have code that needs to run when the ignition is turned off. Right now, I have an r/c timer that runs a second 7805 for a few seconds, then turns off, but it's not working the way I planned. I am hoping to just put it to sleep after the ignition off code, then have it reset to start fresh with ignition on. Thanks, adown

Ok, if you want the Arduino to stay on and run code then leave it on running code and build your circuit so that hitting the ignition cuts arduinos power for a second. That will reset the board.

If you want it to stop running code until the next bit of the ignition, then cut its power from the time it's done doing what you want until it is time to turn on again.

Sleeping and waking up usually doesn't involve a reset. That's all for powering down without resetting. If you want a reset then forget sleep and just cut the power.

Delta_G: Ok, if you want the Arduino to stay on and run code then leave it on running code and build your circuit so that hitting the ignition cuts arduinos power for a second. That will reset the board.

Do you have a suggestion on how?

Delta_G: If you want it to stop running code until the next bit of the ignition, then cut its power from the time it's done doing what you want until it is time to turn on again.

It will run code continuously from the time the ignition turns on, until 10 seconds after the ignition is turned off. I need to reset to run through setup each time the ignition is turned on, or at least jump to setup.

Vaclav, I have read that. that is exactly what I want. disable BOD and enter standby, then use an interrupt to wake and reset. I just don't know how to do it. Thanks, adown

adown: It will run code continuously from the time the ignition turns on, until 10 seconds after the ignition is turned off. I need to reset to run through setup each time the ignition is turned on, or at least jump to setup.

Well that's simple then. Let it pull power from the ignition side of the ignition switch, like the ECU or some power windows, or other things in the car that only work when the ignition is in the run position. Find a capacitor or supercap that can get you the extra ten seconds after the ignition is off. Once it is drained, there is no power until the ignition is turned on again and the board starts from the beginning.

adown: Delta_G, I have code that needs to run when the ignition is turned off.

OK, this seem contradictory - you want to run code , but than you ( at present) sut the power off after few seconds.

Right now, I have an r/c timer that runs a second 7805 for a few seconds, then turns off, but it's not working the way I planned.

So how do you power the r/c timer? I would guess that keeping the timer powered defeats the purpose to save the battery after the ingnition is completed.

I am hoping to just put it to sleep

so use the processor sleep mode after "ignition complete" timer ( in your code - software, not external r/c timer ) expires.

after the ignition off code, then have it reset to start fresh with ignition on.

than have code to get the sleeping processor to awake

Thanks, adown

Vaclav, I have read that. that is exactly what I want. disable BOD and enter standby, then use an interrupt to wake and reset. I just don't know how to do it. Thanks, adown

Sorry, I was typing away when you posted this. Let me work on details, but I need to finish some code on ARM processor first.

There was a discussion here on how different modes of "sleep" works, and it MAY have some code samples. Can you Google that in meantime? Sorry, I barely have time to chat here HA HA There may be code in the manual too, see the link I posted. I did not look.

Vaclav:
Vaclav, I have read that. that is exactly what I want. disable BOD and enter standby, then use an interrupt to wake and reset. I just don’t know how to do it. Thanks, adown

Your problem with this is the reset. What Vaclav is describing will allow you to put the Arduino to sleep and wake it up, but won’t reset the board.

If you really must reset the board from software, enable the watchdog timer and put the code into an infinite loop. You wait however long you set the watchdog for and then the board resets.

Or you could refactor your code so that it doesn’t need a hard reset to do what you want.

I am running a 555 turning on a transistor triggered from the ignition switch through a voltage divider and cap. It should only trigger on ignition off, but it only works correctly 25% of the time, triggering the 555 on ignition on also. Even if it worked right, if someone turns off the ignition for 2 seconds, then decides to move, turns the ignition back on, the chip never shut off and will resume code from there. You're right, it would probably be easier to move my code from setup to another loop and if condition. An interrupt to reset just sounds so easy. Thanks, adown

OK, you've lost me. What does this thing actually do? Can you show a schematic for what you're talking about in reply 11. Where did the 555 come from? What does the code look like?

This is all doable, but it's time to stop hand-waving and work on the concrete solution.

Your problem with this is the reset. What Vaclav is describing will allow you to put the Arduino to sleep and wake it up, but won't reset the board.

Sorry guys, but I really do not have time to dedicate to this. I was just posting some generic suggestions and did not expected this to turn into step by step coding. I am sorry.

In one of the source I found a note was made that "brown-out" detector is bad because it actually resets the processor.

I don't buy that. I am sure there must be some code sample somewhere on net how to accomplish what adown wants to do. But in may be on "register " level only and I am currently in deep trouble with ARM registers, sorry.

No, it's not a register thing. There is a rather dangerous (at least as I understand it) volatile jump to zero. And there is the set the watchdog and let it time out style. Those are the only two ways I'm aware of to reset the board from software.

I don't understand how the BOD would fit in there. Yeah it resets the board, but it does so in response to falling supply voltage. If you're going to cut the supply voltage down to reset the board then you might as well pull the power completely and reset the board the old fashioned way.

I have 2 7805 voltage regs for the mega328. One runs straight off the ignition switch, the other off a timer circuit, both diode isolated. This timer should only energize when the ignition is turned off, powering a second 7805 for 10 seconds while the ignition off stuff happens. The timer circuit is not dependable. Sometimes it energizes on ignition off, and some times it energizes on ignition on. I could probably replace the 555 with an atiny to reset the mega, or how about a calling a loop to turn on the WDT reset and have it go right into reset. I don't know, now I'm just getting frustrated. I need to wait until I can look at my code.

PS: I can't post my code. Thanks for your help, adown

adown: PS: I can't post my code.

And just why not. This is an open source community. If your project is proprietary then you shouldn't abuse us to help you fix it without giving us some ownership of it or at least some pay.

I still think a supercap that can hold you up for at least 10 seconds would be the way to go. Arduino can detect the power cut to the ignition and start doing whatever it's gotta do for 10 seconds while it gets power from the supercap. The Arduino can time this out itself if the cap lasts a little too long. Then, Arduino is all the way off and not drawing any power while the ignition is off after the ten seconds. When the ignition is turned on again Arduino gets power and starts over.

This way you could also deal with the case where the car is turned off for less than 10 seconds. If Arduino can sense that the ignition was turned off, it can sense when it is turned back on and start doing whatever its gotta do then.

It's hard to talk around this without knowing what it is supposed to do. I think I'm done here if the project really is proprietary. If you can't share, neither will I. Best of luck to you.

I thonk you can also use something like this, let you arduino be supplied direct by battery and add this circuit to reset with ignition key :

Cheers, Ale.

(Not shure if the image is visible in post, I attached it anyway)

Here is another resource to check. But I like the idea to just remove power _ say by WDT - KISS?

I feel we are mixing power source and "ignition on" ( whatever that is ) and that may be an issue when the processor is being restarted.

http://playground.arduino.cc/Learning/ArduinoSleepCode

ilguargua: I thonk you can also use something like this, let you arduino be supplied direct by battery and add this circuit to reset with ignition key :

Cheers, Ale.

(Not shure if the image is visible in post, I attached it anyway)

Not to jump ahead of problem, there are pretty predicable "things" happening when just turning the ignition on and actually starting ( I assume that is in the plan) the engine.

Nasty things as far as electronics is concerned - unwanted brown-out would be one of them on weak battery.

This is not an easy "problem" in real world.