Shop OBEX P1 Docs P2 Docs Learn Events
Measuring voltage with a pin on the SX/28? — Parallax Forums

Measuring voltage with a pin on the SX/28?

eagletalontimeagletalontim Posts: 1,399
edited 2008-07-16 13:37 in General Discussion
Is there any command like the ANALOGIN that will work with the SX/28? I need to measure the voltage of one wire from my car and process the voltage variable in the chip.

Comments

  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2008-07-07 22:00
    Just to clarify, are you looking for something like ANALOGIN?· Because if you are asking if ANALOGIN will work with the SX-28, it will.··smilewinkgrin.gif

    ·- Sparks
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-07-07 22:04
    hmmm. i did not see it in the help section of the program tongue.gif Any good documentation on it so I can better understand that command?
  • Sparks-R-FunSparks-R-Fun Posts: 388
    edited 2008-07-07 22:27
    Make sure you have the latest SX/B and help file versions from the "sticky posts" at the top of this forum.

    In the help file under Reference and Commands the ANALOGIN command is the first one listed.

    Please post if you need further help.

    ·- Sparks
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-07-08 13:59
    ok, well i found that ANALOGIN may not be exactly what I was looking for since the voltage range i am trying to read is .001 vDc to 1.000 vDc. It appears ANALOGIN is only accurate to .50 vDc. Is there a different or more efficient approach to reading voltage on 1 pin?
  • BeanBean Posts: 8,129
    edited 2008-07-08 14:04
    You will have to use an external ADC chip for that resolution.
    BTW: ANALOGIN has a resolution of 0.02v (5.00 / 255).

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    "A government big enough to give you everything you want, is big enough to take away everything you·have."·· Thomas Jefferson

    "It is our choices, Harry, that show what we truly are, far more than our abilities."·Dumbledore from Harry Potter

    www.iElectronicDesigns.com

    ·
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-07-08 14:26
    So for reading voltage accurately + - .002 Vdc, I could do something like this :

    ANALOGIN InPin, OutPin, Volt
    Volt = Volt / 255

    Is that correct?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-07-08 14:29
    You can set the full scale to other ranges by adding 2 resistors.
    See attachement.

    In your case:
    Vdd = 5v
    Uinmin = 0v
    Uinmax = 1v

    This yields
    R2 = 5*R1
    R3 = 1.25*R1
    leave R4 out
    The C is not critical, 0.1u will do.

    This gives you full range 0-255 representing 0-1 volt.

    regards peter
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-07-09 02:22
    ok, I am completely lost now! tongue.gif I have tried several different resistors and several different formulas and all i can get for the Volt is 0, 1, or 2 when using the WATCH command.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-07-09 03:40
    Can someone better explain the formula to use with ANALOGIN to get the correct voltage to the nearest 100th or 10th decimal? I have tested a 1.5v AA battery and I got Volt to equal 85.

    Is the math :

    TrueVoltage = ((225 / Volt) * 5vdc) / 10)

    If that is the case, the 1.5v battery measured at 85 for the Volt variable and if plugged into the formula above, it gives 1.324 vDc.

    The only problem I have is that if I put 5vdc to it, I get 225 as the Volt. If plugged into the formula, it is .5vdc. What am I doing wrong?
  • pjvpjv Posts: 1,903
    edited 2008-07-09 04:14
    Hi Tim;

    Don't get discouraged... you are learning tons here, and lots more to go!

    Please dissect Peter's formulas to the point where you fully understand them..... there is a wealth of information in them.

    You will find that as you bias the sensing circuit of te A/D to near the switching threshold, the effective amount of ampification possibe grows greatly. Although I have not (yet) had the time to pursue this concept, I believe that one could make a nice, albeit low frequency, software amplifier out of that D/A circuit, and enhance the resolution of it to 1 millivolt, say minus to plus 128 mV. Now in order to do that, the software would need to be written in a very deterministic manner, and would, at least at this time, certainly require the useof assembler code.

    I'm anxious to find the time to pursue this, but alas it will have to wait for a while.

    Cheers,

    (the other) Peter V (pjv)
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-07-09 04:31
    Seeing all those letters and numbers is what confused me. I suck at math and need major help on how to simply read the exact voltage to the nearest 100th or 10th decimal then display it. For some reason, I can't get the chip to understand decimal points so this is being a major hassle so far. I am using the ANALOGIN example schematic in the Help section to get closer to where I need to get. So far, I can get the WATCH Volt to show 85 when I put a good AA battery to the test leads. Now, how to I convert that number into the actual voltage?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-07-09 04:44
    Tim,

    The ANALOGIN produces a 8bit value, 0-255, that represents the full scale.
    In case of the sx/b help file example, both resistors are equal and the
    input range is 0-5v.

    TrueVoltage = (Volt/255)*5v
    Your measured 85 therefore represents (85/255)*5v = 1.66v

    More generally, using Uinmin and Uinmax

    TrueVoltage = Uinmin + (Volt/255)*(Uinmax-Uinmin)

    Note that when you use this formula directly in sx/b you will
    not have a result in decimals due to the integer division.
    To have 2 decimals let TrueVoltage = 100 represent 1.00v
    TrueVoltage = 100*Uinmin + (100*Volt/255)*(Uinmax-Uinmin)
    Use words to do the math.

    regards peter
  • pjvpjv Posts: 1,903
    edited 2008-07-09 04:53
    Hi Tim;

    Well, you would need to scale it. Presumably you are using a 5volt setup, so 256 counts would represent 0 to 5 volts, so as Bean said, each count represents 5 divided by 256 = 0.019, or approximately 20 millivolts. And if you are reading 85 counts, then this means you are measuring a voltage of 85 times 20 millivolts = 1.7 volts approximately.

    To display that number you would need to take the reading of 85 and multiply by 20 to see 1700. Optionally you could divide that result by 100 in order to see 17 , and park a decimal between the two digits.

    Cheers

    Peter (pjv)
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-07-09 04:53
    so basically, I have the math about right, but the resistors are incorrect? Based on your last post, it shows how to get the resistor values.

    R2 = 5*R1
    R3 = 1.25*R1

    so...

    R1 = 10k
    R2 = 50k ??????
    R3 = 12.5k ??????

    I did not know those sizes existed or i am doing something totally wrong tongue.gif
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-07-09 05:01
    That are the values for an input range of 0-1v.
    10k is available, 50k equals two 100k parallel, 12k5 equals 10k in series with 4x 10k parallel.
    You could use 12k instead of 12k5 which gives a small change in input range.

    regards peter
  • ERIC THE GREATERIC THE GREAT Posts: 19
    edited 2008-07-15 11:02
    I have built a dc voltmeter using an analog devices adc 654. The IC converts voltage into frequency. A pin on the SX can be configured as a TTL input to receive this signal. The count command can be used to count pulses over time. The main program can be written to convert pulses over time to DC volts, an the program can be configured to manipulate output pins on the SX for peripherals.

    Hope this helps
  • ProfessorwizProfessorwiz Posts: 153
    edited 2008-07-15 13:49
    Eric,
    That sounds interesting, could you post any of your code or schematics?
    Thanks,
    Russ
  • ERIC THE GREATERIC THE GREAT Posts: 19
    edited 2008-07-16 11:33
    Here is the code for a DC digital voltmeter using an analalog devices ADC 654. There are 3 scales selectable by a rotary switch. The rotary switch does 2 things. 1) It communicates with pins on the SX telling the program what scale the meter is on. 2) It connects the probes across·no voltage divider,·or one·of two voltage dividers. The ADC is configured at 1.00 VDC a frequency of 100KHZ. There are 3 scales 1, 10, and 100 VDC. The 1 volt scale uses no divider, basically just probes connected to the ADC. On other scales a voltage divider is used to convert 10VDC to 1VDC or 100VDC to 1VDC, where the divided signal is sent to the ADC. The program calculates tenth volts and displays on a 4 digit multiplexed display. This program is in its early stages and needs many improvments. It is configured to run on a 50 MHZ external resonator which is required for the count command to count at the required speed. On the 1 volt scale it is accurate to +_ .1 volt which gets magnified some on higher scales. I am working on this and believe it to be correctable as a configuration on the ADC. Look at the analog devices website an there are schematics and sample circuits. As far as my circuit I have no schematic yet. It will drastically change as I am now altering it to measure AC as well as DC. Some of my comments on the program may no longer apply due to some changes. The ADC is configured using a timing capacitor and a few resistors. By chosoing the values properly you can get a specified frequency at a wide range of full scale voltages.
  • ProfessorwizProfessorwiz Posts: 153
    edited 2008-07-16 13:37
    Eric,
    Very nice, looks like I'll have to buy some more proto boards for another project.. Way too many great ideas on this board!

    Russ
Sign In or Register to comment.