Hello,
I am using iMXRT1064 device and wanted to configure PWM on GPIO_SD_B0_00 pin.
I configured GPIO_SD_B0_00 to use using MCU config tools as below,
routed: J4
Peripheral: PWM1
Signal: A,0
Routeto : GPIO_SD_B0_00
but how to configure the PWM properties such as frequency, duty cycle in code.
I referred the demo code evkmimxrt1064_pwm but not able to figure out what parameters to use for above pin.
I configured the parameters in code such as
PWM_GetDefaultConfig(&pwmConfig);
/* Use full cycle reload */
pwmConfig.reloadLogic = kPWM_ReloadPwmFullCycle;
/* PWM A & PWM B form a complementary PWM pair */
pwmConfig.pairOperation = kPWM_Independent;
pwmConfig.enableDebugMode = true;
/* Initialize submodule 0 */
if (PWM_Init(BOARD_PWM_BASEADDR, kPWM_Module_0, &pwmConfig) == kStatus_Fail)
{
PRINTF("PWM initialization failed\n");
return 1;
}
Then,
pwmSignal[0].pwmChannel = kPWM_PwmA;
pwmSignal[0].level = kPWM_HighTrue;
pwmSignal[0].dutyCyclePercent = 50; /* 1 percent dutycycle */
pwmSignal[0].deadtimeValue = deadTimeVal;
PWM_SetupPwm(BOARD_PWM_BASEADDR, kPWM_Module_0, pwmSignal, 1, kPWM_SignedCenterAligned, pwmFrequencyInHz,
pwmSourceClockInHz);
/* Set the load okay bit for all submodules to load registers from their buffer */
PWM_SetPwmLdok(BOARD_PWM_BASEADDR, kPWM_Control_Module_0, true);
/* Start the PWM generation from Submodules 0 */
PWM_StartTimer(BOARD_PWM_BASEADDR, kPWM_Control_Module_0);
But do not see any output. My pwm signal is connected to LCD display.
I want to generate any frequency with 50% duty cycle on the pin GPIO_SD_B0_00.
Can you please help me out regarding this?
Thanks
Regards,
Anuj
Hello Anuj,
GPIO_SD_B0_00 pin is already configured in the SDK example. Please make sure you weld a 0 ohm resistor at R279, R280 and R281. Otherwise you won't be able to see PWM output through J24 header.
Hope it helps!
Best regards,
Felipe
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hello felipegsoto
I am not using the EVK board but a prototype board.
I now am configuring GPIO_SD_B0_01 for PWM through the MCU config tools. A buzzer is attached to this pin.
Please see the configuration options attached
I also am getting some warnings related to PWM configuration. snapshot below,
I want to generate a PWM with period 360 usec on GPIO_SD_B0_01. The buzzer does not sound when i load the program with these settings.
is my configuration correct?
Thanks
Regards,
Anuj
Hello Anuj,
Those warnings are generated because PWM fault inputs are not set inside BOARD_InitPins function so Config Tool cannot recognize they were already initialized.
PWM example from SDK handle this as follows. I highly recommend to refer to our SDK example where GPIO_SD_B0_01 is used.
/* Set the PWM Fault inputs to a low value */
XBARA_Init(XBARA1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault0);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault2);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault3);
I hope this helps you.
Best regards,
Felipe
Hello felipegsoto
Thanks for the reply.
I have shared the other PWM configurations in above discussions. Is the PWM configuration done correct?
I have configured the demo pwm example as per my requirements for using pin GPIO_SD_B0_01
so channel is B and sub module 0
Initialisation
/* Set the PWM Fault inputs to a low value */
XBARA_Init(XBARA1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault0);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault2);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault3);
PWM_GetDefaultConfig(&pwmConfig);
/* Use full cycle reload */
pwmConfig.reloadLogic = kPWM_ReloadPwmFullCycle;
pwmConfig.pairOperation = kPWM_Independent;
pwmConfig.enableDebugMode = true;
/* Initialize submodule 0 */
if (PWM_Init(BOARD_PWM_BASEADDR, kPWM_Module_0, &pwmConfig) == kStatus_Fail)
{
PRINTF("PWM initialization failed\n");
return 1;
}
call to PWM_DRV_Init3PhPwm{
uint16_t deadTimeVal;
pwm_signal_param_t pwmSignal[2];
uint32_t pwmSourceClockInHz;
uint32_t pwmFrequencyInHz = 2702702; // freq 2.7kHz required for buzzer.
pwmSourceClockInHz = PWM_SRC_CLK_FREQ;
/* Set deadtime count, we set this to about 650ns */
deadTimeVal = ((uint64_t)pwmSourceClockInHz * 650) / 1000000000;
pwmSignal[0].pwmChannel = kPWM_PwmB;
pwmSignal[0].level = kPWM_HighTrue;
pwmSignal[0].dutyCyclePercent = 50; /* 1 percent dutycycle */
pwmSignal[0].deadtimeValue = deadTimeVal ;
PWM_SetupPwm(BOARD_PWM_BASEADDR, kPWM_Module_0, pwmSignal, 1, kPWM_SignedCenterAligned, pwmFrequencyInHz,
pwmSourceClockInHz);
}
/* Set the load okay bit for all submodules to load registers from their buffer */
PWM_SetPwmLdok(BOARD_PWM_BASEADDR, kPWM_Control_Module_0 , true);
/* Start the PWM generation from Submodules 0, 1 and 2 */
PWM_StartTimer(BOARD_PWM_BASEADDR, kPWM_Control_Module_0 );
Not sure why the buzzer is not working.
Can you please confirm whether my initialization is correct?
Regards,
Anuj
Hello felipegsoto
I was able to run the PWM example code successfully for my LCD backlight and it is working on my prototype board using
GPIO_SD_B0_00 - PWM1 channel A sub module 0.
I just wanted to run the same code on iMXRT1064 EVK board. On EVK board pin GPIO_B1_15 is used. I configured it to use PWM4 - A,3
signal. Replaced the above code with PWM4 and channel A sub module 3 parameters. As per EVK datasheet a frequency of 100 Hz to 100kHz can be applied as PWM so kept freq as 50 kHz.
for pin GPIO_SD_B0_00 PWM1 channel A sub module 0 i have configured as per your suggestion below and it is working.
XBARA_Init(XBARA1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault0);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1Fault1);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault2);
XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault3);
for pin GPIO_B1_15 which is PWM4 channel 4 submodule 3 how do i modify the above code.
What is the relation between PWM number , channel , sub module and XBARA or XBARB
Can you please help me out regarding this?
Thanks
Regards,
Anuj
Hello Anuj,
For GPIO_B1_15 you will need to configure PWM 4, channel A and submodule 3. The relation between the things you mentioned is the following:
PWM 4: This is the module number itself.
Channel A: The channel is the output of the PWM module, in this case you have two options, channel A and channel B.
Submodule 3: Each submodule is set up to control a single half-bridge power stage and has its own timer so it can run at a different frequency.
Regarding XBAR, the intended application of the Inter-Peripheral Crossbar Switch (XBAR) module is to provide a flexible crossbar switch function that allows any input (typically from external GPIO or internal module outputs) to be connected to any output (typically to external GPIO or internal module inputs) under user control. This is used to allow user configuration of data paths between internal modules and between internal modules and GPIO.
I hope this information is helpful.
Best regards,
Felipe
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------
Hello felipegsoto,
Thanks for your reply.
How to i configure the XBARA for GPIO_SD_B0_01 (PWM) and GPIO_B1_15 (PWM).
For ex. if i am configuring the GPIO_SD_B0_01. How do i determine the XBARA initialization for this pin.
Thanks
Regards,
Anuj
Hi Anuj,
You can see this in Table 3-7. of Reference Manual.
Best regards,
Felipe
Exactly what I needed! You just saved me several hours. Thanks!