Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Read voltage level of a single battery pack and report to software.
- # Adapted from LiPo monitor circuit.
- # Assumed monitor circuit connected to ADC0
- # Set variables
- # Default values set for 12v Lead Acid. For 6v divide by 2
- # Change $vundervoltage to the under voltage of your specific battery if required
- # Change $vcritical to your lowest voltage you wish for the battery to get before human intervention
- # Change $vmin to low level alert value
- # Change $vmax to battery full charge
- # Change $multiplyer if using voltage divider
- # Factor is 5/255 for adc value conversion to volts
- $vundervoltage = 10.50
- $vcritical = 11.31
- $vmin = 11.58
- $vmax = 12.70
- $multiplier = 4
- $factor = 0.019607843
- :ReadCells
- # Get ADC values
- $vc1 = GetADC(ADC0)
- # Convert values to voltage to 2 decimal places
- $batterylevel = $vc1 * $factor
- $batterylevel = $batterylevel * $multiplier
- $batterylevel = Round($batterylevel,2)
- # Check for errors on circuit
- IF ($batterylevel > $vmax)
- Print("Battery Monitor Error")
- Print("Check Monitor Circuits")
- # Check for errors on battery connection
- ELSEIF ($batterylevel <= 0)
- Print ("Battery Connection Error")
- Print ("Check Battery Connection")
- # Check for under voltage
- ELSEIF ($batterylevel <= $vundervoltage)
- Print ("Battery Under Voltage")
- Print("Check Or Replace Battery")
- # Check if at critical levels
- ELSEIF ($batterylevel <= $vcritical)
- # Do sometihing if critical
- Print("Battery Critical")
- # Shut down all power, switch to back up battery alarm?
- # Check if below recommended levels
- ELSEIF ($batterylevel < $vmin)
- # Do something if voltage low
- Print("Battery Level Low")
- ELSE
- # Output voltages
- Print($batterylevel + "V")
- # Output to LCD display here (if required)
- ENDIF
- # Wait 5 seconds
- Sleep(5000)
- # Go back to the start
- Goto(ReadCells)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement