S32K116 EVB Pwm and Timer Problem

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

S32K116 EVB Pwm and Timer Problem

1,345 Views
mfatihkoseoglu
Contributor I

Hello, 

 

I am using S32K116-EVB and i wanna use timer interrupt and pwm. If I just use timer or just use pwm it has work but, If I wanna use both of them my sistem is not work. 

 

I use S32DS 3.3 and RTM 4.0.1 Library. 

 

Mycode: 

#include "sdk_project_config.h"
#include "peripherals_flexTimer_mc_1.h"
#include "peripherals_flexTimer_pwm_1.h"

#include "stdio.h"

#define LED_PIN 15U /* LED pin on PTD15 for the EVB Board */
#define LED_PORT PTD

volatile int exit_code = 0;
/* User includes */

void FTM1_Ovf_Reload_IRQHandler(void)
{
static uint32_t counter = 0;

counter++;
if (counter == 20)
{
counter = 0;
}
FTM_DRV_ClearStatusFlags(INST_FLEXTIMER_MC_1, (uint32_t)FTM_TIME_OVER_FLOW_FLAG);
}

/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Write your code here */
ftm_state_t state;
ftm_state_t ftmStateStruct;
uint16_t dutyCycle = flexTimer_pwm_1_IndependentChannelsConfig[0].uDutyCyclePercent;

CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT, g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);

/* Initialize pins */
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS0, g_pin_mux_InitConfigArr0);

/* Initialize FTM */
FTM_DRV_Init(INST_FLEXTIMER_MC_1, &flexTimer_mc_1_InitConfig_0, &state);
/* Initialize FTM instance */
FTM_DRV_Init(INST_FLEXTIMER_PWM_1, &flexTimer_pwm_1_InitConfig, &ftmStateStruct);

/* Initialize counter */
FTM_DRV_InitCounter(INST_FLEXTIMER_MC_1, &flexTimer_mc_1_TimerConfig_0);
/* Initialize FTM PWM channel */
FTM_DRV_InitPwm(INST_FLEXTIMER_PWM_1, &flexTimer_pwm_1_PwmConfig);

/* Start Counter */
FTM_DRV_CounterStart(INST_FLEXTIMER_MC_1);


for(;;)
{
FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM_1,
flexTimer_pwm_1_IndependentChannelsConfig[0].hwChannelId,
FTM_PWM_UPDATE_IN_DUTY_CYCLE, 1000,
0U,
true);

if(exit_code != 0)
{
break;
}
}
return exit_code;
}

I will be glad if you help me.

0 Kudos
Reply
3 Replies

1,337 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi mfatihkoseoglu,

Would you please direct attach whole project?
It will help us check the issue faster.

Best Regards,
Robin

0 Kudos
Reply

1,334 Views
mfatihkoseoglu
Contributor I

Hello, 

 

Thanks for your return. I added my project

0 Kudos
Reply

1,311 Views
Robin_Shen
NXP TechSupport
NXP TechSupport

Hi mfatihkoseoglu,

1. Seems that you configure the wrong pin with channel(FTM0 channel 0 is selected but FTM0_CH1 PTD16 is configured)

Pins FTM0_CH1.pngPeripherals FTM0_CH0.png

2. FTM_DRV_UpdatePwmChannel in main loop seems too frequency. The period of PWM is 1ms but the frequency that you FTM_DRV_UpdatePwmChannel is much higher. I think you should FTM_DRV_UpdatePwmChannel only after dutyCycle is changed.

compare ftm_pwm_s32k116.png

3. Please select Next Loading Point and check Max Loading Point for FTM0.

Sync Point.png

Best Regards,
Robin
-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply