Shop OBEX P1 Docs P2 Docs Learn Events
controling a 4 potentiometers with a propeller — Parallax Forums

controling a 4 potentiometers with a propeller

Sigma XSigma X Posts: 38
edited 2010-07-26 02:34 in Propeller 1
hello everyone I am at my ropes end and I need help
I have the book "programming the propeller in spin"
I've gotten to the experiment of·using a pot to control a servo
I programmed the code word for word but no luck
has anyone attempted this if so please help
·

Comments

  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-07-18 03:49
    Rather than typing in the code yourself, I think you might be able to download it from the book's support website and cut and paste it, so you might avoid possible software errors that way. Check out the link below and scroll down to the name of the book.

    www.mhprofessional.com/getpage.php?c=computing_downloads.php&cat=112

    hope that helps,
    Mark


    www.mhprofessional.com/downloads/products/0071716661/0071716661_SPIN_Programs.txt

    www.mhprofessional.com/downloads/products/0071716661/0071716661_Wiring_Diagrams.pdf
  • Sigma XSigma X Posts: 38
    edited 2010-07-18 03:52
    thankyou I'll give it a shot
  • Sigma XSigma X Posts: 38
    edited 2010-07-18 04:11
    ok everything is good but one thing on the experiment it doesn't show where the pot goes it just showsvwhere the servo is
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-07-18 05:24
    Sigma X said...
    ok everything is good but one thing on the experiment it doesn't show where the pot goes it just showsvwhere the servo is

    Did you check out the wiring diagrams link? I think it shows how to hook up a pot and maybe even it has the exact figure for your test, but I'm not sure because I don't own the book.

    www.mhprofessional.com/downloads/products/0071716661/0071716661_Wiring_Diagrams.pdf
  • Sigma XSigma X Posts: 38
    edited 2010-07-18 07:02
    nope I checked the entire book and no luck even the program still doesn't work i'm guessing that the propeller
    cannot control a servo through a pot
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-07-18 09:34
    Sigma X said...
    nope I checked the entire book and no luck even the program still doesn't work i'm guessing that the propeller
    cannot control a servo through a pot
    Of course the Propeller can control a servo through a pot. Did you set up the simple circuit for reading a pot? Did you get that to work? If not, go back and do that first.

    Then set up the simple circuit for using the Prop to move a servo, and get that working.

    Once you understand both of those, you can use the pot to control the servo with just some small changes to the code.
  • Gerry KeelyGerry Keely Posts: 75
    edited 2010-07-18 11:55
    Attached is taken from the Utilities Method

    READING A POTENTIOMETER

    This routine ready a 10K pot with a 10 mfd cap
    This routine is what is used in the utilities to read the pot
    Pot is always read from the same line

    }}···
    CON·································································
    · _CLKMODE=XTAL1+ PLL2X········ 'The system clock spec
    · _XINFREQ = 5_000_000········· 'Crystal spec
    · PotLine·· = 19········· 'line the pot it on······· <<<<<<<<<<<<<<

    Regards

    Gerry
  • HarpritHarprit Posts: 539
    edited 2010-07-18 13:46
    There is a whole section in the book devoted to running R/C servos
    There is a whole section in the book devoted to reading A/D devices, the 3202 and the 3208
    The book also explains how to read a potentiometer using R C decay as alluded to by Gerry
    Using the 3202/8 is more accurate in that you can read them to 12 bits
    Put it all together for the results you need.

    Harprit
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-07-18 15:25
    Sigma X said...
    nope I checked the entire book and no luck even the program still doesn't work i'm guessing that the propeller
    cannot control a servo through a pot


    Sigma,

    look at page 22 of the link I have posted here for how to hook up a pot to a Prop. It is entitled "Figure 16-1, Circuitry for reading a potentiometer with a Propeller chip."

    Click on this link to read the wiring diagrams and see page 22:

    www.mhprofessional.com/downloads/products/0071716661/0071716661_Wiring_Diagrams.pdf


    If you still find that material irrelevant to your problem, then perhaps you are talking about a different book???
  • Sigma XSigma X Posts: 38
    edited 2010-07-18 17:35
    ElectricAye it's the same book
    it's just not working the ciricut the schematic it's all right
    but none of this works

    I even tried using the formula on 24-1
    still no luck

    Post Edited (Sigma X) : 7/18/2010 6:28:31 PM GMT
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-07-18 17:47
    Sigma X said...
    ElectricAye it's the same book
    it's just not working the ciricut the schematic it's all right
    but none of this works

    Can you post of photo of your set up?
    Do you have a multimeter/voltmeter to check your connections, starting with the power supply and moving through the system? If you're using a battery, be sure it's not dead.
  • Sigma XSigma X Posts: 38
    edited 2010-07-18 18:43
    I'll have a pic up shortly
  • Sigma XSigma X Posts: 38
    edited 2010-07-18 18:56
    Success...sort of I connected my servo and pot ok when I added power
    the servo moved sort of it kinda moved like a clock ticking and whatnot
    I still cannot change direction but this is progress right?
  • Sigma XSigma X Posts: 38
    edited 2010-07-18 19:10
    ok even more news when I add power to the servo directly
    it turns all the way clockwise when I turn the pot nothing happens
    I hope this info helps
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-07-18 20:14
    In addition to posting a picture of your set-up, you might also post your entire code. A common error for beginners is to botch the alignment of IF statements and Repeat loops, etc.

    To post your code, you need to copy it and then paste it between two code tags. The first tag looks like [noparse][[/noparse] code ] except you need to remove all the spaces. And the ending tag looks like [noparse][[/noparse] / code ] except, again, be sure to remove all the spaces.

      When you place your code
        between code tags
          it should come out looking like this.
    
    
    



    I'm just making a wild guess here, but it sounds like maybe you haven't worked your way through all the basic experiments before attempting this pot-controlled servo experiment. Or perhaps you didn't sufficiently absorb the concepts provided by those earlier lessons. Might it help for you to go back and re-do some of those earlier projects?

    hope that helps. smile.gif
  • HarpritHarprit Posts: 539
    edited 2010-07-18 21:44
    Read the chapter and run the program in chapter 24.
    In this program the 3202 is on lines 24 to 27 of the prop. This is covered earlier in the book on the 3202
    and remains connected at all times to provide support for the Utilities OBJ in all subsequent experiments.

    However if you don't read the book and do the exercises you are going to have problems again and again.
    Good luck and keep reading.

    Where is the pic you promised, where is the code?

    Harprit
  • Sigma XSigma X Posts: 38
    edited 2010-07-18 23:03
    [noparse][[/noparse]code]{{ 06 Sep 09Harprit Sandhu·
    RC_ServoPosition.spin
    Propeller Tool Version 1.2.6
    Chapter 24 Program 02·····
    READING A SERVO'S POSITION· uses pin 23
    This program allows you to tie the signal sent to an
    R/C servo to the position that it goes to.
    Connections
    White· P23 signal from Prop
    Red 5 volts
    Black ground
    }}···
    CON············································································
    · _CLKMODE=XTAL1+ PLL2X········ 'The system clock spec
    · _XINFREQ = 5_000_000
    ·· outPin· =23·················· 'line the servo is on
    ··································
    VAR···························· 'these are the variables we will use.
    · long ServoPos················ 'The program will read this variable from
    ······························· 'the main Hub RAM to determine the
    ······························· 'servo signal's high pulse duration
    · long stack [noparse][[/noparse]15]·············· 'space for Cog for LCD
    · long stack2[noparse][[/noparse]50]·············· 'space for Move Motor Cog
    · long pcount·················· '
    OBJ····························· 'These are the methods we will need for our calls
    · LCD· : "LCDRoutines4"········· 'for the LCD methods
    · UTIL : "Utilities"············ 'for general methods, pot
    ··
    PUB Go·························· 'main cog
    · dira[noparse][[/noparse]outPin]~~···················· 'set direction for amplifier··············
    · cognew(MoveMotor(outPin),@Stack)·· 'start a new cog and run the MoveMotor method
    ································ 'on it and output pulses on Pin 23·
    ································ 'The new cog that is started above continuously
    ································ 'reads the "position" variable as it's changed
    ································ 'by the example Spin code below
    · cognew(cog_two, @stack2)······ 'start new cog for the LCD·························
    · repeat························ 'this is the Cog's main loop·································································································
    ··· pcount:=UTIL.Read3202_0····· 'get the pot reading from the utilities
    ··· ServoPos:=7200+pcount*4····· 'calculate position count
    ·

    ···
    Pub cog_two························ 'set up and run the LCD············
    · LCD.INITIALIZE_LCD··············· 'initialize the LCD
    · repeat··························· 'LCD loop················
    ··· LCD.POSITION (1,1)············· 'Go to 1st line 1st space
    ··· LCD.PRINT(STRING("Pot Pos="))·· 'Potentiometer position ID
    ··· LCD.PRINT_DEC(Pcount)·········· 'print the pot reading·······························································
    ··· LCD.SPACE(2)··················· 'erase over old text······
    ·····················
    PUB MoveMotor(Pin)|LowTime,period·· 'method to toggle the output line, set
    ··································· 'up first
    · dira[noparse][[/noparse]Pin]~~······················ 'Set the direction of "Pin" to be an output
    · ctra[noparse][[/noparse]30..26]:=%00100············· 'Set this cog's "A Counter" in single
    ··································· 'ended NCO/PWM mode (where frqa always············································
    ··································· 'accumulates to phsa and the Apin output
    ··································· 'state is bit 31 of the phsa value)·······························
    · ctra[noparse][[/noparse]5..0]:=Pin·················· 'Set the "A pin" of this cog's "A Counter"
    ··································· 'to be "Pin"··········································
    · frqa:=1·························· 'Set this counter's frqa value to 1 (so 1
    ··································· 'will be added to phsa on each clock pulse)
    · ServoPos:=0······················ 'Start with position=0 (until the position
    ··································· 'value is changed by another cog)················
    · LowTime:=clkfreq/60·············· 'Set the time that the pulse will be low
    ··································· 'to 16ms = 1/60 secs
    · period:=cnt······················ 'Store current value of the system counter
    · repeat··························· 'line toggling routine.
    ··· phsa:=-ServoPos················ 'Send a high pulse for "position" number of
    ··································· 'clock cycles. Note negative sign
    ··· period:=period+LowTime········· 'Calculate what system clock's value will
    ··································· 'be at the end of this cycle's period
    ··· waitcnt(period)················ 'Wait for the system counter to reach the
    ··································· '"period" value (end of cycle)
    [noparse][[/noparse]/code]
    above is the code i'm using I went through the entire book however I didn't do any experiments until this one
    btw my camera is busted so the setup pic will come a bit later maybe on tuesday...i hope

    Post Edited (Sigma X) : 7/18/2010 11:09:45 PM GMT
  • HarpritHarprit Posts: 539
    edited 2010-07-19 02:09
    For this program to work the LCDRoutines4 and the Utilities Objects have to be functional
    The LCD has to be in place among other things if you want to see what is happening in the program
    They are made functional in preceding programs that you have skipped
    These preceding programs also show you how to set up the 3202 etc. You need this to read the pot.
    Go do all the program exercises in order and it will all work
    This is a powerful and complicated system. It will take some discipline but you can do it.
    Its like a geometry proof, you cant skip some steps and still get it!

    Harprit.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-07-19 02:11
    Sigma X said...

    
    {{ 06 Sep 09Harprit Sandhu  
    RC_ServoPosition.spin
    Propeller Tool Version 1.2.6
    Chapter 24 Program 02      
    READING A SERVO'S POSITION  uses pin 23
    This program allows you to tie the signal sent to an
    R/C servo to the position that it goes to.
    
    Connections
    
    White  P23 signal from Prop
    Red 5 volts
    Black ground
    
    }}   
     
    CON                                                                             
      _CLKMODE=XTAL1+ PLL2X         'The system clock spec
      _XINFREQ = 5_000_000
       outPin  =23                   'line the servo is on
                                       
    VAR                             'these are the variables we will use.
      long ServoPos                 'The program will read this variable from
                                    'the main Hub RAM to determine the
                                    'servo signal's high pulse duration
      long stack [noparse][[/noparse]15]               'space for Cog for LCD
      long stack2[noparse][[/noparse]50]               'space for Move Motor Cog
      long pcount                   '
    
    OBJ                              'These are the methods we will need for our calls
      LCD  : "LCDRoutines4"          'for the LCD methods
      UTIL : "Utilities"             'for general methods, pot
       
    PUB Go                           'main cog
      dira[noparse][[/noparse]outPin]~~                     'set direction for amplifier               
      cognew(MoveMotor(outPin),@Stack)   'start a new cog and run the MoveMotor method
                                     'on it and output pulses on Pin 23  
                                     'The new cog that is started above continuously
                                     'reads the "position" variable as it's changed
                                     'by the example Spin code below 
      cognew(cog_two, @stack2)       'start new cog for the LCD                          
      repeat                         'this is the Cog's main loop                                                                                                  
        pcount:=UTIL.Read3202_0      'get the pot reading from the utilities
        ServoPos:=7200+pcount*4      'calculate position count
    
      
    
    
        
    Pub cog_two                         'set up and run the LCD             
      LCD.INITIALIZE_LCD                'initialize the LCD
      repeat                            'LCD loop                 
        LCD.POSITION (1,1)              'Go to 1st line 1st space
        LCD.PRINT(STRING("Pot Pos="))   'Potentiometer position ID
        LCD.PRINT_DEC(Pcount)           'print the pot reading                                                                
        LCD.SPACE(2)                    'erase over old text       
                          
    PUB MoveMotor(Pin)|LowTime,period   'method to toggle the output line, set
                                        'up first
      dira[noparse][[/noparse]Pin]~~                       'Set the direction of "Pin" to be an output
      ctra[noparse][[/noparse]30..26]:=%00100              'Set this cog's "A Counter" in single
                                        'ended NCO/PWM mode (where frqa always                                             
                                        'accumulates to phsa and the Apin output
                                        'state is bit 31 of the phsa value)                                
      ctra[noparse][[/noparse]5..0]:=Pin                   'Set the "A pin" of this cog's "A Counter"
                                        'to be "Pin"                                           
      frqa:=1                           'Set this counter's frqa value to 1 (so 1
                                        'will be added to phsa on each clock pulse)
      ServoPos:=0                       'Start with position=0 (until the position
                                        'value is changed by another cog)                 
      LowTime:=clkfreq/60               'Set the time that the pulse will be low
                                        'to 16ms = 1/60 secs 
      period:=cnt                       'Store current value of the system counter
      repeat                            'line toggling routine.
        phsa:=-ServoPos                 'Send a high pulse for "position" number of
                                        'clock cycles. Note negative sign
        period:=period+LowTime          'Calculate what system clock's value will
                                        'be at the end of this cycle's period
        waitcnt(period)                 'Wait for the system counter to reach the
                                        '"period" value (end of cycle)
    
    
    
    




    .....

    Sigma,

    I cleaned up your code tags by separating them from the body of your code. I think my browser could not understand your tags because you had them running into the body of the code (much like the way you write, BTW. cool.gif )




    Sigma X said...


    ....I went through the entire book however I didn't do any experiments until this one...

    Well, maybe the best thing to do is back up a little bit and play with some of the simpler set-ups that are presented earlier in the book. It probably won't take you long and it sounds like you can build off of those simple concepts to achieve what you're trying to do.

    Let us know how you do.
    Good luck!

    smile.gif
  • HarpritHarprit Posts: 539
    edited 2010-07-19 02:19
    per your earlier note,
    the servo moved to one end because the pot was read as having an infinite resistance
    or being pegged at 4095.

    Harprit.

    ElectricAye

    Thanks for getting to this before I noticed that it was about my book.

    H
  • Sigma XSigma X Posts: 38
    edited 2010-07-19 04:22
    sorry for the way I type I didn't mean to cause any trouble with it
    with that stated I may have to start over mainly with the book I have it's probally too dificult to start
    out with I just thought it'll be easy due to having skill with the basic stamp
  • ElectricAyeElectricAye Posts: 4,561
    edited 2010-07-19 04:38
    Sigma X said...
    ... I just thought it'll be easy due to having skill with the basic stamp

    If you have previous experience with the Stamp, then you'll have no problem learning how to work with the Propeller. But the Propeller is a different animal, so take your time, be patient with yourself, and go step by step. Also, don't be afraid to post your questions on this forum. People on here have helped me tremendously.

    cheers,
    Mark
  • Sigma XSigma X Posts: 38
    edited 2010-07-26 02:34
    ElectricAye said...
    Sigma X said...
    ... I just thought it'll be easy due to having skill with the basic stamp

    If you have previous experience with the Stamp, then you'll have no problem learning how to work with the Propeller. But the Propeller is a different animal, so take your time, be patient with yourself, and go step by step. Also, don't be afraid to post your questions on this forum. People on here have helped me tremendously.

    cheers,
    Mark
    · You guys we're right now I'm getting somewhere I wen't back and did some smaller experiments "blinking a led'
    in doing so I found somthing
    1)It wasn't a hardware error or mostly the propeller experimental board was built right on my first try but
    alot of equipment was too old and faulty·mainly the servos

    2)It was a power problem this thing takes tremedous juice to run my 9v batteries we're dead·enough not to be found sometimes

    once I took my time and inspected things the blink a led circut worked liked a charm
    and learning the spin language is really really simple thanks everyone for your help and support
Sign In or Register to comment.