Hello there!
I am a newbie but after done some “homework” I looked back to the photovore_v1 source code and I have questions in the following portions of the code.
in the header (.h) file…
void delay_cycles(unsigned long int cycles)
{
while(cycles > 0)
cycles--;
}
//***************************************
void servo_left(signed long int speed)
{
PORT_ON(PORTD, 0);
delay_cycles(speed);
PORT_OFF(PORTD, 0);//keep off
delay_cycles(200);
}
void servo_right(signed long int speed)
{
PORT_ON(PORTD, 1);
delay_cycles(speed);
PORT_OFF(PORTD, 1);//keep off
delay_cycles(200);
}
and in the c file...
delay_cycles(500);//a small delay to prevent crazy oscillations
The questions are:
a) Why do we have the command “delay_cycles(200) after turning port D to zero? Why is it necessary?
b) From my readings on servo-motor specs, I believe that the signal that we are sending to the motor, such as 1.5 ms of high voltage, must be “modulated” in a 50 ms signal. Therefore, if we send a 1.0 ms of high voltage making the motor to go full left position, then we need to make the next 49 ms with low voltage and then after it, and repeat this sequence over and over again if you want to keep this position. If we apply 2.0 ms of high voltage, then we need only 48 ms. Assuming that the above statement is correct, then here comes my question:
b1) the servo_right and servo_left have the same last line (delay_cycles(200)). I believe that they should be different to account for the differences in the length of time (48 ms and 49 ms explained above). Is it right?
b2) also, there is a delay_cycles(500) in the last line of the while(1) loop.
Adding up for those delays for any turn, such as left turn, we get the following numbers: one servo will have a total of delay cycles of 745 and the other 725, what gives a total of ~32 and 31 milliseconds respectively. The question then is: where is the rest of milliseconds that the microprocessor should have to wait to add up the 50 ms modulation accounted in this code?
c) Last but not the least… to calculate the number of cycles to be delayed, the code states the following:
23/.992*(time in milliseconds) = number of cycles
I could not figure out from where the “23” and the “0.992” came from. Could any one of you give me a reasonable explanation? Thanks.
Well that is it. If you know any of the above questions, please give me a feedback.
Regards,
Paulo Brasko