Menu

How I can add a SERVO command to GCBASIC?

Help
2008-01-15
2013-05-30
  • Nobody/Anonymous

    First of all my regard to Mr Hugh Considine and colaborators.
    My question is: How I can add a SERVO command to GCBASIC?

     
    • Nobody/Anonymous

      I haven't actually got a chance to test this code.  It's dependant on the PULSEOUT function working accuratly with a runtime varible as an input. (not just a compile time constant)

      If PULSEOUT doesn't work with runtime variable input, GCBASIC will need to be updated to include proper runtime variable support for PULSEOUT because this feature is tremendously important for things like driving servos in robotic projects.

      If PULSEOUT does work correctly, then it's really simple because almost all RC servos use a simple positive pulse of 1ms to 2ms to control thier position (though a few companies in the past have also used negative pulses).

      A 1ms wide pulse runs the servo to one extreme while a 2ms pulse will run it to the other end of it's travel (a 1.5ms pulse is defined as the center position).

      For a standard positive pulse servo the off time is not supposed to be a factor, but it's a good idea to leave at least a few tenths of a millisecond between pulses as a minimum to make sure the individual pulses are recognized, and no more than 10ms to 20ms between pulses as a maximum to prevent jitter as the servo updates.

      To create a Servo drive command you just need to use the PULSEOUT command with the resolution of the 'time units' for the command set to '10us', and make sure to pre-scale your variable to fall within the range of 100 to 200 (1ms to 2ms).

      Just scale the number from 0 to 100 (which we can think of as 0 to 100% motion) then add a baseline value of 100 to get it in the range of 100 to 200 then use the PULSEOUT command with the 'time unit' resolution value of '10us' .

      Here is a simple test program that should move the servo through it's full range -

      DIR PORTA.0 OUT  'Servo's control input to PORTA.0 (Servo also connected to GND, 5V)
         
      Main:

      FOR position = 100 to 200
      PULSEOUT PORTA.0, position 1Ous  '1ms to 2ms positive pulse to servo, with 100 steps
      WAIT 10 ms                       'at about 11 to 12 ms each = 1.15 seconds total for
      NEXT                              'the servo to travel from full CCW to full CW.

      DO WHILE position >= 100
      PULSEOUT PORTA.0, position 10us
      position = position - 1          'Return sweep at takes roughly 5 times longer
      WAIT 50ms                        'due to this 50ms delay.
      LOOP                     

      GOTO Main

       
      • Nobody/Anonymous

        Hi, this is exactly what I am trying to do also.  But, when I ran your test code I received the following compiler error message:

        An error has been found:

        stdbasic.h (115): Error: Delay units not specified

        I'm running v9.0.3 (the latest download) and ide v1.4.  Thanks....

         
    • Nobody/Anonymous

      Take a look at PicBasic Pro from MeLabs and also the Rentron site. Rentron has several projects with servo's with PicBasic code. Also take a look at the Oshonsoft site. The manual shows code for controling a servo. When you download the Pic_Sim_Ide you get the maual with it.

       
    • Nobody/Anonymous

      Download the update file for Gcbasic and overwrite the existing with this .

       

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.