Trouble with RCTIME to monitor a 12V SLA Battery
DavidM
Posts: 630
HI,
I am having trouble with RCTIME to monitor a 12 VOLT SLA BATTERY ( the battery is used to power the propeller circuit and I want to display its "LEVEL" on 8 LED's. in this case I am just using the 8 LED's of the PROP DEMO Board.
Attached is my code and schematic..
I think I have the correct idea but i am not sure of some of the values/calculations for ..
1) PAUSE the start of the routine so as to CHARGE the CAPACITOR
2) ADJUST the time for the SPIN code that has executed so far.
3) Once I get some kind of value I need to "SCALE" / ADJUST" it to meet my desired output.
I am getting NO RESULTS so far and I also don't have any DEBUGGING setup, BUT I believe I need it for this kind of task.
My RCTIME routine is called "GetVoltage"
I don't even think my capacitor is charging!
Thanks
Dave M
I am having trouble with RCTIME to monitor a 12 VOLT SLA BATTERY ( the battery is used to power the propeller circuit and I want to display its "LEVEL" on 8 LED's. in this case I am just using the 8 LED's of the PROP DEMO Board.
Attached is my code and schematic..
I think I have the correct idea but i am not sure of some of the values/calculations for ..
1) PAUSE the start of the routine so as to CHARGE the CAPACITOR
2) ADJUST the time for the SPIN code that has executed so far.
3) Once I get some kind of value I need to "SCALE" / ADJUST" it to meet my desired output.
I am getting NO RESULTS so far and I also don't have any DEBUGGING setup, BUT I believe I need it for this kind of task.
My RCTIME routine is called "GetVoltage"
I don't even think my capacitor is charging!
'' RCTIME 12V BATTERY MONITOR TEST CON _CLKMODE =XTAL1 +PLL16X _XINFREQ =5_000_000 VAR LONG RcTimePinNo LONG BatteryVoltage LONG RcTemp PUB Main RcTimePinNo :=0 DIRA[noparse][[/noparse]16..23]~~ ''Make leds outputs OUTA[noparse][[/noparse]16..23]:=%00000000 ''Turn them off REPEAT BatteryVoltage:=GetVoltage( RcTimePinNo) '' VALUE between 130 to 100 to be returned 13V to 10V ?? CASE BatteryVoltage 130..129: OUTA[noparse][[/noparse]16..23]:=%11111111 ''13.0 Volts - Fully Charged 13V?? 128..127: OUTA[noparse][[/noparse]16..23]:=%11111110 ''12.8 Volts 126..125: OUTA[noparse][[/noparse]16..23]:=%11111100 ''12.6 Volts 124..123: OUTA[noparse][[/noparse]16..23]:=%11111000 ''12.4 Volts 122..121: OUTA[noparse][[/noparse]16..23]:=%11110000 ''12.2 Volts 120..116: OUTA[noparse][[/noparse]16..23]:=%11100000 ''12.0 Volts 115..101: OUTA[noparse][[/noparse]16..23]:=%11000000 ''11.5 Volts 100..0 : OUTA[noparse][[/noparse]16..23]:=%10000000 ''10.0 Volts - Battery Just about Dead, 10V?? PUB GetVoltage(vRcTimePinNo) : vBatteryVoltage RcTemp := 0 ''Initialise RcTemp OUTA[noparse][[/noparse]vRcTimePinNo] := 0 ''Set it Hi to CHARGE capacitor DIRA[noparse][[/noparse]vRcTimePinNo] := 1 ''Make pin an OUTPUT WAITCNT(CLKFREQ / 2000 + CNT) ''PAUSE for 0.5ms DIRA[noparse][[/noparse]vRcTimePinNo] := 0 ''Make pin an INPUT RcTemp := CNT ''TRAP the current Time in RcTemp WAITPEQ( 1, vRcTimePinNo, 0 ) ''WAIT until a change occurs on pin RcTemp := || ( CNT-RcTemp) ''Calculate the time LAPSED RcTemp := RcTemp - 1600 ''ADJUST the time for SPIN code executed vBatteryVoltage :=RcTemp ''Divide by 16 and store in the Battery Voltage Variable
Thanks
Dave M
Comments
You need to discharge the capacitor first then let the +12V charge it which by the way is what you are actually doing. The RC time constant does not change but the of course the time it takes to get to the logic inputs threshold voltage will decrease with higher voltage due to higher charge rate.
Why isn't RcTimePinNo set to the pin mask because 0 will not achieve anything. If it is P8 for instance then the mask should be %1_0000_0000.
*Peter*
EDIT:
My mistake Dave, it was late and I sometimes forget this is Spin on the prop. OUTA and DIRA do take a pin number, not a mask. Is P0 the pin you are using?
*Peter*
Post Edited (Peter Jakacki) : 9/9/2007 10:36:05 PM GMT
Yes PIN 0 is the pin I am using that is connected to the capacitor, Did you look at my schematic?
It also declares is here in my code..
PUB Main
RcTimePinNo :=0
So I gather I have to discharge that cap first, Is that what the PAUSE is for?
So I have modified my code as below.
Thanks
Dave M
WAITPEQ( 1, vRcTimePinNo, 0 ) ''WAIT until a change occurs on pin
should be..
WAITPEQ( 1, |<vRcTimePinNo, 0 )
the |< operator is a bitwise decode which will take any pin NUMBER 0-32 and convert it to the correct bit pattern
ie. %00000000_00000000_00000000_00000001
Is this correct?
Thanks
Dave M
*Peter*
Although the capacitor charging is non-linear you will find that the initial charge curve is fairly linear so you can read the value and perform a simply calculation to get the volts.
*Peter*