NXP: understand FlexPWM API

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

NXP: understand FlexPWM API

986 Views
illy777
Contributor III

Hi,

 

I'm working with the imxrt117x and 'm trying to run a simple PWM on output PWM(A,2) with this code:

 

```

  pwm_config_t       pwmConfig;
  pwm_signal_param_t pwmSignal[1];
  uint32_t           pwmSourceClockHz = PWM_SRC_CLK_FREQ;
  uint32_t           pwmFreqHz        = 10000; // 10 kHz frequency

  // Default PWM configuration (init PWM for a submodule)
  PWM_GetDefaultConfig(&pwmConfig);

  // Adjust the configuration for our specific use case
  pwmConfig.enableDebugMode       = true;
  pwmConfig.reloadLogic           = kPWM_ReloadImmediate;
  pwmConfig.pairOperation         = kPWM_Independent;
  pwmConfig.enableDebugMode       = true;
  pwmConfig.clockSource           = kPWM_BusClock;
  pwmConfig.prescale              = kPWM_Prescale_Divide_4;
  pwmConfig.initializationControl = kPWM_Initialize_LocalSync;

  /* Initialize submodule 2 the same way as submodule 1 */
  if (PWM_Init(BOARD_PWM_BASEADDR, kPWM_Module_2, &pwmConfig) == kStatus_Fail)
  {
    PRINTF("PWM initialization failed\n");
    return 1;
  }

  // Configure the PWM signal for channel A and channel B
  pwmSignal[0].pwmChannel       = kPWM_PwmA;
  pwmSignal[0].level            = kPWM_HighTrue;
  pwmSignal[0].dutyCyclePercent = 50; // 50% duty cycle

  PWM_SetPwmLdok(BOARD_PWM_BASEADDR, kPWM_Control_Module_2, false);

  // Set up PWM signals
  PWM_SetupPwm(BOARD_PWM_BASEADDR, kPWM_Module_2, pwmSignal, 2,
               kPWM_SignedCenterAligned, pwmFreqHz, pwmSourceClockHz);

  // Load the configuration
  PWM_SetPwmLdok(BOARD_PWM_BASEADDR, kPWM_Control_Module_2, true);

  // Start the PWM
  PWM_StartTimer(BOARD_PWM_BASEADDR, kPWM_Control_Module_2);
 
```
 
Still I don't get why it's not working. 
 
I got also the pinmuxing: 
 
```
  IOMUXC_SetPinMux(
      IOMUXC_GPIO_AD_28_FLEXPWM2_PWM2_A,      /* GPIO_AD_28 is configured as FLEXPWM2_PWM2_A */
      0U);                                    /* Software Input On Field: Input Path is determined by functionality */
```
 
Is there anything else that I need to take into account?
 
 
Thx
Labels (1)
Tags (1)
0 Kudos
Reply
6 Replies

925 Views
illy777
Contributor III

Hi Edwin, thx for helping me out!

no I had PWM2 configured.. however I discovered that when I turned off the debug mode the PWM was then working. But still, I do not get the frequency value that I wish.. didn't figure out why yet...

 

Thx,

 

Isaac

0 Kudos
Reply

917 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @illy777,

Thanks for the clarification. what frequency are you expecting and what are you seeing? How are you measuring the results? 

 

0 Kudos
Reply

862 Views
illy777
Contributor III

Hi I was expecting to get the frequency I configured, I wanted to have 10kHz... For the exact value, if thisis important, i should make another test.

 

I was measuring thrugh an oscilloscope with 200kHz band width, what should be enough for the measurement. I was measuring against ground.

0 Kudos
Reply

855 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @illy777,

The function you should be debugging is "PWM_SetupPwm()", as this is where the PWM registers are set to a specific frequency and duty cycle. Are you seeing the correct values loaded here? Of not, what are the values you are seeing? Also, what is the source clock frequency you are using?

BR,
Edwin.

0 Kudos
Reply

845 Views
illy777
Contributor III
Hi @EdwinHz

When I measured again the problem seeme to be solved and I'm getting the 10kHz...

don't quite understand but it seems to be resolved! Thank you!
0 Kudos
Reply

936 Views
EdwinHz
NXP TechSupport
NXP TechSupport

Hi @illy777,

I believe the issue lies on the pin that you are initializing.

Your code sets up Module FLEXPWM2, Sub-Module 2, channel A.

EdwinHz_0-1714509608925.png

This, because you are using "BOARD_PWM_BASEADDR", which is defined as PWM1:

/* The PWM base address */
#define BOARD_PWM_BASEADDR PWM1

However, the pin you are using is for the FLEXPWM2 module, rather than FLEXPWM1. You can see its name makes reference to Module PWM2, Submodule 2, Channel A: "IOMUXC_GPIO_AD_28_FLEXPWM2_PWM2_A"

 

The pin you should set-up for the configuration you are using is GPIO_AD_04 (or GPIO_EMC_B1_27):

EdwinHz_1-1714510195258.png

BR,
Edwin.

 

 

0 Kudos
Reply