Low-Power-Detection needed

Hi Folks, with my Arduino Nano I'm collecting telemetry-data of my model-airplane. One value I'm collecting is the fuel-level of the tank. During power-off the arduino, I would like to write the actual value of the Counter into the EEPROM. Therefor I Implemented an external Interrupt by:

attachinterrupt(1, SaveTankCount, FALLING);

Interrupt-Routine:

void SaveTankCount()
{
  EEPROM.writeInt(0, TankVolumenAktuell);
}

The code works fine. My Problem ist to detect the power-down cycle of the arduino, to write the value to the EEPROM as the last action.

Does the Arduino / ATmega328 have something like Low-Power-Detection that I can use for this ?

Can somebody help me?

Thanks in advanced, Bernie

Hi Bernie,

If I understand enough from your description, your sensor connot directly measure the level of fuel in the tank, perhaps because of the movement of the plane. Instead, it gives a signal each time a small measured volume of fuel flows to the motor?

Does the Arduino pick up that signal and calculate the fuel level? If so, if you record to eeprom each time you update the fuel level, you will not need to detect power down.

The only problem with that idea is that it will write more frequently to the eeprom. The eeprom has limited life, perhaps at least 100,000 writes. How frequent are these signals? If they are every 10 seconds, the eeprom will last 300 hours of flight. How long do the other components in the plane last?

Paul

Hi Paul,

yes your Interpretation ist correct. The sensor gives a low-signal every 1ml used fuel. The tank has about 1500 ml capacity. After 60-70 flights the eeprom will be gone. That's why I try to write the eeprom just when the power goes down.

I tried to solve the Problem using a capacitor of about 100µF between VCC an GND. Additional a Diode in front of the Battery (between VCC and Battery) . Pin D3 (Interrupt 1) I connected direct at the battery.

The idea was to buffer the power in the capacitor for writing the eeprom. At D3 the nano should detect the power-down. But this does not work reliable.

Do you have any suggestions for me how to solve the problem?

Bernie

I would not use the interupt routine to write to the EEPROM. I would use it to increment (or decrement) a variable. Then occasionally you can write that value to the EEPROM.

You can use the ADC on the Arduino to measure the battery voltage and you could use that to determine when the "fuel" value needs to be written to the EEPROM.

...R

Hi Robin,

yes I use the second Interrupt of the nano, to decrement the Counter. But it will not help to monitor the battery voltage using a ADC, because I don’t have to detect an empty battery. I have to detect the power-down using a mechanical power-Switch. And in case of “switchin-off” the device, saving the countervalue must be very fast. If you know what I mean…

I think the Interrupt-routine as schown above works fine. The problem ist to detect the power-off Status.

I tried to use an OP to detect the power-down. The OP was configured as a comperator. But it also detect the power-down not as fast as it was needed.
Now the battery is empty, I have to charge them. I will continue tomorrow.

Maybe I get the solution during a sleepless night…

Thanks for your help!

Bernie

Write the value whenever the throttle goes to idle?

Bernie0663:
After 60-70 flights the eeprom will be gone.

Would around 2000 flights be enough?

The Nano’s atmega328 has 1024 bytes of eeprom, organised into 32 pages of 32 bytes each, I have read. Each page can be written to 100,000 times. So if you can spread the writing evenly over those 32 pages, you get 3.2M writes.

You can do this by maintaining a variable which records the eeprom address that should be written to next. Each time you write the fuel value to eeprom (at the address given by that variable), you then add 32 to the variable so that the next write goes to the next page. When the variable gets to 1024, set it back to zero.

When the Arduino starts up or gets reset, in the setup() function, you can search each of the 32 pages for the lowest fuel value recorded, and where you find it, set your variable with the address for the next write.

Of course, when you refill the tank, you will need to reset all 32 addresses back to 1500.

You’ve probably heard of this idea: “wear levelling”.

Paul

Bernie0663: And in case of "switchin-off" the device, saving the countervalue must be very fast. If you know what I mean...

I did not realize that is what you want to do.

I think a large part of the answer must lie in an "improved" switch-off procedure.

Can you arrange that the "off" switch just sends a signal to the Arduino and, after saving data, the Arduino then turns off its own power - perhaps via a relay.

The alternative, I think, is to save the data every (say) 5 or 10 seconds and accept the fact that up to 10 seconds worth of data may get lost at power off.

...R

Hi,

now I got it. It works with some external elements:
(See attached file)

I modified the value of the capacitor to 1000µF. And I uses a voltage divider (R2, R3) to detect the power down using an OP 741.
(R1 is not correct! I used a 100K one.)

This small HW works perfect on a 2-cell Lipo-battery as I want to.

i say thank you for your Support.
Maybe someone an use this also…

Thanks, Bernie