Buy an Axon, Axon II, or Axon Mote and build a great robot, while helping to support SoR.
0 Members and 1 Guest are viewing this topic.
while(1){PORTC |= (1 << PC0);_delay_us(1500);PORTC &= ~(1 << PC0);_delay_us(18500);}
while(1) // do an infinite loop { servo(PORTA,7,700); // give the servo connected to PORTA.7 one pulse of 700 cycles which is the center point of the servo delay_ms(20); // delay 20 milliseconds so as not to overload the servo }
#include "SoR_Utils.h" //includes all the technical stuff#define CLAMPMS(x) (((x) > (2.5)) ? (2.5) : (((x) < (0.5)) ? (0.5) : (x)))#define CLAMPDG(x) (((x) > (180)) ? (180) : (((x) < (0)) ? (0) : (x)))volatile float amt=0;volatile float count=0;volatile float ms=1.5;// uses the following logic to count its iteration rate:// (16000000 / 8) / 256 = 7812.5 cycles per 1000 ms// by this i deduce that 156.25 cycles is 20 ms// and in turn have a formula to plug in 1.5 ms to...void timerInterruptFunc(void){ count+=1.0; if(count>=156.25) { count=0; amt = (float)((float)(7812.5 * ms)/1000.0); PORTC |= (1 << PC0); } if(count>=amt) { PORTC &= ~(1 << PC0); }}int main(void){ //declare variables here int i=0;//useless variable int j=0;//useless variable char inp[6]; int inpon=0; int t; char degrees=0; /****************INITIALIZATIONS*******************/ //other stuff Im experimenting with for SoR 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 //G=Ground, T=Tx (connect to external Rx), R=Rx (connect to external Tx) rprintfInit(uart1SendByte);// initialize rprintf system and configure uart1 (USB) for rprintf timer0Init(); // initialize the timer system configure_ports(); // configure which ports are analog, digital, etc. a2dInit(); // initialize analog to digital converter (ADC) a2dSetPrescaler(ADC_PRESCALE_DIV32); // configure ADC scaling a2dSetReference(ADC_REFERENCE_AVCC); // configure ADC reference voltage LED_on(); rprintf("\r\nSystem Warming Up"); //let system stabelize for X time for(i=0;i<=16;i++) { delay_cycles(5000); rprintf("."); } delay_cycles(6000); //read each ADC once to get it working accurately for(i=0;i<16;i++) j=a2dConvert8bit(i); LED_off(); rprintf("Initialization Complete \r\n"); timerAttach(TIMER0OVERFLOW_INT, timerInterruptFunc); reset_timer_0(); while(1) { t=uart1GetByte(); if(t!=-1) { if(t==13) // enter { rprintf("\n"); inp[inpon] = '\0'; inpon=0; if(degrees==1) ms = atoi(inp); else ms = atof(inp); if(degrees==1) { ms = CLAMPDG(ms); rprintf("using: %d", (int)ms); rprintf("\n"); ms = (((ms/180.0)*1.8) + 0.6); } else { ms = CLAMPMS(ms); rprintf("using: "); rprintfFloat(3, (double)ms); rprintf("\n"); } } else if((t>=48 && t<=57) || t == 46) // numeral or period { inp[inpon++] = (char)t; rprintf("%c", t); } else if(t==68 || t==100) // 'D' 'd' { rprintf("\ndegrees.\n"); degrees = 1; } else if(t==77 || t==109) // 'M' 'm' { rprintf("\nmilliseconds.\n"); degrees = 0; } else if(t==8) // backspace { inp[--inpon]='\0'; rprintf("\n"); for(i=0; i<6; i++) { if(inp[i]!='\0') rprintf("%c", inp[i]); else break; } } } } return 0;}
well its interrupt driven, all you do is set ms to 1.5 or whatever in the while(1) main exec loop...but suddenly my servo doesn't work anymore daaaaaammiiiiiit
In axon's case it is 1 000 000 000 (ns) / 20 000 000 (MHz)