#include "sdk_project_config.h"
#include "osif.h"
#include <stdio.h>
#define CLOCK_PIN 5U //PTB5
#define CLOCK_PORT PTB
#define PWM_CHANNEL 6u // PTE8 PWM CH6
#define PWM_POLARITY FTM_POLARITY_HIGH
volatile int exit_code = 0;
int count = 0;
int main(void)
{
/* Write your local variable definition here */
ftm_state_t ftmStateStruct;
ftm_state_t state;
int dutyCycle = 0U;
flexTimer_pwm_1_IndependentChannelsConfig[0].hwChannelId = PWM_CHANNEL;
flexTimer_pwm_1_IndependentChannelsConfig[0].polarity = (ftm_polarity_t)PWM_CHANNEL;
/* Initialize clock module */
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 instance */
FTM_DRV_Init(INST_FLEXTIMER_PWM_1, &flexTimer_pwm_1_InitConfig, &ftmStateStruct);
FTM_DRV_Init(INST_FLEXTIMER_MC_1, &flexTimer_mc_1_InitConfig_0, &state);
/* Initialize FTM PWM channel */
FTM_DRV_InitPwm(INST_FLEXTIMER_PWM_1, &flexTimer_pwm_1_PwmConfig);
FTM_DRV_InitCounter(INST_FLEXTIMER_MC_1, &flexTimer_mc_1_TimerConfig_0);
FTM_DRV_CounterStart(INST_FLEXTIMER_MC_1);
/* Infinite loop */
for ( ;; )
{
PINS_DRV_TogglePins(CLOCK_PORT, (1 << CLOCK_PIN)); // PTB5 TOGGLE (1)
OSIF_TimeDelay(100);
for (dutyCycle = 0; dutyCycle < 30000; dutyCycle += 2000) // PTE8 PWM (2)
{
FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM_1,
flexTimer_pwm_1_IndependentChannelsConfig[0].hwChannelId,
FTM_PWM_UPDATE_IN_TICKS, dutyCycle,
0U,
true);
OSIF_TimeDelay(100);
}
for(dutyCycle=30000;dutyCycle>0;dutyCycle -=2000){ // PTE8 PWM (2)
FTM_DRV_UpdatePwmChannel(INST_FLEXTIMER_PWM_1,
flexTimer_pwm_1_IndependentChannelsConfig[0].hwChannelId,
FTM_PWM_UPDATE_IN_TICKS,dutyCycle,
0U,
true);
OSIF_TimeDelay(100);
}
}
OSIF_TimeDelay(100);
return exit_code;
}
I made PWM on PTE8 using example file on S32 DS and I made a separate code to toggle by repeating 0 and 1 on pin PTB5 using example. But I'm trying to combine the two codes into one code.
This is the code being tried.
I can't express all functions with this code
Instead of 1 and 2 being executed independently, 1 and 2 are executed quickly in order by the loop syntax, making it mistaken as if a signal is coming out at the same time.
Is there a simple way to do this independently?
For example, through for, while, and if phrases
I don't know if what I'm trying to say is conveyed well, I need your help.
Do be honest, I really don't understand your issue too much.
If you call two functions sequentially than it'll be also sequentially executed. Please clarify