AnsweredAssumed Answered

MCF5329 PWM 16bits change duty cycle

Question asked by marcioaureliofurtadomontezuma on Dec 28, 2016
Latest reply on Jan 2, 2017 by marcioaureliofurtadomontezuma

Hi
I adapted the PWM program from M52233DEMO_PWM to M5329EVB.
Now I want to know how to update 16 bits duty cycle (PWMDTY0 and PWMDTY1 ) in one operation.

To avoid change duty cycle in wrong way.
Below is the adapted code. The code is working fine. I verified the period and duty cycle using an oscilloscope.

 

/*
* main implementation: use this sample to create your own application
*
*/
#include "support_common.h" /* include peripheral declarations and more */
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)
/* Standard IO is only possible if Console or UART support is enabled. */
#include <stdio.h>
#endif

/**
* \brief init_pin_assignments - Function for Pin Assignment and General Purpose I/O
* \author TIC Guadalajara adapted by Marcio A. F. Montezuma for M5329EVB
* \param void
* \return void
* \todo
* \warning
*/
static void init_pin_assignments (void)
{

/* Pin assignments for port PWM
Pin PWM1 : PWM output channel PWM1
*/
MCF_GPIO_PDDR_PWM = MCF_GPIO_PCLRR_PWM_PCLRR_PWM2;

/* 0xFC0A_401A (PDDR_PWM) - Bit 2 - PWM1
Bit 3 - PWM3
Bit 4 - PWM5
Bit 5 - PWM7
MCF5329 Ref. Manual pag. 13-17 and MCF5329_GPIO.h */

MCF_PAD_PAR_PWM = MCF_PAD_PAR_PWM_PAR_PWM1(3);

/* Define Pin PWM1 as PWM1 MBGA256 H16
0xFC0A_4051 (PAR_PWM) - Bits 0 e 1 - Value 0b11 - PWM1
MCF5329 Ref. Manual pag. 13-31 and MCF5329_PAD.h */

}

/**
* \brief init_pwm - Setup Pulse Width Modulation (PWM) Module
* \author TIC Guadalajara adapted by Marcio A. F. Montezuma for M5329EVB
* \param void
* \return void
* \todo
* \warning
*/
/*********************************************************************
* init_pwm - Pulse Width Modulation (PWM) Module *
**********************************************************************/
static void init_pwm (void)
{
/* Clock A frequency = 60.00 MHz, fsys = 180.00 MHz, bus clock = fsys/3
Clock B frequency = 60.00 MHz, fsys = 180.00 MHz, bus clock = fsys/3
PWM continues to run in freeze mode
PWM continues to run in wait mode

Settings for PWM Channel 1:
Clock source is Clock A
Left-Aligned output mode
Period = 60,000 clocks (0xEA60) (1 milisecond)
High for 6000 clocks (0x1770) per period (10.000% duty cycle)
*/
MCF_PWM_PWMPER0 = MCF_PWM_PWMPER_PERIOD(0xEA);
MCF_PWM_PWMPER1 = MCF_PWM_PWMPER_PERIOD(0x60);
MCF_PWM_PWMDTY0 = MCF_PWM_PWMDTY_DUTY(0x17);
MCF_PWM_PWMDTY1 = MCF_PWM_PWMDTY_DUTY(0x70);

 

MCF_PWM_PWMPOL = MCF_PWM_PWMPOL_PPOL1;

/*channel n output is high at the
beginning of the period, then goes
low when the duty count is reached*/

MCF_PWM_PWMCLK &= 0b11111101; // Define PWM1 Clock Source as Clock A.
MCF_PWM_PWMPRCLK = MCF_PWM_PWMPRCLK_PCKA(0); // Define Prescaler of Clock A as 1 - 0b000.
MCF_PWM_PWMCAE &= 0b11111101; // Define PWM1 as lef-aligned.
MCF_PWM_PWMCTL |= 0b00010000; // Concatenates PWM channels 0 and 1 to form one 16-bit PWM channel.
MCF_PWM_PWMSCLA = 0; // This hasn't effect because the choice of Clock A otherwise of Clock SA.
MCF_PWM_PWMSCLB = 0; // This hasn't effect because only affect PWM3 and PWM7.
/* Enable PWM channels*/
MCF_PWM_PWME = MCF_PWM_PWME_PWME1; // Enable PWM1 concatenated
MCF_PWM_PWMSDN = 0; // Disable Emergency shutdown
}

/**
* \brief main - Main Function
* \author TIC Guadalajara adapted by Marcio A. F. Montezuma for M5329EVB
* \param void
* \return No return.
* \todo
* \warning
*/
int main(void)
{
int counter = 0;

#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)
printf("Hello World in C from MCF5329 derivative on M5329EVBDEMO board\n\r");
//fflush(stdout);
#endif

/** Setup GPIO*/
init_pin_assignments();

/** Setup PWM*/
init_pwm();

for(;;) {
counter++;
}
}

Outcomes