Generating a pulse width modulated signal on Timer Port 1 using OC7 and OC1
/*
* Program to generate pulse width modulation
* on PT1
*/
#include "hc12.h"
#define DUTY_CYCLE 0x750
#define PERIOD 0x1000
#define TRUE 1
main()
{
/* Turn on timer subsystem */
TSCR = 0x80;
/* Set prescaler to 8 */
TMSK2 = 0x03;
/* Configure PT1 for OC; bring PT1 low, no int */
TIOS = TIOS | 0x02; /* TC1 set for output compare */
TCTL2 = (TCTL2 | 0x08) & ~0x04; /* OM1:OL1 = 10 */
/* Set up OC7 to bring PT1 high, enable int */
TIOS = TIOS | 0x80; /* TC7 set for output compare */
OC7M = OC7M | 0x02; /* OC7 controls OC1 */
OC7D = OC7D | 0x02; /* OC7 brings OC1 high */
TFLG1 = 0x80; /* Clear OC7 flag */
TMSK1 = TMSK1 | 0x80; /* Enable OC7 interrupt*/
enable(); /* Enable interrupts */
while (TRUE) ; /* Do nothing */
}
@interrupt void toc7_isr(void)
{
TC1 = TC7 + DUTY_CYCLE; /* Bring OC1 low after Duty Cycle */
TC7 = TC7 + PERIOD; /* Bring OC1 high after Period */
TFLG1 = 0x80; /* Clear OC7 flag */
}
vector.c file for above program
/* INTERRUPT VECTORS TABLE 68HC12
*/
void toc7_isr();
void (* const _vectab[])() = { /* 0x0B10 */
0, /* BDLC */
0, /* ATD */
0, /* reserved */
0, /* SCI0 */
0, /* SPI */
0, /* Pulse acc input */
0, /* Pulse acc overf */
0, /* Timer overf */
toc7_isr, /* Timer channel 7 */
0, /* Timer channel 6 */
0, /* Timer channel 5 */
0, /* Timer channel 4 */
0, /* Timer channel 3 */
0, /* Timer channel 2 */
0, /* Timer channel 1 */
0, /* Timer channel 0 */
0, /* Real time */
0, /* IRQ */
0, /* XIRQ */
0, /* SWI */
0, /* illegal */
0, /* cop fail */
0, /* cop clock fail */
(void *)0xff80, /* RESET */
};