Erik Lee

Strange PWM results

Discussion created by Erik Lee on Dec 4, 2007
Latest reply on Dec 7, 2007 by Erik Lee
I am working with a freescale MC9S12DT256 and attempting to get a pwm signal.  As a first approach processor expert was used and successfully produced a pwm signal.  Since this is for educational purposes the goal is define all memory locations manually.  The code below will sometimes produce a pwm signal and other times not.  I should also note that it compiles.  I have tested it on multiple processors and get the same result.  To ensure that it is correctly wired to the scope I have tested the code generated with processor expert and it works.  At this point I am stuck and not sure where my problem is.  Any help would be greatly appreciated. 

#include <hidef.h>      /* common defines and macros */
#include <mc9s12dt256.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12dt256b"

#define EPWMCNT (*((volatile unsigned int*) (0x000000AC)))
#define EPWMPER (*((volatile unsigned int*) (0x000000B4)))
#define EPWMDTY (*((volatile unsigned int*) (0x000000BC)))
#define EPWMPRCLKE (*((volatile unsigned int*) (0x000000A3)))
#define EPWMSCLAE (*((volatile unsigned long*) (0x000000A8)))
#define EPWMCLK_PCLK0E (*((volatile unsigned int*) (0x000000A2)))
#define EPWME_PWME0E (*((volatile unsigned int*) (0x000000A0)))
#define one (1<<0)

void pwmpercentage2(int percent){
     if (percent > 100) {
          percent = 100;
     if (percent < 0) {
          percent = 0;

volatile static byte pwmChannel[1];
void main(void) {

EPWMPER=255; //sets the period
EPWMDTY = 25;//initialize duty cycle.
EPWMPRCLKE = 3; //set prescaler register
EPWMSCLAE = 187; //set scale register
EPWMCLK_PCLK0E = one; //select clock source
EPWME_PWME0E = one;  //run counter
  /* put your own code here */
  pwmChannel[0]= PTP_PTP0;