//Example 17-14 for TWR-HCS12G128 Tower module using CodeWarrior //Modified by Mazidi from Example 17-14 of Mazidi & Causey HCS12 textbook //Tested by Brandon Collison //Using Scope, observe the PWM signal generated on PP2 pin //PP2 is available on pin 18 (PP2) of J3 of Axiom Peripheral board //See page 9 of TWR Axiom Peripheral board User Guide //http://www.axman.com/sites/default/files/TWR-DEV-PERIPH_UG.pdf //Use F7 to Make, F5 (Debug) to download, and F5 (Start) to run the program //In CodeWarrior,make sure you are in Open Source BDM when downloading and running. #include /* common defines and macros */ #include "derivative.h" /* derivative-specific definitions */ void main(void) { /* put your own code here */ PWMPRCLK=0x30; //ClockSB=Fbus/8=6.25MHz/8 = 781250Hz PWMSCLB=50; //ClockSB/2x50=781225Hz/100=7812Hz PWMCLK=0x04; //Use ClockSB for chan 2 PWMPOL=0x04; //high, then low for polarity PWMCAE=0; //left aligned PWMCTL=0; //8-bit chan,PWM during freeze and wait PWMPER2=100; //PWMFreq=ClockSB/100=7812Hz/100=78Hz PWMDTY2=40; //40% duty cycle. Change this and view the scope PWMCNT2=0; //clear PWMCNT2 PWME=0x04; //turn on (start) PWM2 while(1); //stay here. }