Shop OBEX P1 Docs P2 Docs Learn Events
PWM Input — Parallax Forums

PWM Input

computer guycomputer guy Posts: 1,113
edited 2007-01-13 05:49 in BASIC Stamp
Hi

I am working on my first basic stamp project. I am using a BS2. I want to conect the servo outputs on my R/C radio reciever to my basic stamp read the
signal and and save the PWM servo signal to a variable and then send it back out through a different pin.
How would you do this.

Thanks in advanced yeah.gif

Comments

  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-01-11 03:38
    Use the PULSIN command to measure the signal, and PULSOUT to send it out.

    -Martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    StampPlot - Graphical Data Acquisition and Control
    AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
  • computer guycomputer guy Posts: 1,113
    edited 2007-01-11 03:47
    What kind of result does the PULSIN command return.
  • computer guycomputer guy Posts: 1,113
    edited 2007-01-11 04:01
    what i mean is does it return a number or an array or something else?
  • ZootZoot Posts: 2,227
    edited 2007-01-11 04:37
    PULSIN returns a Word sized value -- the value is X units of time, where X depends on your particular Stamp. The faster Stamps use smaller units (they are higher resolution, in other words). See the PULSIN command in the Basic Stamp manual.

    So... you can do a PULSIN on the pin(s) connected to the receiver and you'll then have a Word sized value. You may need to scale that value for PULSOUT, using * or / or */. PULSOUT also has it's own units for depending on which Stamp you are using.

    Is this helpful?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When the going gets weird, the weird turn pro. -- HST
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-11 14:17
    The Servo control signal is a pulse of a certain width (1 mSec to 2 mSec, depending on desired position of the servo) repeated every 20 mSec.

    So, you use PULSIN on the 'reciever' to measure the width of the command pulse. The result is a 16-bit integer "number of ticks" -- when the "number of ticks" varies depending on which BS2 family you're using. The 'plain' BS2 uses 2 uS for it's 'tick' size.

    You then use PULSOUT to send a command pulse of the same size out to the servo. I believe the 'tick' size for both PULSIN and PULSOUT are the same -- both being 2 uSec for the 'plain' BS2.
  • Tom WalkerTom Walker Posts: 509
    edited 2007-01-11 15:03
    The "feeling" that I get from your question, is that you are wanting to do something a little more complicated than what you stated. If you are looking for "real-time" modification of a servo control signal, I think you will run into problems accomplishing anything "interesting" using a simgle-tasking Stamp due to the processing time for each interpreted command. If you are looking to record the signal "for a while" and then just play it back, then you will probably be able to get some results, but you might be limited by the variable space available to record readings. Saving readings to external EEPROM could overcome this limitation, but, again, the granularity of your readings would suffer due to the added processing time for the EEPROM writes.

    You should probably start by going through the "What's a Microcontroller?" text...it's free and fun and provides a good foundation in basic digital electronics, the Stamp, and in ways to look at design challenges.

    If all you really want to do is look at a single servo command and echo it back out, then my crystal ball is on the fritz again, and you can just follow Zoot's suggestions...

    Time for caffeine...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Truly Understand the Fundamentals and the Path will be so much easier...

    Post Edited (Tom Walker) : 1/11/2007 3:09:33 PM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2007-01-12 06:26
    What i want to do is this:

    BS|-----------| P0 <_____ R/C reciever out 1 
      |           | P1 <_____ R/C reciever out 2
      |           | P2 <_____ Ultra sonic i/o
      |           |
      |           |
      |           | P5 _____> Motor controller In 1
      |           | P6 _____> Motor controller In 2
      |-----------| 
    
    


    1. Recieve reciever inputs and save as variable.
    2. Input ultrasonic data.
    3. If ultrasonic shows object infront goto sub Auto control
    else send reciever pulses to Motor Controller Outs.

    The idea is that if you try to drive the robot into a wall or object with the controller the robot will go into auto mode
    and turn arround once it has turned arround it will go back to manual mode.

    Post Edited (computer guy) : 1/12/2007 6:35:24 AM GMT
  • Mike GreenMike Green Posts: 23,101
    edited 2007-01-12 06:56
    You're probably not going to be able to do all this because the Stamp can't really do more than one thing at a time. Sometimes, when things happen slowly, you can overlap several operations. For example, you can control 2 or 3 servos at a time because there's a lot of idle time between servo pulses (the pulses are 2.5ms max, but have to be repeated only every 20ms). The PING can take a lot longer than 20ms to get a response. It's possible even to overlap that with two servo output pulses, but you start losing accuracy in the PING timing. The Stamps are just not fast enough to combine that with trying to time incoming servo pulses.

    With some external logic, you could make this happen. A quad NAND gate would do it. You would have two pins on the Stamp, one would let the servo pulses through if HIGH, inhibit them if LOW. The other would be idle if HIGH and would make a servo pulse if LOW (inverted pulses). The Stamp could just do the PINGs and inhibit the incoming servo control if the PING sensed something. The Stamp would have complete override control of the servos.
                            --------
    let through--->|         |       --------
    servo input--->|         |--->|         |
                           --------        |         |--------> to servo
    inverted servo------------->|         |
                                             ---------
    
    


    Both gates are NAND. The top input is the servo pass through control. The next down is the servo input. The next is the inverted servo override and the output is to the servo itself. A typical gate package would be the 74HC00. You'd need a total of 4 Stamp pins and two pairs of gates (one quad gate in package).

    Post Edited (Mike Green) : 1/12/2007 7:12:01 AM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2007-01-12 08:22
    This is what i want to do exactly.

    although the speed of the basic stamp 2 might cause problems i am willing to lose a bit of accuracy by adjusting pauses between ping commands and things like that.

    attachment.php?attachmentid=44981

    Post Edited (computer guy) : 1/12/2007 8:37:43 AM GMT
  • BeanBean Posts: 8,129
    edited 2007-01-12 12:44
    I don't think the motor controllers require much current on the input signal, so I would try just putting a resistor (1K ?) between the R/C receiver output and the motor controller input. Then also connect the motor controller input directly to a Stamp pin.

    When you want the user to have control, make the stamp pins INPUTS. When an object is detected, make the stamp pins OUTPUTs and drive them to control the motors (this will override the R/C receiver signals).

    Note that the R/C receiver outputs do not go into the stamp at all. If you want/need to monitor the signals they can be sensed on the motor control pins (as long as they are INPUTs).


    In your diagram above you would:
    ··disconnect the line going to P0 and connect it to P5 through a 1K resistor.
    · disconnect the line going to P1 and connect it to P6 through a 1K resistor.


    And the code would go something like:
    · 1) Make P5 and P6 inputs
    · 2)·Measure PING distance
    · 3) If distance is > limit then goto step 2
    · 4) Make P5 and/or P6 OUTPUTs
    · 5) Send pulses to P5 and/or P6 to auto control robot
    · 6) Measure PING distance
    · 7) If distance is < limit then goto step 5
    · 8) goto step 1


    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
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman

    Post Edited (Bean (Hitt Consulting)) : 1/12/2007 12:51:21 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-01-12 14:06
    While the BS2 does only one thing at a time, I believe you can get this to work.

    I = 1
    MAIN:

    IF I = 1 THEN
    PULSIN Chan1Pin, Chan1Val ' This will take up to 20 mSec
    I = 0
    ELSE
    PULSIN Chan2Pin, Chan2Val ' This will take up to 20 mSec
    I = 1
    ENDIF

    ' OK, when here, we've gotten either Chan1Val or Chan2Val updated
    ' AND, we've waited our 20 mSec. So, go ahead and send

    PULSOUT Serv1Pin, Chan1Val ' We update both every 20 mSec to hold positions.
    PULSOUT Serv2Pin, Chan2Val
    GOTO MAIN
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2007-01-12 15:37
    Computer guy,

    What you describe has been done using HB-25 Motor Controllers (which we manufacture). I have checked to see what the refresh rate is to the controllers though. The HB-25 does not require refreshing like a servo even though it uses servo pulses.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • computer guycomputer guy Posts: 1,113
    edited 2007-01-12 22:38
    Thank you Bean, allanlane5 and Chris Savage for your support and help i am looking forward to seeing how this goes and will post my progress. I expect the whole project to take up to 2 years as i am building a large robot up to 60 cm long, 45 cm wide and 25 cm tall. This is going to be a really big project.

    So far the robot has cost me about AU$700 and i havent built the chassis so yea about 2 - 3 years.

    Thank you
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-01-12 22:54
    Guy,
    If you are investing that much time and money, your should seriously consider switching over the Propeller. The BASIC Stamp is nice, but you are going to hit task limitations pretty quickly and I think you'd enjoy the power and the flexibility of the Propeller much more.

    My 2 cents,
    martin

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Martin Hebel
    StampPlot - Graphical Data Acquisition and Control
    AppBee -·2.4GHz Wireless Adapters & transceivers·for the BASIC Stamp & Other controllers·
  • computer guycomputer guy Posts: 1,113
    edited 2007-01-12 23:10
    Since i have already spent the money on a basic stamp 2 and a board of education. which cost me a large amount of my current spent money. I think i will stick with that for the moment. But if that doesn't work out or in the future i decide to add more to my bot i might consider a propeller chip.

    Thank you for your recomendation Martin

    P.S because of the propeller logo i couldn't take it seriously. It just looks to kiddy.
  • computer guycomputer guy Posts: 1,113
    edited 2007-01-12 23:16
    If i could use the Board of education with the propeller chip i would be more likely to use it as i dont like wireing expensive chips to a power source.
    Perhaps parallax will develop a propeller Board of education type board to replace the Propeller Education Kit that uses a bread board for the whole thing. ( www.parallax.com/detail.asp?product_id=32305 ).
  • Martin HebelMartin Hebel Posts: 1,239
    edited 2007-01-13 02:35
    Hi Guy,
    Well, you'll need to get over your 'kiddy' impression of the logo.· Parallax is very playful, but extremely competent.· To many in industry, the BASIC Stamp is the kiddy, whereas the propeller is being seen as the powerful controller it truly is.

    Soon a protoboard for the propeller is due to be released, and while it is solderboard, you can slap a couple small breadboards, like the BOE ones, or solder directly for a firm connection needed in robotics.· They board is expected to be around $25, plus another $29 for the programming interface, and it has an area for servo headers.

    Don't get me wrong, I love the Stamp, but I know its limitations too, especially in the area of real time control.

    -Martin
    ·
  • computer guycomputer guy Posts: 1,113
    edited 2007-01-13 05:49
    Thank you martin. I whent to the parallax web site to look at getting a stamp and noticed the logo but diddn't think that it was more powerfull than the stamp until you told me.

    Thank you for pointing out the power of the propeller chip will definately use it in future projects.
    I look forward to the release of the development board for it.
Sign In or Register to comment.