getting a PWM going on ColdFire

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

getting a PWM going on ColdFire

4,318 Views
airswit
Contributor III
hi all,

I am trying to get my PWM to work on my eval board for the CF5213. I have entered the code below, and called it from the main function. I want a really long period (about 3 seconds), which is why I am using a 16 bit channel. I have the output (PWM1) hooked up to an LED through a transistor. When i reset the board, and start sending the code, the led is lit (meaning it is a GPIO, i guess). Once the code starts running, the LED turns off...and stays off. any suggestions?

code:

void pwm_setup(void)
{
// MCF_GPIO_DDRTD = MCF_GPIO_DDRTD_DDRTD0 | MCF_GPIO_DDRTD_DDRTD1; //set data direction register
MCF_GPIO_PTDPAR = 0
| MCF_GPIO_PTDPAR_PTDPAR0
| MCF_GPIO_PTDPAR_PTDPAR1
| MCF_GPIO_PTDPAR_PTDPAR2
| MCF_GPIO_PTDPAR_PTDPAR3; //set for primary function

MCF_PWM_PWMCLK = 0 | MCF_PWM_PWMCLK_PCLK1; //set scaled clock input
MCF_PWM_PWMPRCLK = MCF_PWM_PWMPRCLK_PCKA(7); //set prescale to 2^7
MCF_PWM_PWMCTL = 0 | MCF_PWM_PWMCTL_CON01; //make PWM1 16 bits wide
MCF_PWM_PWMSCLA = MCF_PWM_PWMSCLA_SCALEA(0x7); //divide prescale by 256
MCF_PWM_PWMPER0 = MCF_PWM_PWMPER(0x0E); //high order period divider
MCF_PWM_PWMPER1 = MCF_PWM_PWMPER(0x4E); //low order period divider
MCF_PWM_PWMDTY0 = MCF_PWM_PWMDTY(0x07); //high order duty cycle
MCF_PWM_PWMDTY1 = MCF_PWM_PWMDTY(0x27); //low order duty cycle
MCF_PWM_PWME = 0
| MCF_PWM_PWME_PWME1; //enable PWM channel 1 & 0
}


Thanks in advance!


p.s. the PWM seems to be set up correctly, because if I change the polarity of the PWM1 channel, the led is opposite (on). it seems as though it is just not starting to count.

Message Edited by airswit on 03-25-200607:17 PM

Labels (1)
0 Kudos
1 Reply

996 Views
airswit
Contributor III
well, i finally got it working. the problem was mainly the header had the wrong address for the period and duty cycle registers!!!! also, i aws misusing the dty() and per() macros (they do not do what i thought they did), so i just used the hex values for the assignment, and it works fine!
0 Kudos