Pulse Width Modulation

  • Clock
  • Pre-scalar
  • Duty cycle (in percentage)
  • Period (the total width of high and low, in ms)
  • When TCNT (time counter) matches OCRA, actions are triggered
void doNextOC() {
    unsigned short *pTCNT = ...
    unsigned short *pOCRA = ...
    *pOCRA += byHigh ? 2800 : 1200;
    byHigh = !byHigh;
}