Advanced AVR Servo 3.0 - POT ADC MCU timer Signal Generation Code
Harder and easier than one could imagine. To increase both code and speed efficiency, 2 timers clocked in with 2 different sources are required to generate the long 20000us delay, the short 500-2500us delay and the ever shorter 30us delay for one step of the arm position. 2000/30=66 positions are possible with a rotation angle of about 200 degree.
This belongs to Advanced AVR 3.0 because beside the above features, there will be a fast mode and a silent mode. While the servo arm is an simple output device, able to track its precise position at any moment of MCU time can be critical, and this has 2 factors: time and load, so good coding is anything but simple.
Thus this is a high precision timer example. Instead of blinking LED, the waveform is used to control a servo. Advanced code developed here will be utilized in a 3D-printed mechanic clock. The rotational mechanism may even be used to switch a 10-digit Nixie tube, a semi-mechanic high voltage digital clock.
Finally to make this battery-friendly, the servo code needs to have 3 modes of operation: 1, active; 2, idle; 3, power-down; In active mode, the servo is continuously powered by a control signal; In idle mode, the servo signal is halted, but its arm location is held by applying power to the module; In power-down mode, no-signal and no power are applied to the servo.