s32k144 pwm issue

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

s32k144 pwm issue

3,035 次查看
alice_th
Contributor III

Hello,

when use FTM PWM, i find when use uart to printf the log, the PWM doesn't work,

but when remove printf, then the pwm output the correct waveform.

could you help to check it what is the reason ? 

i attached the project, please test it.

void test_pwm()
{
    //pwm_init();
    uint16_t duty_cycle[] = {0,0x2000,0x4000,0x6000,0x8000};
    uint8_t len = sizeof(duty_cycle)/sizeof(uint16_t);
    status_t st = STATUS_SUCCESS;
    while(1)
    {
        for(uint8_t i = 0;i<len;i++)
        {

            //set_pwm_duty_cycle(0,duty_cycle[i]);
            st = FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM_1,
                                                 flexTimer_pwm_1_IndependentChannelsConfig[0].hwChannelId,
                                                 FTM_PWM_UPDATE_IN_DUTY_CYCLE, duty_cycle[i],
                                                 0U,
                                                 true);
            printf("duty_cycle=0x%x,pwm status=0x%x\n\r",duty_cycle[i],st);
            OSIF_TimeDelay(100);
            //OSIF_TimeDelay(10000);
        }

    }
}
see the log, when add these printf, pwm status return 1 = STATUS_ERROR

duty_cycle=0x0,pwm status=0x1
duty_cycle=0x2000,pwm status=0x1
duty_cycle=0x4000,pwm status=0x1
duty_cycle=0x6000,pwm status=0x1
duty_cycle=0x8000,pwm status=0x1

标记 (1)
0 项奖励
回复
14 回复数

2,907 次查看
alice_th
Contributor III

here is the new project, please help to check it, thank you! @danielmartynek 

0 项奖励
回复

2,990 次查看
alice_th
Contributor III

can anybody who help test and answer this question, thank you very much! 

0 项奖励
回复

2,975 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi Alice,

There is something wrong with the console lib, but we don't have the capacity to debug this SW.

Why don't you use the LPUART SDK driver directly?

The printf() uses LPUART_1 anyway.

 

Regards,

Daniel

 

0 项奖励
回复

2,938 次查看
alice_th
Contributor III

do you have examples about printf ?

if use directly LPUART SDK driver, there some transfer when need print different variable

0 项奖励
回复

2,933 次查看
alice_th
Contributor III

@danielmartynek i try it with this

 

void uart_printf(const char *ptr)
{
uint32_t bytesRemain;
size_t bytes=strlen(ptr);
// unsigned char ret_car[]={"\r"};
LPUART_DRV_SendData(INST_LPUART_1, (uint8_t *)ptr, bytes);
while(LPUART_DRV_GetTransmitStatus(INST_LPUART_1, &bytesRemain) != STATUS_SUCCESS);
// LPUART_DRV_SendData(INST_LPUART1, ret_car, 1);
// while(LPUART_DRV_GetTransmitStatus(INST_LPUART1, &bytesRemain) != STATUS_SUCCESS);
}

void test_pwm()
{
//pwm_init();
uint16_t duty_cycle[] = {0,0x2000,0x4000,0x6000,0x8000};
uint8_t len = sizeof(duty_cycle)/sizeof(uint16_t);
status_t st = STATUS_SUCCESS;
while(1)
{
for(uint8_t i = 0;i<len;i++)
{
 
//set_pwm_duty_cycle(0,duty_cycle[i]);
st = FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM_1,
                                     flexTimer_pwm_1_IndependentChannelsConfig[0].hwChannelId,
FTM_PWM_UPDATE_IN_DUTY_CYCLE, duty_cycle[i],
                                     0U,
                                     true);
uart_printf("test_pwm\n\r");
OSIF_TimeDelay(100);
//OSIF_TimeDelay(10000);
}
 
}
}
still the same, there is no pwm output when use uart_printf, could you help to check, how to implement the printf funciton , thank you very much!

 

0 项奖励
回复

2,919 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @alice_th,

Can you send the new project?

 

Thank you

0 项奖励
回复

2,829 次查看
alice_th
Contributor III

@danielmartynek any feedback , thanks!

0 项奖励
回复

2,792 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @alice_th,

Sorry for the delay, I could not get to the testing because of the overload.

Can you declare ftm_state_t ftmStateStruct as a global variable?

0 项奖励
回复

2,732 次查看
alice_th
Contributor III

after set ftm_state_t ftmStateStruct as a global variable, now it works even with printf(the console lib) it still can work, why need set as a global variable ?

0 项奖励
回复

2,725 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @alice_th,

I'm glad it works now.

Because you are calling the APIs of the driver from different functions that must access the struct.

 

 

 

 

0 项奖励
回复

2,712 次查看
alice_th
Contributor III

hello @danielmartynek 

when i set with dead time, ch1 don't have waveform output, could you help to check it 

 

alice_thanks_0-1728530394416.png

alice_thanks_1-1728530478492.png

look at ch1 with green line, no pwm output

alice_thanks_2-1728530685331.pngalice_thanks_3-1728530714604.png

 

0 项奖励
回复

2,689 次查看
danielmartynek
NXP TechSupport
NXP TechSupport

Hello @alice_th,

This is not related to the topic of this thread.

Please create a new one.

 

Thank you

0 项奖励
回复

2,710 次查看
alice_th
Contributor III

here is attached

0 项奖励
回复

2,879 次查看
alice_th
Contributor III

here is the project @danielmartynek 

0 项奖励
回复