kw36 4MHz PWM

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

kw36 4MHz PWM

2,242件の閲覧回数
jictannu
Contributor III

I am trying to output 4MHz and 50% dutycycle on KW36. I run the demo frdmkw36_driver_examples_tpm_simple_pwm and I make some modifications:

int main(void)
{
 tpm_config_t tpmInfo;
 tpm_chnl_pwm_signal_param_t tpmParam;
#ifndef TPM_LED_ON_LEVEL
 #define TPM_LED_ON_LEVEL kTPM_LowTrue
#endif

 /* Configure tpm params with frequency 24kHZ */
 tpmParam.chnlNumber = (tpm_chnl_t)BOARD_TPM_CHANNEL;
 tpmParam.level = TPM_LED_ON_LEVEL;
 tpmParam.dutyCyclePercent = 50;
/* Board pin, clock, debug console init */
 BOARD_InitPins();
 BOARD_BootClockRUN();
 BOARD_InitDebugConsole();
/* Select the clock source for the TPM counter as MCGFLLCLK */
 CLOCK_SetTpmClock(1U);
/* Print a note to terminal */
 PRINTF("\r\nTPM example to output center-aligned PWM signal\r\n");
 PRINTF("\r\nIf an LED is connected to the TPM pin, you will see a change in LED brightness if you enter different values");
 PRINTF("\r\nIf no LED is connected to the TPM pin, then probe the signal using an oscilloscope");
TPM_GetDefaultConfig(&tpmInfo);
 /* Initialize TPM module */
 TPM_Init(BOARD_TPM_BASEADDR, &tpmInfo);
TPM_SetupPwm(BOARD_TPM_BASEADDR, &tpmParam, 1U, kTPM_CenterAlignedPwm, 4000000U, TPM_SOURCE_CLOCK);
TPM_StartTimer(BOARD_TPM_BASEADDR, kTPM_SystemClock);
while (1)
 {
}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

but I get this:

ZDS2000-2019-10-21-16-03-55.bmp

This is not 50% dutycycle. How could I get 50% dutycycle pwm?

ラベル(1)
タグ(1)
0 件の賞賛
返信
5 返答(返信)

1,884件の閲覧回数
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Mo Xinyu, I hope you're doing well!

 

Unfortunately, it's not recommended to generate PWM signals of high frequencies such as 4MHz, as they tend to get really deformed because of the physical capabilities of the board, and they don't tend to work as well as a lower frequency PWM signal.

 pastedImage_1.png

I'm sorry for the inconveniences this may cause.

 

Please let me know if you need any more information.

 

Best regards,

Sebastian

0 件の賞賛
返信

1,884件の閲覧回数
jictannu
Contributor III

Hi, Sebastian. I find this in MKW36A/35A Data Sheet:

企业微信截图_15717930158763.png

But in fact the rise and fall time is almost 80ns. Maybe I need a pull-up or pull-down?

企业微信截图_15717935359249.png

Maybe the capacitance have an effect?

0 件の賞賛
返信

1,884件の閲覧回数
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Mo Xinyu,

 

Unfortunately, TPM generated PWM signals tend to get deformed at high frequencies. An alternative you could try is to instead manually toggle the pin by using the timer's interrupt, instead of using the PWM generation functions. Maybe that way you can generate a better signal.

 

Please do note that you may still get of waveform deformation.

 

Best regards,

Sebastian

0 件の賞賛
返信

1,884件の閲覧回数
jictannu
Contributor III

Hi Sebastian,

Now the clock frequency is 40MHz, is it too low? I try to change the clock frequency but it runs into hardfualt. This is my code:

企业微信截图_1571887344743.png

0 件の賞賛
返信

1,884件の閲覧回数
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi Mo Xinyu,

 

The KW36Z can run at a maximum frequency of 48MHz, so setting the system clock to a multiplier resulting in a higher frequency than that would result in a hard fault.

 

You can try to set the maximum frequency by using the clocks tool included in the MCUXpresso Config Tools.

 

Still, even after changing the frequency value, the PWM signal may still look distorted.

 

If you would like to read more about the MCUXpresso Config Tools, please take a look at the user guide, here.

 

Best regards,

Sebastian

0 件の賞賛
返信