Shop OBEX P1 Docs P2 Docs Learn Events
C3 Analog Port Header usage — Parallax Forums

C3 Analog Port Header usage

RsadeikaRsadeika Posts: 3,837
edited 2011-01-16 19:24 in Propeller 1
I will be using the C3 on my mobile robot, and I would like to keep track of the charge state in the two 6VDC (8 and 10) amp hour batteries. I have used a voltage divider setup to bring the voltage down to the 5VDC level, and then try to figure what the actual voltage of the batteries are. Is there a better way of doing this with the C3? Anybody have some slick solutions or examples out there?

Thanks
Ray

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-16 08:14
    I'm doing the same thing on a custom board, reading the input voltage (12 to 24v) through a divider using the MCP3208 (same family) and converting to millivolts like this
    volts := (5_000 * adc[7] / 4_095) * constant(14_700 + 1_620) / 1_620
    

    The top side of the divider is a 14.7K resistor, the bottom side is a 1.62K resistor. It works well.
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-01-16 08:37
    Thanks JonnyMac. The first problem I have now is, I used to have a formula for figuring out the size of the resistors I would need, I cannot find where I got the information from. I had it in a spreadsheet, plug a value(s) in, and voila, the resistor values, but it is now lost or hiding somewhere. The second problem is, because the batteries would charge to different values at each charge, I was having a problem getting the correct resistor values. It has to be pretty close to what the actual battery charge level is, otherwise when the robot is to far away from the charge station, it will die, and then I have to carry the robot back. I also want to have it check the charge state when on the charger, then it will automatically back off, and continue its programmed chore.

    Ray
  • AndreLAndreL Posts: 1,004
    edited 2011-01-16 12:48
    @rsadeika,

    There is no formula per se, just ohms law really. V=I*R and the voltage divider equation. So, in this case, you have a number of variables and not enough constraints, this is fine, just set up some node or loop equations for the circuit and then pick a value, and then let the other value fall out of that constraint, then pick another value and adjust until you find the values that give you the max range you want, have the correct impedance and satisfy what you are trying to do. Basically, just use a heuristic algorithm and a few values. Of course, there always is away to do the calculations, but its not needed if you use some rough guestimates and trial and error on paper or spread sheet.

    Andre'
  • RsadeikaRsadeika Posts: 3,837
    edited 2011-01-16 13:52
    I was searching on the WEB and I found this http://www.raltron.com/cust/tools/voltage_divider.asp Just to test out the calculator I plugged in JonnyMac resistor values, and the output V, I am assuming that the output voltage he is looking for is 5V. Now, according to the calculator, it is showing an input voltage of 50.37V. Can this calculator be trusted, or do I have to rethink what I think I know about voltage dividers.

    I have not checked my battery values after a full charge, but I think it was 6.25V. Using the above mentioned calculator, it shows r1 - 250, r2 - 1000 would get me 5V output. I chose 250, and 1000, because I have those resistors available. I guess what I am thinking is, I check the charged value of the battery, and use the highest value, then pick the resistor values that I have on hand. Then I can use JonnyMac formula with my values, is this correct?

    Ray
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-01-16 19:24
    You must be very careful not to grab values from others -- in fact, I didn't design the circuit I'm programming for and would have used different values. My point was to illustrate that you could write code that gives you the desired feedback and is easy to understand and update.

    I suspect your batteries could charge somewhere north of 6v so you should prepare for this. For example, use 8v. In an ideal situation you'd like to have a divider that gives you pretty close to 5v (full-scale input of the adc) at the tap when you have 8v on the input. With arrangement the ration of the stack (both resistors) to the one below the tap is 8 / 5. You may have to select empirically to find the best combination, and building a little spreadsheet will help.
Sign In or Register to comment.