Setting up PWM

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

Setting up PWM

1,918 Views
Ming
Contributor III

I am using S32K148EVB to do some R&D work, having trouble get PWM going. Here is a sample code snippet listed at the bottom of this post, as you can tell I am using ftm_pwm component APIs provided by the SDK. When running debug mode, an exception occurs which resets the cpu. See attached screen capture. Returning from FTM_DRV_UpdatePwmChannel() led to the exception (inaccessible addressing?). Looking at the trace, I decided to double the stack size in ld file but the same problem persists. Any ideal what was going on? This exception happens only on successful return. If I force the function to return earlier (error return), no exception occurs. Obviously in this case initialization fails and I won't able to run PWM function. Untitled.jpg 

FTM_DRV_Init(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_InitConfig, (ftm_state_t * )ftmStatePtr);
FTM_DRV_InitPwm(INST_FLEXTIMER_PWM1, &flexTimer_pwm1_PwmConfig);
//FTM_DRV_FastUpdatePwmChannels(INST_FLEXTIMER_PWM1, 1, &pwm_channel, &pwm_duty_cycle, 0); 

0 Kudos
7 Replies

1,636 Views
Ming
Contributor III

Ok I figured it out, when you invoke FTM_DRV_Init(), you do NOT pass in ftmStatePtr. You have to create your own ftm state structure and use it instead. The pwm example project declares ftmStateStruct in application code (main.c). This also explains why the configurations obtained in FTM_DRV_Init() isn't being properly assigned to ftmStatePtr such as ftm mode and clock source. 

0 Kudos

1,636 Views
razva_tilimpea
NXP Employee
NXP Employee

Hi,

Yes, the memory necessary for state structure must be allocated by application as passed as pointer in Init function. This is applicable for all SDK drivers.

Best regards,

Razvan

0 Kudos

1,636 Views
Ming
Contributor III

Good to know that. Thanks.

0 Kudos

1,636 Views
razva_tilimpea
NXP Employee
NXP Employee

Hi,

Could you share the project with us?

We don't know about this issue and it can be caused by multiple root-causes, so we have to investigate it.

Best regards,

Razvan

0 Kudos

1,636 Views
Ming
Contributor III

I have Free RTOS integrated into my project. It's not a simple project import. 

0 Kudos

1,636 Views
razva_tilimpea
NXP Employee
NXP Employee

Could you create a project just with FTM, clock and pins setup to reproduce this issue?

0 Kudos

1,636 Views
Ming
Contributor III

I already comment out RTOS initialization (PEX_RTOS_INIT) and start (PEX_RTOS_START) in my project, doesn't make any difference. BTW, I traced down the exception to the line in FTM_DRV_UpdatePwmChannel() which is called from FTM_DRV_InitPwm(): 

/* Store the PWM period in the state structure */
state->ftmPeriod = ftmPeriod;

CPU resets as soon as this statement is executed.

What bothers me is the run time ftm state structure at this moment, the clock source is 81 (I am not sure if that's a valid option), ftm mode is set to center aligned even though I configured the pwm as edge aligned. 

Untitled.jpg

0 Kudos