Shop OBEX P1 Docs P2 Docs Learn Events
SX28, PING)) and a Parallax Standard Servo and parallel 2x16 LCD Working Code — Parallax Forums

SX28, PING)) and a Parallax Standard Servo and parallel 2x16 LCD Working Code

Bill ChennaultBill Chennault Posts: 1,198
edited 2010-01-15 18:43 in General Discussion
All--

Attached is the working code which uses an SX28 to drive PING)) mounted on a servo. PING)) distance is displayed on a parallel 2x16 LCD. The servo parameters were all empirically derived for this particular configuration.

The current configuration lives on a PDB with an SX28 and a 20MHz resonator. I plan to move it to one of RobotWorkshop's breadboard-mounted SX48 Modules on my robot. However, I will soon replace the PING))/servo combination with three fixed PING)) units.

Getting the servo to work correctly was very difficult. In the future, I may dedicate a Stamp for servo control and simply communicate with it from whatever microcontroller needs the data.

Thanks to all that helped!

--Bill

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
You are what you write.

Comments

  • RobotWorkshopRobotWorkshop Posts: 2,307
    edited 2010-01-15 16:15
    Hello Bill,

    When you move to the SX48 chip I have some example SX/B code that may help you control one or two servos. My son has a small SumoRobot that uses an SX48 as the brain. To control the two servo motors I have each one connected to the built in 16-bit Hardware timers that the SX48 has. The SX28 only has a single 8-bit timer. By using the built-in hardware timers in PWM mode you can just load the values you want and forget it. The hardware does it all in the background for you and you don't need to put that code in your ISR or in your regular code. You just need to load the appropriate timer values whenever you want to set a new position for the servo. The only issue I ran into and had to address was that by default the hardware timers would generate an interrupt when enabled. When you don't expect the extra Interrupts it can cause problems with your ISR code. Since I didn't need (or care) about any interrupts from the timers (not needed in PWM mode) I just masked them off and ignored them. Once that was done it worked perfect.

    Robert
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2010-01-15 16:21
    Robert--

    I went into SX48 mode at 2:20AM, today! [noparse]:)[/noparse]

    I have been thinking about putting the servo in an ISR, but your·method sounds way better. (Will your method PREVENT one from using interrupts, also?)

    By the way, the code attached above·"ported" to·your SX48 Module perfectly. I have it up and running on a PDB at 20MHz.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
  • JonnyMacJonnyMac Posts: 9,211
    edited 2010-01-15 18:14
    Bill:

    In the SX/B help file under TIMER you'll find example code for driving a servo with one of the SX48 hardware counter/timers. Note that when you're dealing with the counters you may not be able to use servo values as you did with PULSOUT. For example, at 20MHz, you may want to set the prescalar to 1:16 -- this will give you a clock rate into the coutner of 0.8us. Now you divide this into your servo values.

    Servo frame = 20ms; 20ms / 0.8us = 25_000
    Servo min = 600us; 600us / 0.8us = 750
    Servo max = 2400us; 2400us / 0.8us = 3_000

    These values can be used with the TIMER1 instruction in PWM mode. Or... if you use an 8MHz resonator (we have them at EFX-TEK) with a 1:8 prescalar the numbers become automatic.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon McPhalen
    Hollywood, CA

    Post Edited (JonnyMac) : 1/15/2010 6:25:00 PM GMT
  • Bill ChennaultBill Chennault Posts: 1,198
    edited 2010-01-15 18:43
    JonnyMac--

    Obviously, more study is in order!

    Thank you for the guidance.

    --Bill

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    You are what you write.
Sign In or Register to comment.