New Servo Motor Include File

Anonymous
2014-06-03
2014-06-03
  • Anonymous - 2014-06-03

    Hi gang,

    As part of my ongoing crusade to show the Arduino crowd that Great Cow Basic can be just as easy if we all pitch in, here is my next contribution: a servo motor include file that makes using such a creature virtually automatic.

    The include file is moderately intelligent, uses scripts and computes any needed constants automatically. The user need know nothing about what's under the bonnet. It works equally well with internal RC clocks, crystals or ceramic resonators. But the source code is thoroughly commented to encourage others to modify and extend it. A single subroutine (setAngle) is then available to set the angle of the servo. For example, here's a quick demo to step a motor along at 30 degree angles:

    ;----- Configuration
    
    #chip 16F88, 8                    ;PIC16F88 running at 8 MHz
    #config mclr=off                  ;reset handled internally
    #config osc=int                   ;internal RC clock
    #include "Servo.h"                ;GC Basic servo include file
    
    ;----- Constants
    
    #define SERVO_PIN         PortB.0 ;servo control pin
    #define SERVO_0_DEGREE    825     ;duty cycle in uS for 0 degrees
    #define SERVO_180_DEGREE  2550    ;duty cycle in uS for 180 degrees
    #define SERVO_PERIOD      20000   ;total period in uS
    
    ;----- Variables
    
    dim i as byte
    
    ;----- Program
    
    do
      for i = 0 to 180 step 30        ;step through the angles
        setAngle(i)
        wait 5 S
      next i  
    loop  
    

    That's it! Short and sweet. Note that this runs in the background using Timer1 and the Compare module, so needs no babysitting. The program itself can do whatever it wants and the servo will take care of itself.

    Did you notice the four constants? Simply set these to match your particular motor and away you go.

    I'll attach the new include file in the next post.

    Thomas Henry

     
  • Anonymous - 2014-06-03

    Here's the Servo include file. I took a lot of time to fully document it in hopes of garnering contributions from others, so I hope you'll take a moment to read over the comments. And since I'm pretty new to servos and GCB include files, I also hope you'll offer up any suggestions for improvements.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks