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:
#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
#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
dim i as byte
for i = 0 to 180 step 30 ;step through the angles
wait 5 S
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.
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.
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.