Shop OBEX P1 Docs P2 Docs Learn Events
Hackable Badge Battery Voltage on Display? — Parallax Forums

Hackable Badge Battery Voltage on Display?

shawnerzshawnerz Posts: 6
edited 2015-11-08 21:19 in Propeller 1
Hello all.
I've got a newbie question. I have my badge. Played with the code. Everything works great. I thought I read a forum post that someone was able to get the badge to display its battery voltage. The gist of the thread was that it was not measuring properly.
I have searched but I cannot find that thread. I would like my badge to display the battery voltage as well. Oh, I poked around in github as well, and didn't find what I was looking for.
Is it a register I have to read from? Is there an ADC to query?
And just to verify, the Hackable Badge is built around a Propeller I, right?
Thank you very much in advance,
-Shawn

Comments

  • The Hackable Badge is indeed built around a Propeller.

    I/O pin 0 (P0) of the Propeller is connected to an RC network with a 0.01uF capacitor charged from the battery through a 300K resistor. P0 is connected through a 1K resistor to the capacitor. You can set P0 to output a zero which will discharge the capacitor, then change P0 to input mode and measure how long it takes to charge up to the switching threshold of P0 (until P0 becomes a 1). There's some variation in the switching threshold from device to device and it will also change with the supply voltage. Best thing to do is to use an accurate voltmeter to calibrate this battery voltage measuring setup. There's a discussion of this technique in the Basic Stamp Reference Manual under the RCTIME statement and some discussion here.
  • JonnyMacJonnyMac Posts: 8,927
    edited 2015-11-09 16:19
    If you're programming the badge in Spin, here's a method that will read the RC circuit as Mike described (this counts on constants found in the eBadge base code).
    pub read_battery | level 
    
    '' Returns battery level
    '' -- value returned is RC charge time in microseconds
    '' -- will require calibration for volts
    
      level := 0
    
      ctra := %01100 << 26 | BATT_MON                                ' setup counter to measure low
      frqa := 1
      outa[BATT_MON] := 0
      
      repeat 4
        dira[BATT_MON] := 1                                          ' discharge rc
        waitcnt(cnt + (MS_001 << 1))
        dira[BATT_MON] := 0                                          ' allow RC to charge
        phsa := 0                                                    ' clear sample
        repeat until ina[BATT_MON]                                   ' wait until finished
        level += phsa                                                ' add sample to level
    
      ctra := 0                                                      ' release counter
    
      return (level >> 2) / US_001                                   ' return average of 4 reads
    
Sign In or Register to comment.