Hello, I was reading a post a few days ago here on the on-board power reader and now i’m trying to make a program to display the power (0-100%) on a LCD screen. What my probable is that my power variable (byte) is not staying a steady value. I don’t having anything hooked up to (servos and motors and such) when i tested it except the 20 x 4 serial LCD. Here is my math:
powervar = ((powervar * 2) - 54)
to convert my raw value into a percentage. The values I’m geting around 44 to 2, and a random order. Is there something I’m forgeting? Heres my code for power input
adin ax0,1,ad_ron,powervar
Please help, I’m sure its something simple… like always
If you are varying the voltage to the entire board then it may be that the processor is browning out and fouling up your readings. Not sure what else could cause this.
Oh, what sort of variable is powervar? If it’s a byte then you need to make it a word.
Just a really lame question about something seemingly really obvious but that could possibly be overlooked… do you have the jumpers installed that actually connect VS to AX0 and VL to AX1 ?
Another thought, it might be worth your time to just display the raw conversion value. Personally I would back it up a step beyond that, set the variable to some known value and prove the LCD can display that.
Once you are certain your LCD display is working, do the next step and use it to display the raw A/D voltage which can be from 0 to 1023… right?
Then if you know that is working apply your math to the variable and convert it to percentage and display that.
Also should probably point out that the value read represents Volts, not Power. It is not clear what 0-100% would correspond to. The voltage divider on the board is a 4:1 ratio, such that VS=20V (don’t do it) should convert to a full scale reading of 1023. VS = say 6V should convert to about 307, so if you wanted to display voltage you would multiply it by say 19.54 to get 6000 mV.
Thanks, so even with the voltage divider in there, that pin is recieving to much volts for a byte? (sorry,still learning ) If so that explains why some of my other home made sensors won’t working. Is there a chart that say like: volts 0 to 2.5 then byte or 0 to 5 then word or something?
Hmm, from the ADIN code snippet he posted a few messages ago I was thinking he was using a BA not BAP. I don’t think it matters though as both return 1023 full scale as you stated.
It’s just basic math.
The A/D converter has 5V full scale input and returns 1023 at full scale. So ADIN returns 1023 * (Vad / 5).
On the board the VS and VL input voltage dividers (RT, RB) is made from 30K and 10K resistors respectively. So for VS, Vad = VS * ((RB)/(RT+RB)) = VS / 4.
Substituting VS/4 for Vad you get ADIN = 1023 * (VS/20)
This is sort of restating what I posted earlier but hopefully it more clearly tells you what the equation used to relate ADIN reading to real-world voltages is. The answer the byte vs. word question, any unsigned value larger than 255 requires a word variable. This corresponds to VS > 5V or Vad > 1.25V. Perhaps just as valid a question might be if the ADIN command on the BA or BAP will correctly store the result when passed only a byte variable rather than a word.
Thanks guys, heres a question that might save me some testing time . I’m currently working *again * on my biped (finally gave in a ordered some aluminum brackets from here , after utterly failing a making my own ) and it has 10 HS-475 servos, three sharp IR, PS2 receiver, and a small relay for servos. When the battery is fully charged and everything is running, the on-board power readings drop suggificately and sometimes fakes my low power alarm. I’ve tried messing around with the alarm trigger values but its kind of hard to test . Does anyone know of an equation or something to calculate when the battery is actuatly low ?
You may want to insulate your voltage detector from momentary voltage drops. A low voltage drop diode (to prevent backfeeding the load), a capacitor (to hold voltage up to the detector for a short period), and a resistor (if needed to slowly bleed voltage off of the capacitor) could be used. Put the diode in series between the battery and the detector, and put the capacitor and resistor to ground between the diode and the detector.