Hi Rob, thanks for the reply..
I have the problem that what I am trying to do is sense the charge state of a 12v lead acid battery, lead acid batteries are starnge, in that you can sense their charge state from their voltage.
usually they are between 11.9v and 14.8v.
Problem is.. connect them to a charger and it drives the battery up about 0.7v.. and then it settles back down.
(actually it jumps around all over the place, varying by about 0.3v)
I was having a problem that my mbed wasn't agreeing with my multimeter about the voltage.
I think my problem is more in the way I'm using it.. its spikey spikey and I don't have anything smoothing it in the circuit. (I don't want anything smoothing it in hardware infact)
My other problem was that I wasn't using tera term to print out what was going on... I just had a multimeter connected, and it was switching when I wasn't expecting it to.
I'd now say TeraTerm is a MUST for anyone using mbed !
anyway..
I can see my values are all in range.. but are very jumpy.. what I really want is the mean of those values. so I did this...
float aveVolt() {
float outside = 0;
for (int j=0;j<3;j++) {
float average = 0;
for (int i=0;i<1024;i++) {
average = average + load1*rRatio*3.3000;
}
average = average / 1024;
wait(1.2);
outside = outside + average;
}
return outside / 3;
}
its a little "manual", and it takes the average of the 3 that I take 1.5 secs apart, but as I am careful about where it is in my code (it takes 4.5 secs to execute with the wait, but I'm happy with that) it appears to work ok.
I wondering whether to make the 1024 bigger... I need to go see how fast an mbed runs.. I'm wondering if a sample taken over half a second (I need to see what the number is for that) would be much more use.
cheers
Dave.
PS. I'd moved my charge points to 12v and 13v (flat and charged) and this is when it went grumpy. I've moved them back to 11.9 and 14.8, and these are far enough apart for it not to keep switching itself in a grumpy manner.
Hi all..
So I'm playing with analogueIn, and I'm using it to turn a relay on and off depending on the input voltage.
so, quite a simple bit of code, and a couple of resistors to bring my input voltage into the range 0 - 3.3v.
a 12k and a 68k resistor working as a potential divider. (is that a term?) to bring a 0-18v voltage down to 0 to 3.3v
(the theory being I can multiple whatever I get from analogueIn by 3.3 and 6.66 to find what the voltage was on the outside) but I'm having problems getting it to turn on and off when I want.
then I noticed that it says analogueIn returns a float between 0.0 and 1.0 (1 decimal place I noted)
1.9v at the pin, would give a value of 0.57 on the 0.0 - 1.0 scale (if the pin can read 0 to 3.3v).
but it looks like 1.9v at the pin gives me 0.6 from analogueIn.
is that correct ? or have I damaged my mbed ?
or have I completely missed something.
Bear with my as I'm usually a Java programmer.. but this is my code. the chargeOne turns the relay off when the input measured at the pin is 1.9v, (12.4 after the calculation) yet upper_charge_limit for the comparisin is 13.0
If 1.9v (analogueIn of 0.57) gets rounded to analogueIn of 0.6, then the calculation returns 13.2.
which would explain why it turns off.
So it does look like analogueIn just rounds to 1 dp.
cheers
Dave