Phase Shifted PWMs in IMX RT 1020

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

Phase Shifted PWMs in IMX RT 1020

1,313 Views
narenchandra401
Contributor III

Hi Community , 

We are using EVk -MIMXRT 1020 for our application development , We have a requirement to switch 5 mosfets .

I have understood the Reference manual and have generated 5 PWMs 

5 PWMs with 50 percent duty cycle and 100KHz frequency .

The requirement is these 5 PWM signals must be phase shifted . 

In the reference manual there is no detailed description on how to configure the PWMs so that they can be phase shifted .

Is there any code that is existing , that explains the phase shifted pwms for imxrt 1020 ?

Is there any register in the IMXRT 1020 , with which we can configure phase shift ?

Below is a code that has configuration of 5 PWMs

 

Pin NumberPad NumberSignal Name
93GPIO_AD_BO_15PWM2 - B0
94GPIO_AD_BO_14PWM2 - A0
95GPIO_AD_BO_13PWM2 - B1
96GPIO_AD_BO_12PWM2 - A1
98GPIO_AD_BO_10PWM2 - A2

int main(void)
{
    BOARD_ConfigMPU();
    BOARD_InitPins();
    BOARD_BootClockRUN();
    PWM_Initialisation(PWM2);
    PWM_DRV_Init(PWM2);
    PWM_SetPwmLdok(PWM2, kPWM_Control_Module_0 | kPWM_Control_Module_1 |kPWM_Control_Module_2,      true);
   PWM_StartTimer(PWM2,  kPWM_Control_Module_0 | kPWM_Control_Module_1 |kPWM_Control_Module_2 );
   while (1)
   {

    }
}
void PWM_Initialisation(PWM_Type *base)
{
    pwm_config_t pwmConfig;
    CLOCK_SetDiv(kCLOCK_AhbDiv, 0x2); /* Set AHB PODF to 2, divide by 3 */
    CLOCK_SetDiv(kCLOCK_IpgDiv, 0x3); /* Set IPG PODF to 3, divede by 4 */
    XBARA_Init(XBARA);
    XBARA_SetSignalsConnection(XBARA, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault0);
    XBARA_SetSignalsConnection(XBARA, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault1);
    XBARA_SetSignalsConnection(XBARA, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm12Fault2);
    XBARA_SetSignalsConnection(XBARA, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm12Fault3);
   
    PWM_GetDefaultConfig(&pwmConfig);
    pwmConfig.reloadLogic = kPWM_ReloadPwmFullCycle;
    if (PWM_Init(base, kPWM_Module_0, &pwmConfig) == kStatus_Fail)
    {
        PRINTF("PWM initialization failed\n");
    }
    pwmConfig.clockSource           = kPWM_Submodule0Clock;
    pwmConfig.initializationControl = kPWM_Initialize_MasterSync;
  if (PWM_Init(base, kPWM_Module_0, &pwmConfig) == kStatus_Fail)
    {
        PRINTF("PWM initialization failed\n");
    }
    if (PWM_Init(base, kPWM_Module_1, &pwmConfig) == kStatus_Fail)
    {
        PRINTF("PWM initialization failed\n");
    }
    if (PWM_Init(base, kPWM_Module_2, &pwmConfig) == kStatus_Fail)
    {
        PRINTF("PWM initialization failed\n");
    }
}
static void PWM_DRV_Init3PhPwm(PWM_Type *base)
{
    uint16_t deadTimeVal;
    pwm_signal_param_t pwmSignal[2];
    uint32_t pwmSourceClockInHz;
    uint32_t pwmFrequencyInHz = 100000;
 
   pwmSourceClockInHz = CLOCK_GetFreq(kCLOCK_IpgClk);
    /* Set deadtime count, we set this to about 650ns */
    deadTimeVal = ((uint64_t)pwmSourceClockInHz * 650) / 1000000000;
    pwmSignal[0].pwmChannel       = kPWM_PwmA;
    pwmSignal[0].level            = kPWM_HighTrue;
    pwmSignal[0].dutyCyclePercent = 50; /* 1 percent dutycycle */
    pwmSignal[0].deadtimeValue    = deadTimeVal;
    pwmSignal[1].pwmChannel = kPWM_PwmB;
    pwmSignal[1].level      = kPWM_HighTrue;
    /* Dutycycle field of PWM B does not matter as we are running in PWM A complementary mode */
    pwmSignal[1].dutyCyclePercent = 50;
    pwmSignal[1].deadtimeValue    = deadTimeVal;
    PWM_SetupPwm(base, kPWM_Module_0, pwmSignal, 2, kPWM_SignedCenterAligned,    pwmFrequencyInHz,pwmSourceClockInHz);
    PWM_SetupPwm(base, kPWM_Module_1, pwmSignal, 2, kPWM_SignedCenterAligned, pwmFrequencyInHz,pwmSourceClockInHz);
    PWM_SetupPwm(base, kPWM_Module_2, pwmSignal, 1, kPWM_SignedCenterAligned, pwmFrequencyInHz,pwmSourceClockInHz);
}
With the above code i am able to generate 5 pwm signals PWM2( A0,B0,A1,B1,A2) with 100Khz frequency and 50% duty cycle . 
But i need to configure these 5 PWMs with a phase shift of 72 degrees between them , How do it do it ? 
The reference manual says 
"If numerical biases are applied to the turn on and turn off edges of different PWM signal, the signals will be phase shifted with respect to each other"
What does Numerical Biases mean ?
Capture.PNG
Please guide me with the procedure for phase shifting .
Anticipating a faster response .
Thanks and regards ,
Naren Chandra
0 Kudos
Reply
1 Reply

1,184 Views
victorjimenez
NXP TechSupport
NXP TechSupport

Hello Naren, 

Regarding your questions please see my comments below. 

Is there any code that is existing , that explains the phase shifted pwms for imxrt 1020 ?

Unfortunately, we don't have any example code for this.

Is there any register in the IMXRT 1020 , with which we can configure phase shift ?

No, there isn't any register on the eFlexPWM module that you can configure to achieve this. 

But i need to configure these 5 PWMs with a phase shift of 72 degrees between them , How do it do it ? 

I found the following community document where one of my co-workers explains how to achieve this for an LPC. Although the module that he's using it's from the LPC family the same concepts apply for the RT eFlexPWM module. Generating phase-shift PWM signal with SCTimer/PWM module 

Regards, 

Victor 

0 Kudos
Reply