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.
23/.992*(time in milliseconds) = number of cycles
From where do we get the 23/.992 ?
Also, how would this formula change if the microcontroller was running at 16mHz
servo(1.5)
If I write a macro for mS, can I do Code: [Select]servo(1.5)Or can it not handle the 1.5?
PORT_ON(PORTE, 6);delay_ms(1.9);PORT_OFF(PORTE, 6);delay_ms(1);
PORT_ON(PORTE, 6);delay_ms(1);PORT_OFF(PORTE, 6);delay_ms(1);
However, I remember that AVRlib had some bug that if you put a variable in it like this:delay_us(variable);that it won't work if the variable went above 255. So thats why I created the cycles method for servos. Plus, on the $50 Robot, timer interrupts are limited.
just use 1500uS instead of 1.5mS
Set up code:'set up servo macro#define servo(port,number,position) (PORT_ON(port,number), delay_us(position), PORT_OFF(port,number))'hardware define:#define servo1( position ) servo(PORTE,6,position)
servo1(1500)
instead of using software based pwm, why don't you use the pwm capabilities built into the avr?
'RA, RK, RH, LA, LK, LH, speed#0 P1427 #1 P1292 #2 P1292 #16 P1573 #17 P1708 #18 P1708 T500
void pulse(uint8_t microseconds) { while (microseconds > 0) { delay_us(1); microsecs--; } // end while loop} // end pulse function
void move_servo(unsigned int duty){ SERVO1 = 1; Delay10TCYx(duty); Delay10TCYx(duty); Delay10TCYx(duty); Delay10TCYx(duty); SERVO1 = 0;}
You could just write a quickie function that converts milliseconds to cycles . . .
void pulse(uint8_t microseconds) { while (microseconds > 0) { delay_us(1); microseconds--; } // end while loop} // end pulse function
//define the servo function macro#define servo(port,number,position) (PORT_ON(port,number), pulse(position), PORT_OFF(port,number))
servo_1(1500) // where 1500 is the pulse in microseconds.
void pulse(uint8_t microseconds) { while (microseconds > 0) { microseconds--; } // end while loop} // end pulse function
void pulse(unsigned long int microseconds) { microseconds=microseconds/16; while (microseconds > 0) { delay_us(1); microseconds--; } // end while loop} // end pulse function
so i'm no C expert but . . . the type "unsigned long int" you use later is possibly a little excessive allowing 4 bites = max value of 4294967295.
Admin: when you were talking about the bug with delay_us accepting a max value of 255 near the start of this thread, delay_us in AVRlib is written to accept the type "unsigned short" which i believe is the same as "unsigned short int" should be good for 2 bytes...this strikes me as a compiler issue rather than a AVRlib issue.what compiler do you use?i'm guessing you could chance AVRlib's timer.c to make delay_us use type "int" instead of "short int" as a workaround.
Isn't it 65535
And isn't it spelled 'byte'?