Menu

Servo help

Help
Nick
2008-09-14
2013-05-30
  • Nick

    Nick - 2008-09-14

    I am new to GCbasic, but so far I love the program.  I am using a PIC16F684 chip and I want to move a single servo from maximum left to maximum right.  I tried several examples that were posted but I am not able to get it to work properly.  Can anyone help?  A working sample code would be excellant.

    Thanks in advance for you help.
    Nick

     
    • Nobody/Anonymous

      read the picaxe servo interface manual. gcbasic doesnt have a servo command, but the manual tells you the timing so you can make your own code

       
    • Nobody/Anonymous

      Have you tried looping a pulseout command between 1.0-2.0 ms? I believe 1ms equals far left and 2 ms equals far right (or the opposite, depends on the servo). Sometimes the ms values will need to be altered to get full rotation.

       
    • Hugh Considine

      Hugh Considine - 2008-09-14

      This worked for me with a 16F877A and a Hitec HS-81 servo. You'll have to change the first 4 lines to suit your setup but otherwise it should be fine:

      #chip 16F877A, 20
      #define ServoPin PORTD.3
      #define ServoMin 65
      #define ServoMax 225

      Dir ServoPin Out
      Do
          For Temp = ServoMin to ServoMax
              PulseOut ServoPin, Temp 10us
              Wait 6 ms
          Next
          For Temp = ServoMax to ServoMin
              PulseOut ServoPin, Temp 10us
              Wait 6 ms
          Next
      Loop

       
    • Nick

      Nick - 2008-09-14

      Thanks for the replies.  I tried the posted code and I think it will work, but my PIC16F684 only supports a 8 MHZ clock.  How does this affect the timing?  The code will move the servo one direction and it stops.  I will try it on a PIC16F690 which supports 20 MHZ as well, but does anyone know if I could use the 8 MHZ clock instead?

      Thanks again.

       
    • Hugh Considine

      Hugh Considine - 2008-09-14

      The timing will be very slightly altered, but only by 2 or 3 microseconds - not anything worth worrying about. The code I posted will work fine on any chip down to 4 MHz.

       
    • Nick

      Nick - 2008-09-16

      Thanks again....It works excellant!

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.