Raman B

Help needed. To generate PWM on a freescale microcontroller

Discussion created by Raman B on Oct 20, 2010
Latest reply on Oct 22, 2010 by bigmac

Hi all

Am using Freescale Micro controller MC9S08SH8. Iam trying to create a PWM using this controller. Though I have carefully set all the registers related to PWM, Am still unable to generate PWM on this.

The main task was to create a edge aligned PWM on all channels of each PWM.
also am using internal oscillator it has.

Can any one give me some example C Codes for the same or try correcting my code.

Tools am using: Codewarrior suite with P&E Programmer
Controller: MC9S08SH8 20pin

Any kind of help is greatly appreciated




My Code


#include <hidef.h> /* for EnableInterrupts macro */#include "derivative.h" /* include peripheral declarations */void main(void) {  EnableInterrupts; /* enable interrupts */     //TIMER1 CH0 n CH1          TPM1SC=0b01001000;     TPM1C0SC=0b00101000;  //Edge aligned pwm with high true pulses      TPM1C1SC=0b00101000;      TPM1MOD=400;     TPM1C0V=400;     TPM1C1V=400;          //TIMER2 CH0 n CH1        TPM2SC=0b01001000;     TPM2C1SC=0b00100100; //Edge aligned pwm with low true pulses      TPM2C0SC=0b00100100;     TPM2MOD=400;     TPM2C1V=400;     TPM2C0V=400;while(1){TPM1C0V=300;TPM1C1V=300;TPM2C1V=300;TPM2C0V=300;}   }