Propeller C Code for Servos
sisc0br
Posts: 4
Problem: Activity Board Rev A sends signals out over multiple headers
I have written C code that calls several functions that direct the movements of two High Speed Continuous Rotation servos. The first servo is connected on Header 12, the second servo is connected on Header 17.
The code that runs the First servo is executed first; then the code for the second servo is executed.
The code for the first servo executes as expected with all signals on Header 17. When the code statements for the second servo begin, the Activity Board sends the same signals to Header 17 as to the intended Header 12. Both servos do the same thing. If I comment out the code for the first servo, then the code for the second servo runs as expected.
Code follows:
/*
craneMotor.c
Rotates Servo
http://learn.parallax.com/propeller-c-tutorials
*/
#include "simpletools.h" // Include simple tool
#include "servo.h"
#include "propeller.h"
#include "stdio.h" // Include servo tools
//Function Prototypes
void rotCntrClkWse(int rotLoops, int rotSpeed);
void rotClkWse(int rotLoops, int rotSpeed);
void lift(int loops, int speed);
void descend(int loops, int speed);
int main()
{
int rotLoops = 500;
int rotSpeed = 100;
int loops = 10000;
int speed = 100;
pause(1500);
pause(500);
printf("Enter counter-clockwise rotation speed: ");
scanf("%d", &rotSpeed);
pause(500);
rotCntrClkWse(rotLoops, rotSpeed);
servo_stop();
printf("Completed counter-clockwise rotation \n");
printf("Enter clockwise rotation speed: ");
scanf("%d", &rotSpeed);
pause(500);
rotClkWse(rotLoops, rotSpeed);
servo_stop();
printf("Completed clockwise rotation \n \n");
pause(500);
printf("Enter desired speed of lift: ");
scanf("%d", &speed);
pause(500);
lift(loops, speed);
servo_stop();
printf("Completed servo lift \n");
printf("Enter desired speed of descent: ");
scanf("%d", &speed);
pause(500);
descend(loops, speed);
servo_stop();
printf("Completed descent \n \n");
pause(1500);
printf("OK! That's it; we are done with this test! \n");
} //End of Main function
void rotCntrClkWse(int rotLoops, int rotSpeed)
{
printf("You set speed of counter-clockwise rotation to %d\n", rotSpeed);
for(int i = 0; i <=rotLoops; i++) // 10,000 cycles produces rotation for 5 sec
{
servo_speed(17, rotSpeed);
}
servo_stop();
}
void rotClkWse(int rotLoops, int rotSpeed)
{
printf("You set speed of clockwise rotation to %d\n", rotSpeed);
for(int i = 0; i <=rotLoops; i++) // 10,000 cycles produces rotation for 5 sec
{
servo_speed(17, -rotSpeed);
}
servo_stop();
}
void lift(int loops, int speed)
{
printf("You set speed of ascent to %d\n", speed);
for(int i = 0; i <=loops; i++) // 10,000 cycles produces rotation for 5 sec
{
servo_speed(17, 0);
servo_speed(12, speed);
}
servo_stop();
}
void descend(int loops, int speed)
{
printf("You set speed of descent to %d\n", speed);
loops = loops - 8300;
for(int i = 0; i <=loops; i++) // 10,000 cycles produces rotation for 5 sec
{
servo_speed(17, 0);
servo_speed(12, -speed);
}
servo_stop();
}
I have written C code that calls several functions that direct the movements of two High Speed Continuous Rotation servos. The first servo is connected on Header 12, the second servo is connected on Header 17.
The code that runs the First servo is executed first; then the code for the second servo is executed.
The code for the first servo executes as expected with all signals on Header 17. When the code statements for the second servo begin, the Activity Board sends the same signals to Header 17 as to the intended Header 12. Both servos do the same thing. If I comment out the code for the first servo, then the code for the second servo runs as expected.
Code follows:
/*
craneMotor.c
Rotates Servo
http://learn.parallax.com/propeller-c-tutorials
*/
#include "simpletools.h" // Include simple tool
#include "servo.h"
#include "propeller.h"
#include "stdio.h" // Include servo tools
//Function Prototypes
void rotCntrClkWse(int rotLoops, int rotSpeed);
void rotClkWse(int rotLoops, int rotSpeed);
void lift(int loops, int speed);
void descend(int loops, int speed);
int main()
{
int rotLoops = 500;
int rotSpeed = 100;
int loops = 10000;
int speed = 100;
pause(1500);
pause(500);
printf("Enter counter-clockwise rotation speed: ");
scanf("%d", &rotSpeed);
pause(500);
rotCntrClkWse(rotLoops, rotSpeed);
servo_stop();
printf("Completed counter-clockwise rotation \n");
printf("Enter clockwise rotation speed: ");
scanf("%d", &rotSpeed);
pause(500);
rotClkWse(rotLoops, rotSpeed);
servo_stop();
printf("Completed clockwise rotation \n \n");
pause(500);
printf("Enter desired speed of lift: ");
scanf("%d", &speed);
pause(500);
lift(loops, speed);
servo_stop();
printf("Completed servo lift \n");
printf("Enter desired speed of descent: ");
scanf("%d", &speed);
pause(500);
descend(loops, speed);
servo_stop();
printf("Completed descent \n \n");
pause(1500);
printf("OK! That's it; we are done with this test! \n");
} //End of Main function
void rotCntrClkWse(int rotLoops, int rotSpeed)
{
printf("You set speed of counter-clockwise rotation to %d\n", rotSpeed);
for(int i = 0; i <=rotLoops; i++) // 10,000 cycles produces rotation for 5 sec
{
servo_speed(17, rotSpeed);
}
servo_stop();
}
void rotClkWse(int rotLoops, int rotSpeed)
{
printf("You set speed of clockwise rotation to %d\n", rotSpeed);
for(int i = 0; i <=rotLoops; i++) // 10,000 cycles produces rotation for 5 sec
{
servo_speed(17, -rotSpeed);
}
servo_stop();
}
void lift(int loops, int speed)
{
printf("You set speed of ascent to %d\n", speed);
for(int i = 0; i <=loops; i++) // 10,000 cycles produces rotation for 5 sec
{
servo_speed(17, 0);
servo_speed(12, speed);
}
servo_stop();
}
void descend(int loops, int speed)
{
printf("You set speed of descent to %d\n", speed);
loops = loops - 8300;
for(int i = 0; i <=loops; i++) // 10,000 cycles produces rotation for 5 sec
{
servo_speed(17, 0);
servo_speed(12, -speed);
}
servo_stop();
}