PDA

View Full Version : Check for low battery


mcervi
05-24-2010, 08:56 AM
I am using the RF Engine (RF100PC6) with firmware 2.2.16, in a battery-powered application.

I would like to have a method to determine if the battery is low. I don't care about measuring the battery voltage in detail; just a 'low battery' indication would be sufficient.

I've seen the example scripts for measuring the battery voltage using the ADC, and they seem to involve the use of external components and at least one externally-wired I/O pin.

Then, just a few minutes ago, I was trying to program a script into one of the RF Engines and I got a warning in portal saying the device's battery was too low to allow programming to proceed. The exact text was "An error occurred while writing the SNAPpy image, operating voltage too low".

How is this able to measure the battery without any external components? Is there a way to tap into this existing battery monitoring functionality from my own script?

P.S. I noticed that you can still do a firmware upgrade using the same set of dead batteries whose voltage is too low to program scripts into the device. :confused:

RFAndy
05-24-2010, 04:40 PM
I also asked the same question but there was no answer on this forum? (see below) :confused:

Note: I think the battery range is from 2.7 - 3.4 VDC.
What a person can do, if this question is not answered on this forum, is to connect a precision variable power supply, in place of the battery and run it down on the low end.

Low voltage protection on RFET :confused:

From the 2.2 Migration Guide -- on page 16:
Quote: "Low Voltage Detection SNAP nodes now have the ability to detect a low voltage condition. When this condition is detected then writing to flash is disabled to prevent corruption. It is important to note that script uploading writes to flash which means a script upload may be prevented due to a low voltage condition."

Question:
At what low voltage (on the Synapse RFET RF Engine) does this occur at? The low voltage trigger or setpoint ? :confused:

kbanks
05-24-2010, 05:28 PM
P.S. I noticed that you can still do a firmware upgrade using the same set of dead batteries whose voltage is too low to program scripts into the device.


The bootloader predates the addition of "low voltage checks" (it is several years old).

If your unit has already told you voltage is bad, stop trying to write to the FLASH!

You can read about the "low voltage detector" in the Freescale data sheets (there is a link to them on this forum). It is a very coarse (good/no good) reading, not an actual battery level.

As mentioned in this thread, example scripts and schematics for true battery monitoring are over in the Script Exchange section of the forum.

mcervi
05-24-2010, 10:54 PM
Thanks for pointing me in the right direction. In case anyone else is interested in this I figured I'd post the basics here.

See page 80 of the following datasheet:
http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08GB60A.pdf?fsrch=1

Bit 7 of register SPMSC2 (address 0x180A) is the low voltage warning flag.

On my RF engine, doing a peek() of address 0x180A returns:
176 = 0xB0 = 10110000 on low batteries
48 = 0x30 = 00110000 on good batteries

So, it seems to work. Apparently, two low voltage warning thresholds are available; the one that appears to be in use by default is 2.4V.

There are more details in the datasheet (clearing the warning flag, etc.) but this will suffice for my needs. At least now I can tell if the batteries are low without needing to add any external components to my circuit or tie up any I/O pins.

capr1c0rn058
07-27-2010, 03:58 PM
I use battery powered SNAP nodes on Atmega128RFA1 platform and i wanted to know which address on this platform memory should i peek into to check for low/good battery powers without having to use any external components.


Thanks

capr1c0rn

gre7g
07-27-2010, 04:38 PM
The ATmega128RFA1 does not have a zero-component-low-voltage-detector.

For the RF200, you will need a pair of resistors to step VCC down to something within the ADC range and then dedicate one of the ADC pins to measuring the supply voltage.

capr1c0rn058
07-28-2010, 10:28 AM
I was going through the ATmega128RFA1 datasheet and i found that there is a way to monitor the battery. Check 9.6.4 section to find Battery Monitor (BATMON) which explains the setting of Threshold voltage and then checking the bits BATMON_OK to know if the node is operating in low/good voltage.
Is there any way i can access this BATMON register?

gre7g
07-28-2010, 10:33 AM
Well I'll be! I was not aware that was in there. This chip is full of surprises.

Try doing a peek or poke of 0x151 and see if it works. The bits of the register are described in 9.12.21.

Also, please post your results here so that other RF200 users can leverage your findings.

capr1c0rn058
07-28-2010, 11:52 AM
I was able to the peek(0x151) and i got a result '34' which means BATMON_OK = '1' and BATMON_VTH = '0010' meaning a Threshold voltage of 2.7V and a battery which is working perfectly fine.

I have doubt regarding poking this address. In the data sheet it is mentioned that BATMON_OK is read-only value. I actually want to increase the Threshold voltage to check if the feature is working fine. Can i poke(0x151,16) so as to mention BATMON_VTH to be '1111' ie a threshold voltage of 3.675V?

gre7g
07-28-2010, 12:03 PM
You should be able to poke it quite easily. poke(0x151, 0x1F) will set it to 3.675. Then peek(0x151) and it should read 31 instead of 63. That will indicate that the BATMON_OK bit is off.

gre7g
07-28-2010, 12:18 PM
I just borrowed an RF200 and BATMON works great. Here's the snippet I used:

BATMON = 0x151
BATMON_OK = 0x20

def test():
i = 0
while i < 0x20:
poke(BATMON, i)
if peek(BATMON) & BATMON_OK:
i += 1
else:
return "BATMON_OK=0 when level="+str(i)
return "BATMON_OK=1 regardless of level set"It returned:

2010-07-28 12:14:03 TM5: Return Value = BATMON_OK=0 when level=27level=27 means BATMON_HR=1 and BATMON_VTH=B, so at a threshold of 3.300V the power was okay and at 3.375V it was not. Perfect!

capr1c0rn058
07-28-2010, 12:20 PM
I tried poking with poke(0x151, 0x1F) and got a result 159. which is '10011111' signifying BAT_LOW='1', BATMON_OK = '0' and BATMON_VTH='1111' as set.

It seems to work fine.

I had previously set BATMON_VTH to 2.7v. Was using a used up battery to test the feature and i was just able to send one rpc after which the battery went dead. And the BATMON_OK reading was '1'. I understand that a node works on min voltage of 2.7V. So,do u recommend me to set the BATMON_VTH to 2.850/2.925V to satisfy my requirement of knowing if node is running on low/good battery?

gre7g
07-28-2010, 12:31 PM
It surprises me that you could only run down to 2.7V. The processor should be okay all the way down to 1.8V. Do you have anything else on the board that has a higher limit?

capr1c0rn058
07-28-2010, 01:41 PM
I am using STK600 board and not using any other pins.

gre7g
07-28-2010, 01:44 PM
Do you have a benchtop supply to do more tightly-controlled tests?

capr1c0rn058
07-28-2010, 01:46 PM
Nope i was using a 3.7/25mAh battery. I should probabaly test it on a variable supply.

gre7g
07-28-2010, 01:47 PM
That would be my advice. To be able to set levels correctly, you're going to need to do controlled and repeatable tests.

capr1c0rn058
07-28-2010, 03:03 PM
I did perform the test and the results have been as expected. The lowest voltage level taken by the board is 1.85V. So i have decided to set the BATMON_VTH to 0x05 ie 2.925 to 1.95V, so as to satisfy my requirements.