Shop OBEX P1 Docs P2 Docs Learn Events
Measuring Voltage — Parallax Forums

Measuring Voltage

djh82ukdjh82uk Posts: 193
edited 2008-02-15 17:42 in General Discussion
Hi Guys

Im trying to measure voltage using analogin on an SX48 protoboard.

Now I have the 2 10k resistors a 0.01uf cap (ceramic disc type) and have wired it as the example in the help file.

I have changed the pin to TLL as the max voltage I want to read on the test is 2v, now I am using the below code, and then runing debug and if I click run, stuff just goes red and the "a" variable in the watch list stays at 0.

Any ideas?

Here is the code:

' Example program using ANALOGIN command
DEVICE SX48, OSC4MHZ
FREQ 4_000_000
InPin PIN RA.0 INPUT TTL
OutPin PIN RA.1 OUTPUT

a VAR Byte
voltage var byte
PROGRAM Start NOSTARTUP
Start:
voltage = a
ANALOGIN InPin, OutPin, a, 1
WATCH a
watch voltage
BREAK
GOTO Start
END



DJH (not part of code :P)
«1

Comments

  • BeanBean Posts: 8,129
    edited 2008-01-20 02:58
    DJH,
    Make sure you have everything connected correctly.

    Do you get anything besides zero using CMOS on the input pin ?

    Using TTL cause some side effect. Mainly that zero volts results in a positive value. And it requires a negative voltage being measured to get a zero result.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-20 19:52
    Still the same on cmos, sometines a=1 and sometimes a=0 but is random, sometimes a=189 on startup in debug mode.

    double checked the coonnections, all seems ok, but RA1 does not seem to be putting out any voltage at all.

    Im using a 9v supply to run the protoboard, and a regtualted psu to simulate voltage between 1-5V on cmos setting

    DJH
  • BeanBean Posts: 8,129
    edited 2008-01-21 12:18
    DJH,
    What is the voltage that you are trying measure coming from ?
    What values to you get if you connect to ground and Vdd ?

    Try different SX Pins and see if you get the same problem.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-21 19:03
    Hi bean, the voltage at the moment is coming from a regulated variable psu.

    I will try other pins

    DJH
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-21 19:04
    do I need the break command, as in is it needed for analogin to function?

    or is it just part of that code?
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-21 19:06
    ok, stupid question, when it says ground, am I right in presuming that it means just the ground of the voltage to be measured, or should that also be connected to the ground on the protoboard.

    Im beginning to think the latter, as otherwise when RA1 puts out voltage, it has no ground to work with so is useless

    Please confirm, I feel really stupid now, this is what happens when i take a break from stuff for too long. [noparse]:([/noparse]

    DJH
  • BeanBean Posts: 8,129
    edited 2008-01-21 19:09
    DJH,
    · Yes to need to connect the grounds together.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-21 19:41
    thank you, tried another pin, same problem.

    here is my code, led is red (else statement led1)

    DEVICE SX48, OSC4MHZ
    FREQ 4_000_000
    InPin PIN RA.0 INPUT CMOS
    OutPin PIN RA.1 OUTPUT
    Led1 PIN RA.2 Output
    Led2 PIN RA.3 Output
    Led3 PIN RA.4 Output

    a VAR Byte
    voltage var byte
    PROGRAM Start NOSTARTUP
    Start:
    led2=0
    voltage = a
    ANALOGIN InPin, OutPin, a, 1
    'WATCH a
    'watch voltage
    if a > 102 then
    led3=1
    else
    led1=1
    endif

    'BREAK
    GOTO Start
    END

    just cannot figure it out
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-21 20:12
    Ok using debug, it seems the output pin works, when outputing I get 4.85V from it (voltage I am trying to test is only 3.7 atm), however it seems the input is not picking anything up at all, which would means I would get a 0 result?

    If I put a multimetere prob at RA.0 it is always a ground, so how can it ever pick anything up?

    I have RA.0 connect straight to inbetween the two resistors, which is also where one of the cap legs is connected (other cap leg goes to both grounds.
    That sounds wrong but matches the diagram?
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-21 20:15
    Also the voltage is not getting past the first 10k resistor

    I presume that the + symbols on the diagram do not mean anything other than to show the lines are connected, and not that possitive voltage should be connected to it?

    Im more and more sure that this is a physical problem with my circuit, just cannot figure out where

    DJH
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-01-21 23:26
    djh82uk -- "I presume that the + symbols on the diagram do not mean anything other than to show the lines are connected."

    ???

    pic attached


    ANALOGIN (??)
    352 x 159 - 4K
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-22 12:56
    This is what i had to go from, sorry for any confusion

    http://forums.parallax.com/forums/attach.aspx?a=12087

    DJH
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-01-23 00:05
    The link is no good.
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-23 00:19
    Works ok for me on another comp, I have taken a screenshot and attatched the picture, it's the same schematic as in the manual

    Thanks

    DJH
    1137 x 250 - 17K
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-01-23 02:21
    Gosh, maybe this'll be an education for me, too.

    I have SX/B 1.50 / SXKey v3.2 and I cannot find an ANALOGIN listed.· Is that a part of a new Rev.?

    "1.50" has an 8-Bit ADC (ADC8.SXB) in·its Example Projects.· The circuit is like yours, except that the input comes in on a third pin.

    Post Edit -- Looks like there IS a SX/B 1.51 and I didn't get the memo.· And there are some bugs (one which you found) and I'm reluctant to install it.· But, anyway -- isn't the circuit used the same except that·the ANALOGIN approach is just a "macro"-ized 'ADC8.SXB'?

    Bean?

    Post Edited (PJ Allen) : 1/23/2008 2:45:40 AM GMT
    338 x 159 - 8K
    427 x 203 - 7K
  • ZootZoot Posts: 2,227
    edited 2008-01-23 13:41
    PJ -- 1.51.03 dates to Sept. 2006 and is, in my experience, *extremely* stable. I wouldn't hesitate to install it. Another user found an error in SASM that prevents more than 10 includes, but that's unrelated to SX/B.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST

    1uffakind.com/robots/povBitMapBuilder.php
    1uffakind.com/robots/resistorLadder.php
  • BeanBean Posts: 8,129
    edited 2008-01-23 14:24
    The latest version 1.51.03, and all known issues with it are documented here:
    http://forums.parallax.com/showthread.php?p=597707

    Bean

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-01-23 15:40
    OK, fine.

    However, is the circuitry used to implement ANALOGIN the same as 1.50's Example Project (using 3 pins), or is it really just done with two pins?

    If it is down to two pins, then perhaps my rendering (analogin.jpg) will shed some light on the subject (really don't like those ASCII-y things.)

    djh82uk -- Does this help any?· Please advise same.


    Post Edited (PJ Allen) : 1/23/2008 3:45:52 PM GMT
  • BeanBean Posts: 8,129
    edited 2008-01-23 16:13
    PJ Allen,

    The 8-bit ADC example in the help file uses the comparitor to compare the input voltage to the voltage generated from the PWM output.

    The analogin is a different method. It does not use the comparitor, and can use any two pins.

    It looks to me like both schematics you post are correct for the method being used.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-23 19:20
    Hi PJ

    Yes that is how I have it connected, RA.0 going in between the 2 resistors, and also the one leg of the cap, my cap says it's a 104 or 103, and my resistors are 10k, but this is where I see a problem, 4.8V say through a 100k resistor, shows as 0v at the other end, so regardless whether the voltage is coming from the power source or from RA.1, RA.0 never sees above 0v it seems.

    Any Ideas? Im sure it's something stupid on my part.

    DJH
  • BeanBean Posts: 8,129
    edited 2008-01-23 19:38
    Why are you going through a 100K resistor ? That won't work. Just hook the 4.8 volts directly to the 10K resistor.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    www.iElectronicDesigns.com

    ·
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-23 19:54
    sorry they are 10k
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-01-23 19:58
    djh82uk said...
    my cap says it's a 104 or 103
    A 104 is 0.1uF; a 103 is 0.01uF.· So, which is it?· It's supposed to be a·0.01uF (103.)· That could be a problem, makes a difference.

    [noparse][[/noparse]The "capacitor code" is the value in picofarads.· So, a 103 is 10 followed by 3 0's pF: 10,000pF /·10nF /·0.01uF]

    10K.· So, they're both brown-black-orange?

    If the circuit is disconnected·from the SX pins·you should measure the source voltage between the junction (R1, R2, C) and Ground or something is wrong (a bad contact in your breadboard, a bad cap.)
    523 x 286 - 13K
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-23 21:08
    Ok thanks guys

    will check when i can get back in the workshop

    DJH
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-23 21:36
    right it is deffo a 103 cap (brown ceramic type), resistors were sold as 10k and multimeter also says they are 10k, (brown, orange, black, black, Brown) orange may be red.

    with power disconnected to the sx, i get 5v before the resistor, and 0v after it.

    Has got to be my problem would you agree?

    DJH
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-23 21:43
    right, just tried it with a 2v Lead Acid battery and have the same problem, 0v at the end of the resistor, tried a new resistor same problem.

    Would you actually get any voltage at the end tho? As a 470ohm resistor reduces 12v enough to run an led, so would'nt 10k completley wipe it out? or is it current related?

    There is defiantley no voltage getting past that 10k resistor anyway

    DJH
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-01-23 21:59
    brown, orange, black, black, Brown = 1 , 3, 0, 0, x10 = 13K· (If it's 'red' then the "3" is a "2").· Anyway, it's not 10K.·
    [noparse][[/noparse]Is it you with the submarine meter or something? [noparse]:)[/noparse] ]

    The troubleshooting·"experiment" requires that the circuit should be disconnected from the SX (note the Red Xs.)

    Are you using a breadboard or are you soldering to the ProtoBoard?
    If you are soldering to the ProtoBoard, then make sure it is to the "uncommitted" pads.

    If you simply solder these presumed resistors in series and place that across your voltage source, totally independent of the SX, does it "divide": 1/2 across one R and the same across the other?

    Post Edit -- picture added

    Post Edited (PJ Allen) : 1/23/2008 10:10:29 PM GMT
    523 x 286 - 18K
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-23 22:36
    Hiya

    Ha ha, did not think i mentioned that, but yes I have an ex-MOD multimeter with nixie tubes etc, has pressure relase valves and warm up circuit, very accurate, tho in this case I am using a normal digital multimeter, although I have a 5kv HT meter here too, tho never used it and prb never will (a good thing)

    Right, i changed resitors, I found some that were 10k, (brown, black, red, gold) and also showed as 9.98k on multimeter,

    Wired them as the diagrame (the one with the red x's) on a breadboard completley away from the sx, gave it 5v, and I get 5, 4.8v and 4.9v at the 3 possible test points on the resistors, so I then used these resistors on the sx board to replace the others, the sx is giving out 5v at the pin into one end of the resistors in series, and im giving it 5v at the other end, shows as 0v in the middle tho, and so RA.0 is also getting 0v, hence the lack of a reading. Perhaps i should describe the circuit, fresh eyes and all that.

    RA.1 is connected to a resistor, connected to the other end of that is another resistor, on the end of that is the possitive connection of the voltage i wish to measure.

    RA.0 is connected to the junction between the 2 resistors, , as is one leg of the cap, the other end of the cap is connected to the ground of the voltage I was to measure, as well as the ground of the sx protoboard (VSS).

    I am soldering to the protoboard and not using any pads that are connected to anything else.

    Thanks for your patience, sorry if I sound stupid, I am useless with electronics theory, something I really need to brush up on when I have time. Yet I can troubleshoot problems on games consoles, psu's etc, down to component level, im self taught which is prob not a good thing.

    DJH
  • djh82ukdjh82uk Posts: 193
    edited 2008-01-23 22:37
    OK, if I put the multimeter leads on as follows, possitve lead to VDD, and neg lead to RA.0, I get a 5v reading, so ra.0 is effectively ground.

    DJH
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2008-01-23 22:57
    brown, black, red, gold is a 1kohm, 5% tol.·(1, 0,·and 2 0's.) ·Is it reading "0.998"?· I think that·"we" need to get these values nailed.· You need to get some 10K resistors, brown-black-orange, or bust.

    I'm thinking about installing the 1.51 SX-Key/SXB to find out what's what here.· But at this rate I've·> 1/2-a-mind to·just whump up a board for you to plug into.

    If anybody wants to jump in, it's OK by me.

    Post Edit -- Can you send post a screenshot of the page from the manual that you're working from (all about ANALOGIN or what ever it is)?
Sign In or Register to comment.