USING OUTPUT COMPARE 7 TO CONTROL ANOTHER PTx PIN ON THE HC12 (0 <=x <= 6)

1.
In the main program:
(a)
Turn on timer subsystem (TSCR reg)
(b)
Set prescaler (TMSK2 reg)
(c)
Set up PTx
i.
Configure PTx as OC (TIOS reg)
ii.
Set up action on Cx compare
(d)
Set up OC7 to contol PTx
i.
Configure OC7 to control PTx (OC7M reg, write 1 to bit x)
ii.
Configure PT7 as OC (TIOS reg)
Set up action for PTx on OC7 compare
(OC7D reg, 1 => set, 0 => clear)
iii.
Clear C7F flag (TFLG1 reg)
iv.
Enable C7I interrupt (TMSK2 reg); do not enable CxI interrupt
2.
In toc7_isr() interrupt service routine
(a)
Adjust TCx reg for next action
  • TCx = TC7 + DUTY_CYCLE
(b)
Adjust TC7 reg for next action
  • Add time to TC7 register
    • Add period of PWM to TC7: TC7 = TC7 + PERIOD
(c)
Clear C7F flag (TFLG1 reg)