How to use MPC5604B to generate PWM signal

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

How to use MPC5604B to generate PWM signal

693 Views
jeffcharles
Contributor III

Hi,

I select the ch0 to generate PWM signal, PWM period = 100us, PWM duty cycle = 10%, the following code is configuration:

void emios_0_init(void)

{

    EMIOS_0.MCR.R = 0x10003f00;                    /* Enable global prescaler, divider ratio = 64, clock = fsys / 64 = 1MHz */

    EMIOS_0.CH[0].CADR.R = 0;    
    EMIOS_0.CH[0].CBDR.R = 10;    
    EMIOS_0.CH[0].CCR.R = 0x20206e0;            /* Select internal counter */
    EMIOS_0.CH[0].CSR.R = 0x80008001;
    EMIOS_0.MCR.B.GPREN = 1;                    /* Start eMIOS */

}

void intc_init(void)

{

    EXCEP_InitExceptionHandlers();
    INTC_InitINTCInterrupts();

    INTC_InstallINTCInterruptHandler(emios_ch1_isr, 141, 2);    /* eMIOS channel 1 priority: 2 */

    INTC.CPR.R = 0x0;

}

void emios_ch1_isr(void)
{
    if (EMIOS_0.CH[0].CSR.B.FLAG == 1)
    {
        EMIOS_0.CH[0].CADR.R += 100;
        EMIOS_0.CH[0].CBDR.R += 100;
        EMIOS_0.CH[0].CSR.B.FLAG = 1;
    }

}

But the wave is wrong, the positive pulse width is 10us and the negative pulse width is 65ms. It seems that EMIOS_0.CH[0].CADR.R and EMIOS_0.CH[0].CBDR.R can't be updated. Is anything wrong with my configuration?

Please guide me to solve it, thanks!

Labels (1)
Tags (2)
2 Replies

450 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

in OPWMB mode, you selected, an external counter driven in MCB Up mode must be selected from one of the
counter buses. So add another channel for MCB up mode if you want to use OPWMB.

Or select OPWFMB for channel 0 and use it accordingly.

BR, Petr

450 Views
jeffcharles
Contributor III

Hi Petr,

I select OPWFMB mode, it can run normally.

Many thanks!

0 Kudos