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;-----Variablesdimiasbyte;-----Programdofori=0to180step30;stepthroughtheanglessetAngle(i)wait5Snextiloop
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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.
When I made a robot with a servo scanning left right I set up a 50Hz interrupt to handle the servo position as I understood it, servos "forget" their position unless retold every 20ms.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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:
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
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.
Last edit: ofuzzy1 2019-06-20
Very nice work! I will have to set up and try it out. Thanks for the include!
When I made a robot with a servo scanning left right I set up a 50Hz interrupt to handle the servo position as I understood it, servos "forget" their position unless retold every 20ms.