Shop OBEX P1 Docs P2 Docs Learn Events
How to interface a rotary potentiometer with the propeller? — Parallax Forums

How to interface a rotary potentiometer with the propeller?

turbosupraturbosupra Posts: 1,088
edited 2010-07-28 21:26 in Propeller 1
I'd like to interface (2) rotary position potentiometers with the propeller. They are 0-9 position potentiometers and I'd want the propeller to be able to interpret an integer from the varying resistance or voltage.

Anyone ever done this? Do you have a code and schematic example?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-19 04:15
    Set up the potentiometers as voltage dividers and use the ADC technique shown in the AN001 application note and its associated sample program.

    www.parallax.com/tabid/832/Default.aspx
  • Gerry KeelyGerry Keely Posts: 75
    edited 2010-07-19 06:48
    You could also·use an rc method as decribed on page 122 of the·Book - "Propeller Education Kit Labs: Fundamentals"(located at same location indicated by Mike).

    Schematic given for this circuit is not quite correct in that a resistor is required between the pot wiper and the propeller pin to prevent a direct short on the pin when the pot wiper is at grounded end of pot.I have used a 330 ohm resistor in the past.

    Gerry



    Post Edited (Gerry Keely) : 7/19/2010 7:43:36 AM GMT
  • ErNaErNa Posts: 1,752
    edited 2010-07-19 07:07
    I have done it, and code and schematic are somewhere in this forum. Search for Muxed ADC or something like that

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cmapspublic3.ihmc.us:80/servlet/SBReadResourceServlet?rid=1181572927203_421963583_5511&partName=htmltext
    Hello Rest Of The World
    Hello Debris
    Install a propeller and blow them away wink.gif
  • turbosupraturbosupra Posts: 1,088
    edited 2010-07-19 19:17
    Is this it?

    http://forums.parallax.com/forums/default.aspx?f=25&m=261327&g=269023#m269023


    ErNa said...
    I have done it, and code and schematic are somewhere in this forum. Search for Muxed ADC or something like that
  • turbosupraturbosupra Posts: 1,088
    edited 2010-07-19 19:23
    Thanks Mike!

    Mike Green said...
    Set up the potentiometers as voltage dividers and use the ADC technique shown in the AN001 application note and its associated sample program.

    www.parallax.com/tabid/832/Default.aspx
  • turbosupraturbosupra Posts: 1,088
    edited 2010-07-22 21:44
    Is there a spin version of this so I can try to interpret the code better?



    Mike Green said...
    Set up the potentiometers as voltage dividers and use the ADC technique shown in the AN001 application note and its associated sample program.

    www.parallax.com/tabid/832/Default.aspx
  • Mike GreenMike Green Posts: 23,101
    edited 2010-07-22 22:17
    The assembly version is much faster and more accurate. Here's my hand conversion of the assembly routine to Spin:
    var long sample
    
    pub ADC(adcPinNo, fbPinNo, bits) | waitTime, cycles, oldSample
    ' adcPinNo and fbPinNo are the I/O pin numbers used for the analog
    ' to digital conversion as discussed in the comments in ADC.spin.  bits
    ' is the number of bits to be used for the conversion.  Note that the
    ' minimum number of bits in Spin would probably be 8.
    
    ' Note that, since Spin is much slower than assembly, the minimum
    ' sample time is much greater in Spin than in the assembly code.
    
       oldSample~   ' Initialize variables and registers
       cycles := |< bits - 1
       dira := |< fbPinNo
       ctra := adcPinNo | (fbPinNo << 9) | (%01001_000 << 23)
       frqa := 1
       waitTime := cnt   ' must come just before the repeat for best initial accuracy
       repeat
          waitcnt(waitTime += cycles)   ' wait for "cycles" system clocks
          sample := phsa - oldSample   ' get count since last sample time
          oldSample += sample   ' accumulate count to include this sample time
    
  • turbosupraturbosupra Posts: 1,088
    edited 2010-07-27 18:18
    In reading up on ADC's, I found this object as well
    http://obex.parallax.com/objects/488/
    and I'm now trying to figure out my best course of action.

    I'd like to control (2) 2.5 digit 7 segment LED's with the least amount of prop pins being used as possible with a BCD

    Am I best to use a 4 pin BCD to give me 16 combinations, or (2) 4 pin BCD's? Maybe I could get away with (1) 5 pin BCD to drive both of them with the 32 binary posibilities?

    If I understand the 4 pin LED driver BCD, it does the following, it takes 2^4 different binary combinations as an input and each combination will represent a different output that corresponds to a number on the 7 segment LED, is my understanding correct?




    I'd also like to have the ability for analog values as inputs, someone asked if the prop uses SPI or IC2 as an interface, and I wasn't sure what to say. Are there certain ADC's that are better compatible with the propeller than others, a millisecond is more than enough speed for me and 2^4 is enough resolution.

    Post Edited (turbosupra) : 7/28/2010 6:34:00 PM GMT
  • ErNaErNa Posts: 1,752
    edited 2010-07-28 10:09

    There is a later version I will try to find it again

    There is another link: http://forums.parallax.com/showthread.php?p=904925

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cmapspublic3.ihmc.us:80/servlet/SBReadResourceServlet?rid=1181572927203_421963583_5511&partName=htmltext
    Hello Rest Of The World
    Hello Debris
    Install a propeller and blow them away wink.gif

    Post Edited (ErNa) : 7/28/2010 12:24:39 PM GMT
  • turbosupraturbosupra Posts: 1,088
    edited 2010-07-28 18:38
    Thanks Erna, I will try and wrap my head around that MUX code
  • ErNaErNa Posts: 1,752
    edited 2010-07-28 19:54
    The principle is: voltage measured is proportional to the counted value in relation to the elapsed time. One problem arises from the fact, that the comparator threshold is not 1/2 vdd, but in the range of 1.2 V. Therefor, zero voltage results in a non zero count, the advantage is: one can measure voltages up to -1V. Therefor you see an offset. It is tricky, but works very well. Even it the runtime changes and is never exact, calculating counts/time eliminates such fluctuations. The sampling rate must not be to long to prevent the system from overflowing 32 bits after the shift-operation.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    cmapspublic3.ihmc.us:80/servlet/SBReadResourceServlet?rid=1181572927203_421963583_5511&partName=htmltext
    Hello Rest Of The World
    Hello Debris
    Install a propeller and blow them away wink.gif
  • Clock LoopClock Loop Posts: 2,069
    edited 2010-07-28 21:26
    I read 12 potentiometers in my black box using spin.
    http://forums.parallax.com/showthread.php?p=831833


        outa[noparse][[/noparse]PotentiometerPIN] := RCState                       'set pin high or low
        dira[noparse][[/noparse]PotentiometerPIN] := 1                             'make I/O an output, charge  
        waitcnt(5_000 + cnt)                       'Wait for 1 ms to charge  
        
        dira[noparse][[/noparse]PotentiometerPIN] := 0                             'make I/O an input, discharge
        ClockCycles := cnt                         'grab clock tick counter value
        WAITPEQ(1-RCState,|< PotentiometerPIN,0)                'wait until pin goes into the opposite state you wish to measure; State: 1=discharge 0=charge
        
        ClockCycles := cnt - ClockCycles - 30000    'see how many clock cycles passed until desired State changed
        ClockCycles #>= 0                          'no less than 0
    
        'change the amount you divide by to match your potentiometer.(this should be the only thing you need to adjust, you might need to change the charge time also)
        Waveform := ClockCycles / 55000           
    
        'This code makes sure the value being stored into the FX data is within HSS limits.
        '0 to 254 
        If byte[noparse][[/noparse]@fx][noparse][[/noparse]0] <> Waveform        
          If Waveform < 1
            byte[noparse][[/noparse]@fx][noparse][[/noparse]0] := 0 
          ElseIf Waveform > 254
            byte[noparse][[/noparse]@fx][noparse][[/noparse]0] := 254 
          Else
            byte[noparse][[/noparse]@fx][noparse][[/noparse]0]:= Waveform
    
    
Sign In or Register to comment.