Servo control woes


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    11

    Default Servo control woes

    I'm trying to get down the basics of PIC servo control, and not having much luck. I'm using a 16F690 and trying to get some kind of meaningful movement out of my servo. However, the only thing my servo will do is move to one extreme of its range and sit there, perhaps scornfully.

    The offending code is:

    @ DEVICE MCLR_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 8
    servo var PORTC.5
    i var byte

    loop:

    for i = 200 to 400
    low servo
    pulsout servo,i
    pause 18
    next i

    goto loop


    I thought that would get a wiggle out of it, but no. I'm using the internal oscillator there, so I think my timing is correct - the 16F690 is running at 8MHz.

    I've tried many different timings, and I've RTFM and RTFDataSheet and RTF-half-the-contents-of-google. I've tried so many tweaks and variations that I'm worried I'll hit the PIC's write limit soon. I've also tried using different servos (from other manufacturers) and a different 16F690. It just moves in one direction to its extreme and sits, every time.

    What is it I am missing here? Any help would be greatly appreciated.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink a Word about Bytes ...

    [QUOTE=Eriswerks]I'm trying to get down the basics of PIC servo control, and not having much luck. I'm using a 16F690 and trying to get some kind of meaningful movement out of my servo. However, the only thing my servo will do is move to one extreme of its range and sit there, perhaps scornfully.

    The offending code is:

    @ DEVICE MCLR_OFF,WDT_OFF,PROTECT_OFF
    DEFINE OSC 8
    servo var PORTC.5
    i var byte

    loop:

    for i = 200 to 400
    low servo
    pulsout servo,i
    pause 18
    next i

    goto loop


    hi,Eris

    @ 8 Mhz, pulsout resolution is 5µS ( 10µS *4 / F.Mhz)

    so, correct for that.

    for i = 200 to 400 means i should not be a byte ( i max = 255 !!! )

    so, what's happening ??? i value goes from 200 to 255 then ... back to 0 , out of the for - next loop !!! program ends.

    just change i for a WORD !!!

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Feb 2006
    Posts
    11


    Did you find this post helpful? Yes | No

    Default Still no joy

    Thanks for the reply. I've changed the variable's type from BYTE to WORD, but there must be something else wrong as well - my servo still goes to one extreme and sits. Even if I do away with the loop entirely and just send it one position to center it, I'm still getting this behavior. That suggests to me that it must be timing-related, but I've tried timing some LED pulses without doing a DEFINE OSC and it confirms the 8MHz I see in the datasheet.

    Maybe if I buy the PIC some chocolates?

  4. #4
    Join Date
    Feb 2006
    Posts
    11


    Did you find this post helpful? Yes | No

    Default More thoughts on the subject

    Looking through the 16F690 datasheet for anything I might have missed, I found this little nugget:

    The output of the 8 MHz HFINTOSC and 31 kHz
    LFINTOSC connects to a postscaler and multiplexer
    (see Figure 3-1). The Internal Oscillator Frequency
    select bits, IRCF<2:0> (OSCCON<6:4>), select the
    frequency output of the internal oscillators. One of eight
    frequencies can be selected via software.


    So, it seems like in order to make sure that the PIC is running at 8MHz, I should be telling it to use HFINTOSC and not LFINTOSC, and according to the diagram mentioned I should be setting the frequency select bits to 111.

    How do I go about doing that in PicBasic? Is it actually necessary to do so, or does the "intrc_osc_noclkout" that's in the include file for this chip have me covered already? I've also found mentions of putting "OSCCON = $70" in the code to set 8MHz, but I can't seem to find any real documentation on it. Is this controlling the frequency select bits? If so, do I still need to specify HFINTOSC somewhere?

    Sorry for the deluge of questions...

  5. #5
    Join Date
    Sep 2005
    Location
    Dayton, Ohio
    Posts
    72


    Did you find this post helpful? Yes | No

    Default

    1. Why not take the whole 8MHz issue out of the equation and run it at 4MHz? Once you get it working at 4MHz...THEN change the oscillator speed.

    2. I have some servo code at home. For a 12F629 I think. I'll dig it out and post it later.

    3. From what I remember, sending a single pulse of 1.5mS won't center the servo. You have to KEEP sending pulses to get it to move. So if it's at the extreme end, then you have to keep sending 1.5mS pulses until the servo reaches center. AND you need to keep sending those pulses if you expect it to STAY in the center. Some servos are quite a bit slower than others (check the spec sheet).

    regards
    Jim Robertson
    "MilesTag" DIY Lasertag
    www.lasertagparts.com/mtdesign.htm
    Dayton, Ohio

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    Eriswerks, milestag is right, the servo requires updates every 50 milliseconds or so othwise most servos will shutdown and produce no torque.

    Dave Purola,
    N8NTA

Similar Threads

  1. More Servo Woes
    By chrisshortys in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 13th May 2009, 08:40
  2. Replies: 10
    Last Post: - 26th May 2008, 07:00
  3. Help with Servo Control Please!
    By wireman22 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 7th June 2007, 18:15
  4. Control RC servo via Parallax Servo Control
    By cibotsan in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th September 2005, 08:18
  5. Servo control with 12F629
    By achilles03 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd June 2005, 23:34

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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