So here are specifications: -prescaler of 8 -Channel A -pulse_width is determined by user defined degrees (converted to clock ticks) -pulse_period is 40000 clock ticks (20ms) -Normal mode -Timer3
So we have a move_servo(unsigned degrees) where all it does is convert the degrees to clock ticks and store it in pulse_width. Ok no problem.
Then we need ISR(TIMER3_COMPA_vect). This interrupt is supposed to actually generate the waveform where pulse_width would be high and (pulse_period-pulse_width) would be low (so total pulse length is 20ms).
Now I am not quite understanding how the OCR3A register works. My thinking for the ISR was to have a flag variable so that the first time ISR goes off, it sends pulse_width out of OCR3A, then set flag, next time it goes off it sends off pulse_period-pulse_width (which will be low and is the wait time between each movement of servo) and will set flag to 0 again.
But writing to OCR3A will move servo right? Will my plan work in the toggle mode for normal mode? So every other trip into the ISR sends out the "wait time" which is low so it doesn't move servo?
My question is basically am I on the right track? Or if not can anyone help me understand how to generate a random lengthed pulse followed by a "wait time" waveform in normal mode?
This is ATmega128 again fyi