(MPC5634, system frequency:64MHz)
void Pwm_Ini(uint8 Chn)
SIU.PCR[Chn + 179].B.PA = 1; /*Initialize PORT*/
SIU.PCR[Chn + 179].B.OBE = 1;
EMIOS.MCR.B.MDIS= 0; /*EMIOS module enter normal mode */
EMIOS.MCR.B.GPRE= 63; /* eMIOS clk= sysclk/(GPRE+1)= 64MHz/64= 1MHz */
EMIOS.MCR.B.ETB= 0; /*External time base is disabled */
EMIOS.MCR.B.GTBE= 1; /*Enable global time base */
EMIOS.MCR.B.GPREN= 1; /*Enable eMIOS clock */
EMIOS.CH[Chn].CCR.B.MODE= 0x19; /*Mode is OPWFM*/
EMIOS.CH[Chn].CCR.B.BSL= 0x3; /*All channels: internal counter */
EMIOS.CH[Chn].CCR.B.UCPREN= 1; /*Prescaler enabled */
EMIOS.CH[Chn].CCR.B.FEN= 0; /*Disable interupt */
EMIOS.CH[Chn].CCR.B.DMA= 0; /*FLAG assigned to Interrupt request */
EMIOS.CH[Chn].CCR.B.UCPRE= 0; /*Prescaler=0,Divide Ratio=1 */
EMIOS.CH[Chn].CCR.B.IF= 0; /*select the min input pulse width that can pass through the filter,0 means bypass */
EMIOS.CH[Chn].CCR.B.FCK= 0; /*Select clock source for the programmable input filter,0 means Prescaled clock */
EMIOS.CH[Chn].CCR.B.EDPOL= 0; /*Polarity-leading edge sets output/trailing clears */
void Pwm_Output(uint8 Chn,uint32 Period, uint32 DutyCycle)
EMIOS.CH[Chn].CBDR.R = Period; /* Set Period */
EMIOS.CH[Chn].CADR.R = DutyCycle; /* Set DutyCycle */
Pwm_Ini(0); /* initialize eMIOS */
Pwm_Ini(2); /* initialize eMIOS */
Pwm_Ini(4); /* initialize eMIOS */
Pwm_Output(0, 1000, 200); /* Frequency=1KHz, DutyCycle=20% */
Pwm_Output(2, 500, 200); /* Frequency=2KHz, DutyCycle=40% */
Pwm_Output(4, 2000, 200); /* Frequency=500Hz, DutyCycle=10% */
why my OPWFM demo can't output PWM waveform for MPC5634???
eMIOS, eMIOS, eMIOS channels have not the output of the PWM waveform.
I want to output PWM waveform that its cycle and duty cycle are variable.
anybody know how to solve the problem??
There is no OPWFM mode supported on this MCU. Just OPWFMB mode can be used on some eMIOS channels (big channels).
See Table 209. Channel descriptions of the device Reference manual to know which modes are available on each channels.
From your selected channels just channel 0 supports OPWFMB mode, but you need to set the MODE = 0x58 as per Table 221.
Can you please help me with the min and max frequency/frequency range in which eMIOS can work for MPC5674F?
I have a 40 MHz crystal.
yes,you are right, MODE=0x58 can oupt pwm wave, but only Channel-0, 8, 9, 10, 12, 14, 15, 23 support OPWFMB mode.
I want to use the channel as much as possible to output pwm wave that its period and duty cycle is variable.
So, I select to set MODE=0x19. (datasheet 188.8.131.52.13 Output Pulse Width and Frequency Modulation (OPWFM) Mode)
What do I need to do to achieve it ?
what I should to do?
As I wrote and Table 209 states there is no OPWFM mode supported, so if you select it the channel will not work.
The chapter 184.108.40.206 describes all possible modes of eMIOS module, but only few of modes are implemented on the MPC5634M’s eMIOS module, as per Table 209 states.
Thus you can only generate variable period and duty cycle PWM on Big channels (0, 8, 9, 10, 12, 14, 15, 23).
The medium channels offers OPWMB mode, but this mode uses external counter bus , so the period is given by that selected external counter bus.
BTW: you can also use the eTPU module for PWM signal generating.