Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
#include "SoR_Utils.h"int main(void){ int i,j; uartInit(); // initialize the UART (serial port) uartSetBaudRate(0, 38400); // set UARTE speed, for Bluetooth uartSetBaudRate(1, 115200);// set UARTD speed, for USB connection uartSetBaudRate(2, 38400); // set UARTH speed uartSetBaudRate(3, 38400); // set UARTJ speed, for Blackfin rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf configure_ports(); timer0Init(); //initialize ISR: UCSR1B |= (1 << RXCIE1); // Enable the USART Recieve Complete interrupt (USART_RXCn) sei();//turn on the Global Interrupt Enable flagint servo_position[21]={650,690,660,700,700,700,715,710,235,1130,275,1090,330,1105,270,1090,650,650,640,650,670,575};int servo_number[21]={6,6,7,2,1,5,2,6,0,4,3,5,3,2,4,4,4,1,5,3,7,3}; int *servo_port[5]={PORTJ,PORTA,PORTE,PORTH,PORTC,PORTA}; while (1) { int isDone=0; for (i=0;(i<21-1)&&(!isDone);i++) { isDone=1; for (j=0;j<21-i-1;j++) { if (servo_position[j]>servo_position[j+1]) { // swap servo position int tmp = servo_position[j]; servo_position[j] = servo_position[j+1]; servo_position[j+1] = tmp; // keep number and port in sync with the position tmp = servo_number[j]; servo_number[j] = servo_number[j+1]; servo_number[j+1] = tmp; tmp = servo_port[j]; servo_port[j] = servo_port[j+1]; servo_port[j+1] = tmp; isDone=0; } } } //turn off interrupts .. this is very important otherwise your servo will jitter! cli(); // set all the ports to on that are enabled (i.e.>0) for (i=0;i<21;i++) { if (servo_position[i]>0) { PORT_ON(*servo_port[i], servo_number[i]); } } // delay until the last position has occured int offset=0; for (i=0;i<21;i++) { if (servo_position[i]>0) { if (servo_position[i]>offset) { // wait until this servo's position offset delay_cycles(servo_position[i]-offset); offset=servo_position[i]; } // turn off this servo and continue with next servos PORT_OFF(*servo_port[i], servo_number[i]); } } // renable interrupts so that we can receive UART/serial values sei(); // wait for a total of 20ms from the last servo timing value. timerPause((4666-offset)/234); }}
...If you need to do a lot of processing at the same time, you will slow down the servo loops until you get jitter again. That is why i recommended getting an external servo controller in addition to your microcontroller.
if (servo_position[i]>offset) { // wait until this servo's position offset delay_cycles(servo_position[i]-offset); offset=servo_position[i]; }