DavidM
09-09-2007, 05:05 PM
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!
'' 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[16..23]~~ ''Make leds outputs
OUTA[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[16..23]:=%11111111 ''13.0 Volts - Fully Charged 13V??
128..127: OUTA[16..23]:=%11111110 ''12.8 Volts
126..125: OUTA[16..23]:=%11111100 ''12.6 Volts
124..123: OUTA[16..23]:=%11111000 ''12.4 Volts
122..121: OUTA[16..23]:=%11110000 ''12.2 Volts
120..116: OUTA[16..23]:=%11100000 ''12.0 Volts
115..101: OUTA[16..23]:=%11000000 ''11.5 Volts
100..0 : OUTA[16..23]:=%10000000 ''10.0 Volts - Battery Just about Dead, 10V??
PUB GetVoltage(vRcTimePinNo) : vBatteryVoltage
RcTemp := 0 ''Initialise RcTemp
OUTA[vRcTimePinNo] := 0 ''Set it Hi to CHARGE capacitor
DIRA[vRcTimePinNo] := 1 ''Make pin an OUTPUT
WAITCNT(CLKFREQ / 2000 + CNT) ''PAUSE for 0.5ms
DIRA[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
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[16..23]~~ ''Make leds outputs
OUTA[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[16..23]:=%11111111 ''13.0 Volts - Fully Charged 13V??
128..127: OUTA[16..23]:=%11111110 ''12.8 Volts
126..125: OUTA[16..23]:=%11111100 ''12.6 Volts
124..123: OUTA[16..23]:=%11111000 ''12.4 Volts
122..121: OUTA[16..23]:=%11110000 ''12.2 Volts
120..116: OUTA[16..23]:=%11100000 ''12.0 Volts
115..101: OUTA[16..23]:=%11000000 ''11.5 Volts
100..0 : OUTA[16..23]:=%10000000 ''10.0 Volts - Battery Just about Dead, 10V??
PUB GetVoltage(vRcTimePinNo) : vBatteryVoltage
RcTemp := 0 ''Initialise RcTemp
OUTA[vRcTimePinNo] := 0 ''Set it Hi to CHARGE capacitor
DIRA[vRcTimePinNo] := 1 ''Make pin an OUTPUT
WAITCNT(CLKFREQ / 2000 + CNT) ''PAUSE for 0.5ms
DIRA[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