Shop OBEX P1 Docs P2 Docs Learn Events
ANALOGIN Problems — Parallax Forums

ANALOGIN Problems

MacGeek117MacGeek117 Posts: 747
edited 2006-10-17 15:39 in General Discussion
I just started·to work with the ANALOGIN command, and it works fine for Vdd and Vss(255, 0, respectively), but it doesn't work for any value in between(I have a voltage divider composed of two 10k resistors connected to Vdd and Vss). Could I please have some help?
RoboGeek

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
"I reject your reality and subsitute my own!"

Adam Savage, Mythbusters
www.parallax.com
www.goldmine-elec.com
www.expresspcb.com
www.startrek.com
·

Comments

  • BeanBean Posts: 8,129
    edited 2006-10-13 17:17
    You'll have to explain what "it doesn't work" means ???
    What value to you get ? What cap value are you using ?
    Details man, we need details...

    P.S. Are you setting the input pin to CMOS trigger level ?

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    Don't mistake experience for intelligence. And vis-vera.
    ·
  • MacGeek117MacGeek117 Posts: 747
    edited 2006-10-13 17:49
    I am using the schematic and program out of the What's New readme file(I am posting both). When I use the divider the value bounces between 0 and 14, where it should be about 127.
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.startrek.com
  • BeanBean Posts: 8,129
    edited 2006-10-13 18:20
    Try using two 1K resistors to create your voltage. The 10K resistance may be too high.
    Does the voltage measure 2.5V on a meter ?
    Try a larger prime value.
    Double check your connections.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    Don't mistake experience for intelligence. And vis-vera.
    ·
  • MacGeek117MacGeek117 Posts: 747
    edited 2006-10-13 20:21
    I've tried the prime values up to 50. Circuit is fine. Input voltage is 2.495V. The ADC still says 0. I simply don't understand!
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.startrek.com
    ·
  • BeanBean Posts: 8,129
    edited 2006-10-13 21:17
    Keep trying stuff, something not right. It DOES work. I have used it and others have too.
    Try using RB.0 & RB.1 like the example.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    Don't mistake experience for intelligence. And vis-vera.
    ·
  • MacGeek117MacGeek117 Posts: 747
    edited 2006-10-14 01:46
    Thanks for your help, Bean! I misread the cap value. It works now Thanks!!!!!!!
    RoboGeek

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "I reject your reality and subsitute my own!"

    Adam Savage, Mythbusters
    www.parallax.com
    www.goldmine-elec.com
    www.expresspcb.com
    www.startrek.com
    ·
  • BeanBean Posts: 8,129
    edited 2006-10-14 02:10
    Cool, I'm glad you got it working.
    Persistance pays...

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    Don't mistake experience for intelligence. And vis-vera.
    ·
  • ellizardellizard Posts: 106
    edited 2006-10-17 10:46
    HI Everybody,

    Just for information,
    Where (apart on this forum's trhead) there are informations on the new command ANALOGIN?
    I searched in the help window and there's no mention of such a command,
    I searched also the What's new section of the SX basic and there's only
    What's New In SX/B 1.51.03

    New Commands:
    LOOP NEVER
    Changes:
    Changed HIGH & LOW if a pin, set state again AFTER making it an output
    Fixes:
    Fixed: Literal replacement didn't handle strings in quotes
    Fixed: name CON -5 compiles as name CON 5 said...


    This is all i could find about.
    Please more informations needed

    Regards
    Stefano

    Post Edited (ellizard) : 10/17/2006 10:51:03 AM GMT
  • BeanBean Posts: 8,129
    edited 2006-10-17 11:39
    Here is a link that explains how it works: http://www.sxlist.com/techref/scenix/lib/io/adc_vp.htm

      ANALOGIN InPin, OutPin, Value[noparse][[/noparse], Prime]
    
        Reads an analog input voltage using the continuous calibration method
    
     
        All you need is 2 10K resistors and a 0.01uF capacitor(for 4MHz) or 0.001(for 50MHz)
    
     
        You can experiment with different resistor and/or capacitor values. Don't use resistor
          values below 220 ohms to protect the SX output pin.
     
        The variable Value will get set to the analog voltage at the input with
          255 = Supply voltage. So if you get a reading of 127 and the supply voltage
          is 5 volts, then the input voltage is about 2.5 volts.
     
        Note that the input pin needs to be set to CMOS input threshold. By default
          the sx sets all pins to TTL threshold. The TTL theshold is 1.4Volts. That
          will make the full scale reading of 255 = 2.8 volts regardless of the
          supply voltage.
     
        The method needs to "prime" the capacitor to get a stable reading. By default
          the prime value is 1. If you get unstable readings either use a smaller cap value
          or increase the prime value. Prime must be a constant from 0 to 255. However
          larger prime values will increase the time it takes to get a reading.
     
        The time required to get a reading is 3825*(1+Prime)/Frequency. So with the
          default prime value of 1, if the clock is 4MHz it will take
          3825*2/4000000 seconds or about 1.91 milliseconds to get a reading.
     
        For faster clocks either use a smaller cap value or a larger prime value.
     
        Note that this circuit has a fairly low input impedence. If you use a pot or resistor
          divider to create the analog voltage the ANALOGIN command may not reach the 
          limits (0 or 255). A simple test using the 10K pots on the PDB yielded values
          from 0 to 241.
     
      The following is an example program:
    '-------------------------------------------------------------------------------
    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000
    InPin  PIN RA.0 INPUT CMOS
    OutPin PIN RA.1 OUTPUT
    ' Analog Voltage >---/\/\/\-------+----+------------ SX Read Pin (RA.0)
    '                      10K        |    |
    '                               -----  +--/\/\/\---- SX Write Pin (RA.1)
    '                               -----       10K
    '                       0.01uF /     \
    '                                 |
    '                                 |
    '                                GND
    a VAR Byte
    PROGRAM Start NOSTARTUP
    Start:
      ANALOGIN InPin, OutPin, a, 2
      WATCH a
      BREAK
      GOTO Start
    END
    
    

    You can also try looking in the help for the Javelin. It has a similar command. I thinks it's called "ADC" on the javelin.

    I hope this helps,

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com

    Don't mistake experience for intelligence. And vis-vera.
    ·
  • ellizardellizard Posts: 106
    edited 2006-10-17 15:39
    thanks for the information so quick..........
    hope it will be in SX-Basic help window too.......

    it helped somehow

    Stefano
Sign In or Register to comment.