Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 15:45 06 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Duinomite gracefull shutdown

Author Message
bobo2
Newbie

Joined: 26/10/2012
Location: Sweden
Posts: 36
Posted: 05:34am 18 Aug 2015
Copy link to clipboard 
Print this post

I have built a small controller using duinomite and MMBasic with CAN.

When I start it up the controller does its thing and then when the power is cut the process is interrupted. This is fine.

I would now like to add some logging to an SD card, and I would like to write to it as seldom as possible to avoid damaging it.

So I am thinking of adding a bigger capacitors or a battery to the duinomite to prevent immediate shutdown and give it some time to finish off logging.

I plan to open a file on startup of my program and then start writing to the file... and if the duinomite senses that power is cut it will close the log file and shut down.

Now to the questions - what would be the best way to sense that power is cut?
- if I use LiPo battery then maybe I can sense difference in supply voltage (the normal supply is 12V, while the battery would be around 3.5V) via one of the analog pins?
- what if I use capacitors in parallel with the 12V supply - would that same idea work too? Or maybe I should dimension the capacitors to assure that the duinomite runs for one more write to the SD card?
- if I use capacitors the duinomite will shut down soon enough, but what if I use battery - is there a "shut down" command that would turn off the duinomite until the next time 12V power is applied? Maybe some device with latching relays?

Is there any other way to handle logging to the SD card, when power is not guaranteed?

It is important for me that I get all the info at the end of the operation - I don't want to miss the final 1 minute of the log.

Thanks in advance for any ideas, suggestions!
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10209
Posted: 05:56am 18 Aug 2015
Copy link to clipboard 
Print this post

How about just putting a diode in the supply and the capacitor (1 Farad 5V should be enough) the processor side of the diode. That way you can measure the voltage on the supply side of the diode using a potential divider into one of the analogue pins and as soon as you see it drop do the logging and close the file
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3282
Posted: 07:14am 18 Aug 2015
Copy link to clipboard 
Print this post

You need to watch out with supercaps (eg, 1F 5V) because they have a large internal resistance and may not be able to supply the current required by the Duinomite.
Geoff Graham - http://geoffg.net
 
bobo2
Newbie

Joined: 26/10/2012
Location: Sweden
Posts: 36
Posted: 07:15am 18 Aug 2015
Copy link to clipboard 
Print this post

Thanks for reply matherp.

I am confused - how is this capacitor and two diodes supposed to work? What is the theory of operation? Or maybe you can make a quick schema?

My "normal" power supply to the duinomite is between 9V and 15V - how is a 5V diode going to work with this? Maybe you meant zener diode?
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10209
Posted: 07:44am 18 Aug 2015
Copy link to clipboard 
Print this post

It is just one ordinary diode in-line with the positive supply to isolate the supply from the capacitor. The capacitor will then maintain the voltage to the processor for as long as the charge lasts (but check the capacitor spec as per Geoff's note).

The voltage divider comes directly from the supply before the diode. This way you can check that the supply has failed but still have some time to close gracefully

-
 
Greg Fordyce
Senior Member

Joined: 16/09/2011
Location: United Kingdom
Posts: 153
Posted: 08:01am 18 Aug 2015
Copy link to clipboard 
Print this post

I've been working on a project using a CMM (colour MM) in a vehicle and had a similar problem, how to shutdown cleanly when the ignition is switched off. My solution was to power the CMM through a relay from the battery, that the CMM controls, and have the CMM monitor the ignition feed. When the ignition is on the CMM keeps the relay on, when the ignition is switched off the CMM then goes to a shutdown routine, does it's logging to SD card and then switches off the relay thereby shutting itself down. The start position, through a diode, bypasses the relay and initially powers the CMM until it turns on its power relay. I use a ULN2003 as a relay driver.

Hope that helps and maybe gives you some ideas.
 
Sir_M
Newbie

Joined: 14/01/2013
Location: Sweden
Posts: 15
Posted: 08:24am 18 Aug 2015
Copy link to clipboard 
Print this post

Hi

Since you use CAN i guess that it is a Duiomite Mega.
There is a charger for battery on that and it will automaticly switch between power sources. If you measure the supply voltage you will have plenty of time to close SD-card. You could even set a time (minutes/hours pending of load) before it shut down.


Hmm, kul. Såg först efter jag svarat att du också var från Sverige :)
// Jörgen Edited by Sir_M 2015-08-19
 
bobo2
Newbie

Joined: 26/10/2012
Location: Sweden
Posts: 36
Posted: 02:12pm 18 Aug 2015
Copy link to clipboard 
Print this post

Thanks guys!
Tack Jörgen!
Yes - it is a Duinomite Mega.

I found following in the manual:

  Quote  USB-FAULT is connected to RG7 to allow the firmware to be aware that it is running on battery
instead of an external power supply. If USB-FAULT is read as 0 the board is powered by battery.
The battery charge state can be monitored by measuring the power supply on BAT port RB2.
The Lithium Polimer battery is connected via the R31/R29 voltage divider (0.319727891) to RB2 port
as RB2 can handle a maximum voltage of 3.3V but the battery voltage can go up to 4.2V when
completely charged.
DM firmware adds PIN(21) analog input pin which could be used for Battery voltage monitoring. Note
that voltage is sensed through voltage vivider as PIC32 inputs can't measure more than 3.3V while LiPo
battery voltage may go up to 4.2V when completely loaded. This is why the measured values from
PIN(21) should be multiplied by the magic number 3.13 to get the real battery voltage.


Very interesting - so I don't need any extra hardware to measure if the board is powered by battery or external power supply.

How can I put the board in "low power" mode (or switch it off completely) if it is powered by battery?
 
bobo2
Newbie

Joined: 26/10/2012
Location: Sweden
Posts: 36
Posted: 02:18pm 18 Aug 2015
Copy link to clipboard 
Print this post

It looks like the sleep function is not supported in MMBasic on the Duinomite Mega-
http://www.thebackshed.com/Forum/forum_posts.asp?TID=5559

Edit: I also found these:
Pololu Pushbutton Power Switch SV
and
toggle power switch Edited by bobo2 2015-08-20
 
bobo2
Newbie

Joined: 26/10/2012
Location: Sweden
Posts: 36
Posted: 07:01am 19 Aug 2015
Copy link to clipboard 
Print this post

  Greg Fordyce said   I've been working on a project using a CMM (colour MM) in a vehicle and had a similar problem, how to shutdown cleanly when the ignition is switched off. My solution was to power the CMM through a relay from the battery, that the CMM controls, and have the CMM monitor the ignition feed. When the ignition is on the CMM keeps the relay on, when the ignition is switched off the CMM then goes to a shutdown routine, does it's logging to SD card and then switches off the relay thereby shutting itself down. The start position, through a diode, bypasses the relay and initially powers the CMM until it turns on its power relay. I use a ULN2003 as a relay driver.

Hope that helps and maybe gives you some ideas.

Hi Greg,
Is there any chance I can see a schematic for your circuit with the relay?
 
bobo2
Newbie

Joined: 26/10/2012
Location: Sweden
Posts: 36
Posted: 10:42am 29 Sep 2016
Copy link to clipboard 
Print this post

Sorry to bring this thread to life again.
I am trying something different and can not seem to find a way to read the state of RG7 (USB-FAULT) of Duinomite Mega with MMBasic v4.5 with CAN.
I found this http://www.dontronics.com/Duino/files/Hardware/Dontronics/Olimex/Documents/Duinomite%20descriptions.pdf
But can not seem to figure out how to read it.

I would appreciate any advice!
 
bobo2
Newbie

Joined: 26/10/2012
Location: Sweden
Posts: 36
Posted: 03:47am 30 Sep 2016
Copy link to clipboard 
Print this post

Here are some videos showing some of the things I am doing with the duinomite:
https://www.youtube.com/watch?v=tblLVtNNdvs
https://www.youtube.com/watch?v=f_bFMviSBu8

The source code is at www.evmonitor.info Edited by bobo2 2016-10-01
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025