Page 1 of 3 123 LastLast
Results 1 to 10 of 30

Thread: Pic servo control question

  1. Pic servo control question

    I am interested in programming a Pic to continuously control 2 servos on my robot's engine when my Propeller Chip tells it to. I unfortunately have only been working with the Pic for less than a week making tasks that much harder.

    I originally planned to use pin RA3 on my Pic16F684 to detect the binary signals 10 or 11 to choose the servo, then the regular pulse requested to have repeated by the Pic every 20ms. But during my earlier tests I found the pulse time the Pic repeated was longer than the input pulse time. Since I know little C, I do no know if there is a way to detect timing other than the way I tried, which was done by incrementing a variable during the time the pulse was presented.

    Working with the Propeller Chip, I know it can detect the time it took to complete a task by looking up the number of clock cycles. Is there something similar on the Pic, or should I take a different approach?

  2. #2
    Join Date
    May 2008
    Location
    TN
    Posts
    853
    Images
    99
    Rep Power
    72

    Re: Pic servo control question

    For similar devices, look at the AVR family. They have a bit bigger hobbyist following I think. The Roboduino is a pretty good robot/AVR development platform and there is no programmer required. Plus it is supported by the Arduino IDE and libraries which makes it much more entry level friendly. It's also a pretty good way to get your feet wet in C.

    Out of curiosity, why not use a serial servo controller?
    "If A is a success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut."
    -
    Einstein

    Don't be a HelpVampire

  3. Re: Pic servo control question

    I am currently learning C out of a book I already have. I am thinking about getting an Arduino later this year, though.

    The reason I don't buy a servo controller is because I already have the parts necessary lying around, and it would be useful to learn how to do this in C anyway. Also, I was planning to connect it to my servo to have it as a more permanent feature and allow me to reduce the number of servo cables I need to have leading away from my engine. It is maybe two feet from my engine to the front area of my robot that I will hold all the electronics.

  4. #4
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Pic servo control question

    An AVR can be programmed in C using _free_ tools.

    But, depending upon the PIC, it does have interrupts [a concept the Propeller has renamed/changed a little], and with interrupts you get timers.
    I Void Warranties�

  5. Re: Pic servo control question

    That could work, but I'll have to do a little research on it. I have an SX book here that talks about it a little, but it works with assembly. Would it be very difficult to then convert the code in ASM to C?

  6. #6
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Pic servo control question

    Not if you're an expert in both PIC Assembler and whatever flavor of C you're coding to - then it's only "moderately difficult".

    If you're not going to learn interrupts and timers inside and out, you're probably better off with a different processor and a different language.
    I Void Warranties�

  7. Re: Pic servo control question

    Hmm, that will have to wait then. I do plan to eventually get this kit though: http://www.robotshop.us/robotshop-kit.html
    Think it's processor could do the job?

  8. #8
    Join Date
    Apr 2008
    Location
    Sacramento, CA, USA Area
    Posts
    5,341
    Rep Power
    176

    Re: Pic servo control question

    Any reasonably sized microcontroller can drive a servo or two. It's not about what the processor can do, - it's entirely about what the programmer can create. PIC, Arduino, what-have-you - microcontrollers depend extensively upon interrupts and, supplementarily - timers. Without interrupts (or some message passing architecture that utilizes them), realtime behavior doesn't happen.

    That said, some learning architectures are designed to insulate one from those concepts for as long as possible.

    Is there a reason not to jump in and learn the concepts? They're not that tough really! Have a read through Fergs' tutorial on interrupts (written for the AVR architecture, but the concepts are similar across the board)
    I Void Warranties�

  9. Re: Pic servo control question

    It's not that I don't wish to learn it, it's just I'm trying to figure out what works. I will read through the tutorial and see if it will help me somewhat, but right now I'm in the dark.

  10. #10
    Join Date
    May 2008
    Posts
    2,228
    Images
    155
    Rep Power
    126

    Re: Pic servo control question

    Ways to Read a Pulse Length (on an Arduino):

    Option 1 - Use the pulsein command to read in the pulse. Pulsein is pretty accurate. It waits for the pulse to start, then loops around. You have to know the exact length of your loop, best timing is going to be plus/minus the length of your loop.

    Option 2 - Use an interrupt, configured for rising and falling edges, when the interrupt triggers on rising edge we mark the time, when the interrupt triggers going down, we subtract the original time from the current time, we have pulse width. Have to time out how long the transition into the ISR is. Best time will be plus/minus the true width of the system clock (several uS on the Arduino I believe).

    Option C - Use a timer/counter, setup to count only when the pin is high. Best time will be plus/minus width of the timer clock... likely not a good option as it will eat up the 16-bit timer/counter, which we need for:

    Controlling a Servo with an Arduino:
    The servo library uses timer/counter1 (the only 16-bit t/c) to control up to 2 servos. Really easy to use.

    -Fergs

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question(s) Servo Control Circut
    By WarriorofHonour in forum DYNAMIXEL & Robot Actuators
    Replies: 9
    Last Post: 06-04-2009, 01:06 AM
  2. Disaster! Video of phidget servo control (Comedy included!)
    By Semicton in forum Software and Programming
    Replies: 6
    Last Post: 02-22-2009, 03:08 AM
  3. RC & Serial Servo Controller Kit
    By Al1970 in forum Garage Sale
    Replies: 0
    Last Post: 01-10-2009, 01:39 AM
  4. Question(s) Servo control using FSRs
    By heat in forum Arbotix, Microcontrollers, Arduino
    Replies: 15
    Last Post: 01-05-2009, 04:32 PM
  5. Kondo web page translated.
    By Droid Works in forum Humanoids, Walkers & Crawlers
    Replies: 4
    Last Post: 10-06-2007, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •