BillyGreen1973
Senior Member
I'm using an 18M2 in the SD21 servo module, running off 4x1.5v AA cells. This will be the backbone of a 19 servo robot I am building.
So far everything is set up fine, I2C works great and I can control all the servos.
The problem I am having is a maths one really.
If you read register 65 on SD21 it returns a number between 0 and 255 relating to battery voltage. Each devision is equal to 39mV so for example if register 65=159...
159 x 39 = 6201
This is 6.201v
I am displaying this info an the AXE033 using this sub routine
This works ok as long as the decimal place is more than 100 (ie 0.100)
if the voltage drops (for example register 65= 156, ie, battery voltage is 6.084), the leading '0' in the decimal is dropped to give a reading of 6.84v
First how can I get just 1 or 2 decimal place accuracy?
and how can I keep the leading 0?
AS you can see I'm a newbie at PicaxeBasic, so any help would be much appreciated.
So far everything is set up fine, I2C works great and I can control all the servos.
The problem I am having is a maths one really.
If you read register 65 on SD21 it returns a number between 0 and 255 relating to battery voltage. Each devision is equal to 39mV so for example if register 65=159...
159 x 39 = 6201
This is 6.201v
I am displaying this info an the AXE033 using this sub routine
Code:
ReadBatt:
hi2cin 65, (b9) 'Read Battery Voltage
w5=b9*39 'multiply register 65 by 39 to get voltage in mV
w6=w5/1000 'returns the voltage whole number into w6
w7=w5//100 'returns the decimal places of volts into w7
serout 7,N2400,(254,128)
pause 10
serout 7,N2400,(" Batt= ",#w6,".",#b14,"V ")'send batt voltage to LCD
pause 10
'sertxd ("batt= ",#w6,".",#w7,"V ",#b9,CR, LF) 'send batt voltage to terminal
Return
if the voltage drops (for example register 65= 156, ie, battery voltage is 6.084), the leading '0' in the decimal is dropped to give a reading of 6.84v
First how can I get just 1 or 2 decimal place accuracy?
and how can I keep the leading 0?
AS you can see I'm a newbie at PicaxeBasic, so any help would be much appreciated.