Shop OBEX P1 Docs P2 Docs Learn Events
Battery Charger — Parallax Forums

Battery Charger

TappermanTapperman Posts: 319
edited 2013-03-21 12:35 in Propeller 1
I Hope I'm not duplicating another post? I searched the forum for such a device, and did not find anything really close.

Has anyone built a battery charger from a propeller? I would love to see a schematic, if so. I've been toying around with the attached circuit, and think it has promise. It only gives feed back on the battery for now, but that's a great starting point.

A Good Charger should plot the battery voltage versus load current at any given instant, and keep track of amp hours installed in the battery, etc.

... Tim
740 x 460 - 13K
VCO.png 13.1K

Comments

  • doggiedocdoggiedoc Posts: 2,245
    edited 2012-09-15 02:28
    I'm very interested. I was researching solar charger's for my Automatic Chicken Coop Project and come across this guy that built a solar/wind charger based the 555 timer. I'd really like to know more about the theory of operation in your circuit.

    Paul
  • TappermanTapperman Posts: 319
    edited 2012-09-15 12:10
    doggiedoc wrote: »
    I'm very interested. I was researching solar charger's for my Automatic Chicken Coop Project and come across this guy that built a solar/wind charger based the 555 timer. I'd really like to know more about the theory of operation in your circuit.

    Paul

    Well, I’m not very good at explaining things. But I’ll try. If you look at the picture attached, you’ll see the functional block diagram for the 555 (8 pin DIP). There are 3 (internal) 5K ohm resistors that divide the supply voltage (Vcc, from 5 to 15v) powering the chip on pin 8. And the two comparators set and reset the internal flip-flop. The internal flip-flop operates the output line (high for ‘on’) on pin 3, as well as the discharge transistor connected to pin 7.

    But, perhaps you are already familiar with the internal design of the timer. I have wired the 555 as an ‘astable’ oscillator. And in a typical application, your RC network would be powered by the same voltage supplied to the 555. But, in the circuit I uploaded earlier, I have removed the RC network connection from the 5v supply line and connected it to an external voltage to be checked.

    One side note, I’m not sure what value my capacitor is? I am unable to read the label. But, when I connect to the RC network to the power pin (pin 8) the circuit generates a 95 Hz signal. And below is what I have measured to far:
    Batt     Freq Hz
                -------------------
                5          95
                6          180
                7.5       380
                9          565
                12        980
    

    ... Tim
    1024 x 768 - 89K
  • kwinnkwinn Posts: 8,697
    edited 2012-09-15 18:08
    doggiedoc wrote: »
    I'm very interested. I was researching solar charger's for my Automatic Chicken Coop Project and come across this guy that built a solar/wind charger based the 555 timer. I'd really like to know more about the theory of operation in your circuit.

    Paul

    In essence you are comparing the input voltage to the 5V powering the 555 timer. The thresholds for the comparators would be at 1.67V and 3.33V, so you are measuring the time it takes for the unknown voltage to charge the capacitor from 1.67V to 3.33V through the 470K resistor. This determines the frequency, which is proportional to the unknown voltage.
  • TappermanTapperman Posts: 319
    edited 2012-09-15 19:48
    kwinn wrote: »
    In essence you are comparing the input voltage to the 5V powering the 555 timer. The thresholds for the comparators would be at 1.67V and 3.33V, so you are measuring the time it takes for the unknown voltage to charge the capacitor from 1.67V to 3.33V through the 470K resistor. This determines the frequency, which is proportional to the unknown voltage.

    Yes ... That was better said than I expressed it ... the input voltage controlls the output freq.

    ... Tim
  • doggiedocdoggiedoc Posts: 2,245
    edited 2012-09-16 03:38
    Really cool. Thanks for the explanations - I'm beginning to understand the detector circuit better now. I look forward to following this project!

    Paul
  • TappermanTapperman Posts: 319
    edited 2012-09-16 09:25
    kwinn wrote: »
    the comparators would be at 1.67V and 3.33V, so you are measuring the time it takes for the unknown voltage to charge the capacitor from 1.67V to 3.33V through the 470K resistor.

    Here's the Scope look at the voltage on the cap, when measuring 9v. Notice the Max & Min voltages?

    ... Tim
    984 x 603 - 186K
  • kwinnkwinn Posts: 8,697
    edited 2012-09-16 12:00
    Thanks for posting that Tim. Nice to see the actual circuit matches the theoretical results that well.
  • TappermanTapperman Posts: 319
    edited 2012-09-16 13:10
    kwinn wrote: »
    Thanks for posting that Tim. Nice to see the actual circuit matches the theoretical results that well.

    Using it to map voltages up to 18v today!

    Going to charge a good 12v battery and then a bad 12v battery that wont take a charge, and post those scans as well.

    ... Tim
    1024 x 576 - 112K
  • TappermanTapperman Posts: 319
    edited 2012-09-17 12:53
    Here are the results between two batteries with the tester shown:

    The Bad battery is a deep cycle 12v lead acid battery from Sears. It will no longer take a charge.

    The other battery is a group 78 12v lead acid battery from my chevy van, and it takes a charge.

    ... Tim
    1024 x 576 - 118K
    1024 x 768 - 90K
  • TappermanTapperman Posts: 319
    edited 2012-09-19 13:52
    I have a question!

    I'm trying to calibrate my routine and I'm using the following:
    PUB Read555(VCO_Pin, error) | t, m
    {
        Note - This code only mearsures the 'on' time of the pulse.
    
           signal from 555 with time --->
                 |t=cnt        | return with (cnt - t)
                 |charge begin | charge end
    }
      m := 1 << VCO_Pin                                     ' mask for pin
      WaitPeq(0,m,0)                                        ' wait for zero
      WaitPeq(m,m,0)                                        ' wait for chrg to start
      t := cnt                                              ' record start time
      WaitPeq(0,m,0)                                        ' wait for chrg to end
    return cnt-t-error                                      ' return with difference
    
    PUB Calibrate(Vco_Pin) | error
    {
        Since the Read555() method only examines the 'on' time of a pulse, we must
        generate a signal that has an 'on' time of 1ms.  And, since the squarewave
        object generates 50% duty waves, we need ---> 1ms on and 1ms off for a period
        time of 2ms.  And since the freq is 1/Period, we need f=1/2ms, or 500 Hz.
        
                | 1 ms off  | 1 ms on  |
          &#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61573;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61569;&#61570;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61574;&#61573;&#61569;&#61569;&#61569;&#61569;&#61569; signal from internal ref timer A --->
                |        2ms period    |
    }
    
      sw.Freq(0, Vco_Pin, 500)                              ' generate test signal
      waitcnt(clkfreq/10 + cnt)                             ' settling time cpu.
      error := read555(Vco_Pin,0)-(clkfreq/1000)            ' error from reader
      ctra~                                                 ' stop generating signal.
    return error
    
    

    But, I am unable to read the square wave from the same pin? Will the output from the timer to a pin, be readable from the same cog containing the timer?

    ... Tim
  • TappermanTapperman Posts: 319
    edited 2012-09-20 08:45
    Well, I have got to ask the same question yet again!
    Will the output from the timer to a pin, be readable from the same cog containing the timer?

    There! Maybe it will work better if I put it in a quote box.


    ... Tim
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2012-09-20 11:57
    What kind of battery are you charging? How you set up the charge profile and charge termination greatly differs on the type of battery.

    If you are charging NiMH, check this out: http://www.panasonic.com/industrial/includes/pdf/Panasonic_NiMH_ChargeMethods.pdf
  • TappermanTapperman Posts: 319
    edited 2012-09-20 12:41
    What kind of battery are you charging? How you set up the charge profile and charge termination greatly differs on the type of battery.

    If you are charging NiMH, check this out: http://www.panasonic.com/industrial/includes/pdf/Panasonic_NiMH_ChargeMethods.pdf

    At the momemt ... I'm not charging any type of batteries ... I was asking a question about the propeller's internal structure and operation.

    Here is the very same question, for the third time!!!
    Will the output from the timer to a pin, be readable from the same cog containing the timer?

    Thank you in advance,

    ... Tim
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2012-09-20 13:11
    Ha, well, I guess the quote box didn't help then. :tongue:

    To answer your question: Will the output from the timer to a pin, be readable from the same cog containing the timer?

    Yes, you can read the state of any I/O pin at any time from any cog, even if a counter module is driving the pin. If one part of your program is driving a pin and you sample that same pin with INA[pin], whatever the state the pin is being driven to (high or low), INA will return that state.

    Even though this does not make use of a counter, consider the following demo program:
    pub go
    
      cognew(meh, $100)
    
      dira[0]~~
      dira[1]~
    
      repeat
        outa[0] := ina[1]    
    
    pub meh
    
      dira[1]~~
      repeat
        !outa[1]
        waitcnt(cnt+clkfreq)
    

    The code in the "meh" method sets pin P1 to an output and toggles that pin every second resulting in a .5 Hz frequency. This code runs freely in its own cog, cog 1. In the starting cog, cog 0, the "go" method freely runs. It sets up the pin directions of P0 and P1, then continuously copies the read state of pin P1 to pin P0.

    The resultant operation of the program is that pin P1 toggles at .5 Hz, and pin P0 mirrors the state of pin P1.

    I hope this answers your actual question.
  • kwinnkwinn Posts: 8,697
    edited 2012-09-20 13:13
    As far as I can tell from the propeller manual you should be able to read the state of a pin from any cog, including the one that is using it as an output. Never tried to do that before but I will when I get home tonight.

    RE: "I'm trying to calibrate my routine" - What are you trying to calibrate ? If you are trying to calibrate the voltage measurement I would have expected that you would have put known voltages in to the '555 and record the voltage and average count to create a calibration table and/or curve over the range of voltages you are interested in.
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2012-09-20 13:17
    I'm now writing a program to demonstrate this operation with a counter module.
  • Daniel HarrisDaniel Harris Posts: 207
    edited 2012-09-20 13:36
    Hi Tim,

    Try running this program:
    pub go | module, outPin, frq
    
      dira[0]~~
    
      module := 0                   'for counter A
      outpin := 1
      frq := 1
      
      Freq(module, outPin, frq)
      
      repeat
        outa[0] := ina[1]    
    
    
    PUB Freq(Module, Pin, Frequency) | s, d, ctr
    
    '' Determine CTR settings for synthesis of 0..128 MHz in 1 Hz steps
    ''
    '' in:    Pin = pin to output frequency on
    ''        Freq = actual Hz to synthesize
    ''
    '' out:   ctr and frq hold ctra/ctrb and frqa/frqb values
    ''
    ''   Uses NCO mode %00100 for 0..499_999 Hz
    ''   Uses PLL mode %00010 for 500_000..128_000_000 Hz
    ''
    
      Frequency := Frequency #> 0 <# 128_000_000     'limit frequency range
      
      if Frequency < 500_000               'if 0 to 499_999 Hz,
        ctr := constant(%00100 << 26)      '..set NCO mode
        s := 1                             '..shift = 1
    
      else                                 'if 500_000 to 128_000_000 Hz,
        ctr := constant(%00010 << 26)      '..set PLL mode
        d := >|((Frequency - 1) / 1_000_000)    'determine PLLDIV
        s := 4 - d                         'determine shift
        ctr |= d << 23                     'set PLLDIV
        
      spr[10 + module] := fraction(Frequency, CLKFREQ, s)    'Compute frqa/frqb value
      ctr |= Pin                           'set PINA to complete ctra/ctrb value
      spr[8 + module] := ctr
    
      dira[pin]~~
      
    
    PRI fraction(a, b, shift) : f
    
      if shift > 0                         'if shift, pre-shift a or b left
        a <<= shift                        'to maintain significant bits while 
      if shift < 0                         'insuring proper result
        b <<= -shift
     
      repeat 32                            'perform long division of a/b
        f <<= 1
        if a => b
          a -= b
          f++           
        a <<= 1
    

    This starts up counter A in cog 0 to toggle a pin (in my case, pin P1) at 1 Hz. The main loop then copies the state of P1 to P0 so that P0 mirrors the state of P1. If I understand your question correctly, this proves that you can read the state of an I/O pin being driven by a counter module at any time.
  • TappermanTapperman Posts: 319
    edited 2012-09-20 13:49
    kwinn wrote: »
    What are you trying to calibrate ? If you are trying to calibrate the voltage measurement I would have expected that you would have put known voltages in to the '555 and record the voltage and average count to create a calibration table and/or curve over the range of voltages you are interested in.

    I have that in a spread sheet already ... but, spin is slow ... and the READ555() method has an expression in the return line, so my thinking was, if I used the same routine to read the reference signal (500 Hz), which is 1 ms on and 1ms off, I should be able to calculate the 'error' between 1ms and what is being returned by the spin method. Does that make sense?

    ... Tim
  • TappermanTapperman Posts: 319
    edited 2012-09-20 15:43
    I guess there was nothing to calibrate. Turns out it was working. The original results were correct.

    It seems to return 80,000 every time I calibrate off of the 500 Hz wave ... curious, I thought it would be slightly higher.

    ... Tim

    BTW - I forgot to say thank you for the feedback!!!!
  • kwinnkwinn Posts: 8,697
    edited 2012-09-20 19:14
    Tapperman wrote: »
    I have that in a spread sheet already ... but, spin is slow ... and the READ555() method has an expression in the return line, so my thinking was, if I used the same routine to read the reference signal (500 Hz), which is 1 ms on and 1ms off, I should be able to calculate the 'error' between 1ms and what is being returned by the spin method. Does that make sense?

    ... Tim

    I think I understand what you are doing here, but I don't see how it can help with speed or accuracy. Subtracting the 500 Hz reference from the '555 signal is basically the same as subtracting a constant from the '555 frequency.

    My approach to calibrating this would be:

    Create a calibration table ( input voltage vs counts ) that has more points in the area of interest ( say 11 - 14V ) and fewer above or below that area.
    Count the pulses from the '555 for a fixed period that is long enough to provide a good stable average and store the count for each voltage point.

    To calculate the battery voltage search for the first point that is lower than the current count and use that point and the next one higher for a straight line interpolation between those points.

    Simple to program and provides pretty good accuracy.
  • Christof Eb.Christof Eb. Posts: 1,234
    edited 2012-09-21 03:43
    Hi Tim,
    the timers have no capture-mode, so they are not very well suited for time measurements.
    But there is the wait-port-equal statement, which makes it possible to wait for a signal and store then cnt. If you do that twice, you can measure the time-.difference bewteen two flanks.

    wait for low
    wait for high
    a = cnt
    wait for low
    wait for high
    b=cnt
    difftime = b-a

    I assume, that spin will be fast enough for 500Hz.

    Good luck!
    Christof
  • TappermanTapperman Posts: 319
    edited 2012-09-21 09:18
    wait for low
    wait for high
    a = cnt
    wait for low
    wait for high
    b=cnt
    difftime = b-a

    Thankyou for your input. And that will give you the period time. But I should explain

    This would return the wrong time! You see when you charge the cap with a high enough external voltage, the 'off' time begins to increase! So I choose to read only the 'on' time for the 555. This is the time pin 7 is 'open' and not discharging the cap. Then I calculate a freq from that time (as though it were the period time [on+off])

    The hope is to avoid including any of the 'off' time from the 555.

    This means the a-stable formula for the 555 (ie, ln(2)rc) to charge will not apply. You need to realize that the charge time is the integral of current into the cap. And this is the difference between (applied external voltage and cap voltage)/470k ohms integrated from a lower limit of 5/3 volts to 10/3 volts (assuming the external voltage doesn't vary to much in that time).

    The nice part, is when reading voltage between 10v and 24v (my current max), the change in freq is linear with voltage (nearly).

    ... Tim
  • kwinnkwinn Posts: 8,697
    edited 2012-09-21 21:53
    Battery voltage is a slow changing variable so I am wondering why you would go to all this work. You could add a single resistor to the circuit to make it a standard astable oscillator and then count the pulses for a fixed period of time to obtain the input voltage.
  • TappermanTapperman Posts: 319
    edited 2012-12-15 16:57
    kwinn wrote: »
    Battery voltage is a slow changing variable so I am wondering why you would go to all this work. You could add a single resistor to the circuit to make it a standard astable oscillator and then count the pulses for a fixed period of time to obtain the input voltage.

    I believe this should clear up 'how'... as to why? Because I like it! Even though I often re-invent the wheel (as it were), I truly enjoy the learning experience that goes with it, more than the final product!

    ... Tim
  • kwinnkwinn Posts: 8,697
    edited 2012-12-15 18:08
    Tapperman wrote: »
    ... as to why? Because I like it! Even though I often re-invent the wheel (as it were), I truly enjoy the learning experience that goes with it, more than the final product!

    ... Tim

    Can't argue with that. It will work at least as well as what I suggested.
  • TappermanTapperman Posts: 319
    edited 2013-03-21 12:35
    Followup, Have added a current meter (home built). The included files, show the light bulb start up current on it's way to 5amps running on 12v batt.

    Have never had a current meter fast enough to see this before.

    ... Tim
    1024 x 768 - 52K
    1024 x 768 - 99K
Sign In or Register to comment.