MCUXpresso v11.1.1 Build 3241
I am configuring the PWMA/eFlexPWM module using the Config tool for two submodules, both using a complementary A/B PWM output, unsigned center-aligned with a frequency of 1 KHz. Since 1 KHz is too slow for the 84 MHz source clock with no prescaler, I have set my prescaler to 2. This results in an input clock of 42 MHz as shown in the image below.
The config tool generates the following definition for frequency:
The definition of PWMA_SM0_COUNTER_CLK_SOURCE_FREQ_HZ should be 84000000U instead of 42000000U. The config tool is taking into account the prescaler value when setting this definition.
The problem with this is that 42000000U is passed to the PWM_SetupPwm() function in peripherals.c. Inside that function, the prescaler (2) is factored in resulting in an incorrect value for pwmClock (see below). In the code below (found in PWM_SetupPwm(), srcClock_Hz is being passed a value of 42000000U and then being divided by the prescaler value (2). This results in a value for pwmClock being 21000000U which then gets used in calculating the pulseCnt value. However, the actual PWM clock is actually running at 42000000 Hz due to the prescaler of 2. The final result of all of this is a PWM frequency that is double what I am requesting, in this case 2 KHz.
I am thinking that when Config Tools generates the PWMA_SM0_COUNTER_CLK_SOURCE_FREQ_HZ value, it should use the value of the clock source before the prescaler value.
In the SubModule 1 configuration, I am using the AUX clock (from submodule 0) as the clock source. Since the SubModule 0 clock was actually configured for 42 MHz (with the prescaler set to 2), the Config Tool is getting the source clock frequency correct as seen in the image below AND in the #define for PWMA_SM1_COUNTER_CLK_SOURCE_FREQ_HZ
In this case, I leave prescaler set to 1 for SubModule1 so it runs at the same frequency as SubModule 0.
The only work around at the moment is to go back in and manually change the value of the #define for PWMA_SM0_COUNTER_CLK_SOURCE_FREQ_HZ to 84000000U. I cannot trick the tool by changing the prescaler since I need the SM0 prescaler set to 2 so it populates the PWMA registers correctly.
Yes, I agree with you. This seems like a bug. The PWM_SetupPwm's parameter srcClock_Hz should be the clock that input to submodules prescaler. I'll report it to software team. Thanks a lot.