Shop OBEX P1 Docs P2 Docs Learn Events
17VDC,ADC and Activity Board — Parallax Forums

17VDC,ADC and Activity Board

RsadeikaRsadeika Posts: 3,837
edited 2014-12-13 11:34 in Propeller 1
I am trying to figure out how you can use the ADC, on the Activity board, to check voltages greater than 10VDC batteries? I know and use the 10K resistor voltage divider setup for batteries that are up to 10VDC, but I am not sure what the setup would be for greater VDC input values.

On the NET you can find voltage divider calculators, but when I tried one out, using 14VDC input, r1-15K, r2-15K, the output voltage is 7V. And it seemed like whatever resistor size I used, the output value was 7V. Now I am at a loss as to how you could use the ADC, on the Activity Board , to check for battery values that are greater than 10VDC?

Thanks

Ray

Comments

  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-11-26 04:50
    Rsadeika wrote: »
    I am trying to figure out how you can use the ADC, on the Activity board, to check voltages greater than 10VDC batteries? I know and use the 10K resistor voltage divider setup for batteries that are up to 10VDC, but I am not sure what the setup would be for greater VDC input values.

    On the NET you can find voltage divider calculators, but when I tried one out, using 14VDC input, r1-15K, r2-15K, the output voltage is 7V. And it seemed like whatever resistor size I used, the output value was 7V. Now I am at a loss as to how you could use the ADC, on the Activity Board , to check for battery values that are greater than 10VDC?

    Thanks

    Ray

    It's about the ratios Ray, if R1=R2 therefore R1/(R1+R2) will always be half. Now if you left R2 (the one to ground) at 10K and made R1 24K then your ratio would be 10/34 * 17V = 5V full scale. Just remember Ohm's Law R=V/I so I = 17/(R1+R2) and then V across R2 (the one that the ADC sees) = R2 times that current of 17/(R1+R2) = 0.5ma by 10K = 5V. Easy Peasy.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-11-26 06:07
    Thanks Peter, now I know how to use the voltage divider calculator. My latest calculation, input - 20VDC,R1-30K,R2-10K, output - 5VDC. Since 10K resistors are more abundant in my resistor box, I guess 3 10K in series on one side and 1 10K resistor on the other side, should work out. Since I will be checking at three different points, it looks like the breadboard might get cluttered up with resistors, unless I can use one 3-10K, 1-10K resistor setup to split into the resistor setup and then split out to three ADC points. Or does each check point need its own voltage divider setup?

    Ray
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-11-26 06:23
    Rsadeika wrote: »
    Thanks Peter, now I know how to use the voltage divider calculator. My latest calculation, input - 20VDC,R1-30K,R2-10K, output - 5VDC. Since 10K resistors are more abundant in my resistor box, I guess 3 10K in series on one side and 1 10K resistor on the other side, should work out. Since I will be checking at three different points, it looks like the breadboard might get cluttered up with resistors, unless I can use one 3-10K, 1-10K resistor setup to split into the resistor setup and then split out to three ADC points. Or does each check point need its own voltage divider setup?

    Ray

    Not sure what you mean when you say "checking at three different points". Maybe a schematic of some kind would help.

    But each independent A/D input will need it's own divider and sometimes you might need a cap on the A/D input due to the resistance in the signal that you introduce and the sampling nature of the A/D. If these resistor where done in surface-mount then each divider of 3x10k + 10k would fit into a tiny 3.2x1.6mm four resistor array however if you use 33K and 10K then that shouldn't be a problem either.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-11-26 06:52
    I am stepping up my window sill solar experiment, I want to record the open circuit values of the solar panel, which should be as high as 17VDC, the 12VDC battery value, and the load value as it comes out of the MPPT controller. I guess I will probably need three voltage divider setups, I am trying to figure out which would be the easiest way to accomplish this using the minimal amount of space on the breadboard. I do not have the skills to conjure up a PC board for doing this, although I may need something a little more substantial as the experiment expands.

    Ray
  • altosackaltosack Posts: 132
    edited 2014-11-26 09:08
    Hi Ray,

    Be careful here: unless you have a very unusual PV module, Voc could be around 21-22 V nominal, and up to (to err on the side of safety) 30 V or so when you include edge-of-cloud effects and cold weather. Your MPPT controller will very quickly bring it down, and your MPP voltage will probably be about 17V, but that's not what I'd design for if you want your project to keep its magic smoke inside.

    You should only need two inputs, because the MPPT controller output should be virtually identical to battery voltage, but the other two must be completely separate; there is no way to combine parts of the voltage dividers.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-11-26 10:25
    ...include edge-of-cloud effects and cold weather.
    Interesting, will have to take that into consideration for checking on those types of conditions.

    Since this is still considered a window sill experiment, I will be using a 50W panel, smaller dimensions, which is rated for 17VDC, at the high end. I also want to setup a check point for the load value of the MPPT controller; in the docs, it also states, that there is voltage reduction from the panel to match a good charging level on the battery, of course I am paraphrasing.

    Now I have to think of a good solution for the voltage divider setup, I guess it will have to be a larger breadboard to contain a manageable tangle of wires and resistors.

    Ray
  • kwinnkwinn Posts: 8,697
    edited 2014-11-26 21:12
    Ray, if you use a 10K and 72K resistor for your voltage divider and convert the adc reading to decimal it will be very close to the actual voltage from the panel. Assuming the resistors and 5V supply are dead on you will get a reading of 2997 for 30V in, 1998 for 20V, 999 for 10V, etc. You will also have an input range of 0 to 41V, so no worries about edge of cloud or cold weather effects.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-11-28 11:59
    I am doing a test run of the three 10K resistor setup. I am using the PropBOE board with a program, "voltmeter test.spin", that I found on Learn.com. The PropBOE is getting a 13.49V input and the "voltmeter test.spin" program is showing 0.00488V as a result. If I multiply this result by 3000, then it would show the correct voltage of 13.49V. The problem is, I do not know where in the spin program, I would have to make the change to make it show what I would like to see. If this were a C program for the PropBOE then I could probably figure it out, but Spin... So does anybody have any C code for working with the PropBOE ADC sockets?

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-11-28 12:04
    This is a test, I just did a reply and it is not showing up, checking to see if this one shows up.

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-11-28 12:12
    OK, lets try this again. I am using a PropBOE board with a 13.49V input, and I am using the "voltmeter test.spin" program, which I found on the Learn.com site, to display the results. I have provided the three 10K resister setup that is using adc(0), and the result that I am getting is 0.00488V. Now if I multiply this by 3000 then I get the 13.49V result, but I do not know where in the Spin program to make the change for this. So, does anybody have any C programs for the PropBOE ADC sockets?

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-11-28 12:14
    I must be blacklisted, there are two posts waiting for moderator approval.

    Ray
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-11-28 12:15
    Ray,

    'Looks like your latest post got through. Your other one was "automoderated" for some strange reason. I'll be glad when the forum software finally gets sorted out.

    -Phil
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-11-29 08:02
    Well, I resolved the issue, I moved the PropBOE board out of service and replaced it with an Activity Board running SimpleIDE PropGCC. I tried out the triple 10K setup with a regulated 12V supply, and the ADC value was showing 4.98VDC, so by adjusting this by a 2.40 value, it now shows 11.98VDC, which is good enough for what I am doing. Now I guess I can read up to about 20VDC, the value I will be measuring should only be as high as 17VDC.

    Ray
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-12-12 13:31
    Now that I have the Activity Board back on line, a new problem has come up, at least for me its a problem. I have a new solar window sill experiment going which involves a 12V system. The solar panel controller that I am using is a PWM model, which I am not sure as to how it really works, but when I hooked up an ADC line to the battery, too read the voltage, I was getting all kinds of numbers.

    Basically what I am seeing is something like: 13V, 10V, 5V, 0V, and on and on. I assume that is what PWM is, sending out different voltages in this case. Since I am using a C program to capture the voltage as is, I need some guidance as to how, using C, I would capture a duration of voltage inputs, average them, and then display the result in a reasonable amount of time? This is a completely new programming strategy for me, or maybe there is a different way of doing this?

    Ray
  • altosackaltosack Posts: 132
    edited 2014-12-12 18:59
    PWM is a switch turned on & off very fast, so if the charge controller is not well bypassed internally (and you have a bit of resistance in your ADC input), it could give readings like you're getting.

    The fix is to bypass your ADC input with a tantalum capacitor (which you should always do, in any case), and you probably won't need to average your voltage readings. However, you have plenty of (microcontroller & circuit) time, so you might as well.

    If you want help doing so, please post your code; it will be easier to modify it than us starting from scratch without knowing what you've done so far.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-12-13 05:36
    Below is the C code that I came up with, it sort of works as expected. The problem is: when I measure the battery with a voltmeter it shows 12.50 V; when I run the ADC, it shows 9.45V. Now, I am not sure why I am seeing a 3 volt difference, is that the 4 10K resistors that are dropping the voltage? It almost looks like it has to be a circuit redesign instead of a software solution, but I would prefer a software solution if possible.

    Ray
    /*
      ABsun.c
    
    */
    #include "simpletools.h"
    #include "adcDCpropab.h"
    
    float v3,y1,y2,y3;
    
    void vtotal(void);
    
    int main()
    {
      // Add startup code here.
      adc_init(21, 20, 19, 18);
    //  float v3,y1,y2,y3;
    
      while(1)
      {
        // Add main loop code here.
        vtotal(); 
        //int x;
        //for(x=0;x<1000;x++)
        //{
       // v3 = adc_volts(3);
        //v3 = (v3*3.80);
         // y2 = adc_volts(3);
         // y1 = y2++;
          
        //}
        //y3 = (y1/1000);
        //y3 = (y3*3.90);
        putChar(HOME);
        print("Battery: %f V %c\n",v3,CLREOL);
        pause(250);
      }  
    }
    
    void vtotal(void)
    {
      int x;
      for(x=0;x<1000;x++)
      {
        y1 = adc_volts(3);
        y3 = y3 + y1;
      }
      y3 = (y3/1000);
      y3 = (y3*4.0);
      v3 = y3;
    }
    
  • altosackaltosack Posts: 132
    edited 2014-12-13 07:14
    What does the voltmeter read at the ADC pin ? If you have (4) 10k resistors, it should be 3.125V.

    I assume you have 5V at the ADC V+; do you also have +5V to Vref ?

    From a previous post, you said you adjusted by a factor of 2.4 for (3) resistors. This isn't right; it should be 3.0, but then again, if the ADC is 5V, it may have been saturated reading 4.98.

    Can you confirm that your resistors are in series, and your ADC is connected to the junction of the first & second, starting from ground ? Again, a voltmeter reading here should be 3.125V.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-12-13 10:19
    Can you confirm that your resistors are in series, and your ADC is connected to the junction of the first & second, starting from ground ? Again, a voltmeter reading here should be 3.125V.
    Yes, I just confirmed that that my reading is 3.12V at the ADC, my battery reading is 12.26V, so my adjustment factor is 3.98=(12.26/3.13), but I am still getting a reading of 9.27V from the program. One thing I forgot to check, what is the battery reading when I run the program. My thinking is that, if the ADC is showing 9.27V, then the battery reading should also be 9.27V, if that is the case then definitely I will not be running this in a while loop.

    Thinking about this from a mathematical perspective, is there a simple formula for predicting the actual battery discharge when run through this resistor setup? I guess in other words, how much power are the resistors using in terms of volts?

    Ray
    <edit> I just checked the battery voltage while the program is running, there is no voltage drop at the battery, now I am lost.<edit>
  • kwinnkwinn Posts: 8,697
    edited 2014-12-13 10:52
    Ray, in theory you should be getting an input voltage to the adc that is 25% of the battery voltage. In reality it may vary a bit from that due to resistor tolerances. Measure and record the battery voltage, input voltage to the adc, and reference voltage to the adc under the same conditions to get a handle on what is going on.

    Measure and record all of them with the propeller running in a while loop and then while paused. If the reference voltage (+5V ?) varies with the current draw of the propeller you will not get accurate readings. If the reference voltage is stable under both conditions you can use the battery and Vin voltage to calculate the calibration factor. Calibration factors calculated from the running while loop and paused should be very close.
  • RsadeikaRsadeika Posts: 3,837
    edited 2014-12-13 11:34
    Mystery solved, all is well. Because, I had this circuit on a separate breadboard and not the breadboard on the Activity Board, of course I did not have a ground connection from the separate breadboard to the ground on the Activity Board. I guess this is a very important lesson about having a common ground through out your whole circuit. I have to come up with a better method for this.

    So, after making this discovery I changed the adjustment factor to 3.73, and now the reading is the same as what the battery is showing. Since I have a sampling rate of a 1000 in my for loop, I guess I will have to work this number to see if I can get away with a smaller number. Now everything is looking brighter even though it is overcast outside.

    Ray
Sign In or Register to comment.