PDA

View Full Version : ATmega128RFA1 BATMON


andre.marschalek
10-03-2011, 09:29 AM
hi

the ATmega128RFA1 Microcontroller has a built-in Battery Monitor

BATMON() returns the current Voltage


def lr_vth(nibble):
bits = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\ x0C\x0D\x0E\x0F'
return ord(bits[nibble])
def hr_vth(nibble):
bits = '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\ x1C\x1D\x1E\x1F'
return ord(bits[nibble])
def lr_voltage(nibble):
voltage = ('1.70','1.75','1.80','1.85','1.90','1.95','2.00', '2.05','2.10','2.15','2.20','2.25','2.30','2.35',' 2.40','2.45')
return voltage[nibble]
def hr_voltage(nibble):
voltage = ('2.550','2.625','2.700','2.775','2.850','2.925',' 3.000','3.075','3.150','3.225','3.300','3.375','3. 450','3.525','3.600','3.675')
return voltage[nibble]
def BATMON():
batval = '0.000'
# HR 3.675V - 2.550V
i = 15
while i > 0:
poke(0x151, 0x1F & hr_vth(i))
if peek(0x151) & 32 == 32:
batval = hr_voltage(i)
if batval == '0.000':
i = i - 1
else:
i = 0
i = i - 1
if batval == '0.000':
# LR 2.45V - 1.70V
i = 15
while i > 0:
poke(0x151, 0x0F & lr_vth(i))
if peek(0x151) & 32 == 32:
batval = lr_voltage(i)
if batval == '0.000':
i = i - 1
else:
i = 0
return batval


br
Andre

jcwoltz
10-26-2011, 08:31 AM
Thank you for posting this!
I have not had a chance to try this out, yet, but I will.
I really like people posting things about low level ATMega128RFA1 registers/features!

Thank you,
J.C. Woltz

satish2858
04-01-2012, 01:28 PM
@andre.marschale

Hi,
thank u for this information , because i was planning to buy a IC to monitor the battery on RF200PD1 module as it has Atmega128RFA1 i could use this program .

But, how should i load it in to the module , because there where no Startup_HOOK function used and not even where to log the data which has been measured . It might be a silly question.

thanking you satish2858

satish2858
04-01-2012, 05:37 PM
@andre.marschale

Hi,
the post #3 which i posted at that time i cold not under stood how to use use it.

after few traile and error method at could use your ur code on RF200PD1 atmega128RFA1.yes it is working.

here what i did

from synapse.platforms import *
from synapse.evalBase import *
portalAdd='\x00\x00\x01'


@setHook(HOOK_STARTUP)
def startupEvent():
"""This is hooked into the HOOK_STARTUP event"""
initProtoHw()


@setHook(HOOK_1S)
def bat():
batt_val=BATMON()
batt_val_1= batt_val
rpc(portalAdd,"logEvent",batt_val_1)

def lr_vth(nibble):
bits = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\ x0C\x0D\x0E\x0F'
return ord(bits[nibble])
def hr_vth(nibble):
bits = '\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\ x1C\x1D\x1E\x1F'
return ord(bits[nibble])
def lr_voltage(nibble):
voltage = ('1.70','1.75','1.80','1.85','1.90','1.95','2.00', '2.05','2.10','2.15','2.20','2.25','2.30','2.35',' 2.40','2.45')
return voltage[nibble]
def hr_voltage(nibble):
voltage = ('2.550','2.625','2.700','2.775','2.850','2.925',' 3.000','3.075','3.150','3.225','3.300','3.375','3. 450','3.525','3.600','3.675')
return voltage[nibble]
def BATMON():
batval = '0.000'
# HR 3.675V - 2.550V
i = 15
while i > 0:
poke(0x151, 0x1F & hr_vth(i))
if peek(0x151) & 32 == 32:
batval = hr_voltage(i)
if batval == '0.000':
i = i - 1
else:
i = 0
i = i - 1
if batval == '0.000':
# LR 2.45V - 1.70V
i = 15
while i > 0:
poke(0x151, 0x0F & lr_vth(i))
if peek(0x151) & 32 == 32:
batval = lr_voltage(i)
if batval == '0.000':
i = i - 1
else:
i = 0
return batval

I used ur code but i could not under stood the logic which u had used

1.poke(0x151, 0x0F & lr_vth(i))
2.peek(0x151) & 32 == 32:

you had used two fuctions peek and pook with some addresses in side hat r they actually represent .

if possible please add few documentation in ur code above.

why i am asking you because , please check out this post of mine

http://forums.synapse-wireless.com/showthread.php?t=2072

if u could help me in this please help me .

thanking you
satish 2858