#ftm_pwm_S32K116 Hi,Dear NXP colleague: I'm looking for help about the project of ftm_pwm_s32k116,the fact is that no matter how I try to change the code or configuration.the MCU can't output PWM signal on default channel(FTM0-channel 0,i.e. PTD15). here is my step : 1.import the new project from example; 2.compile it and all PASS,I check the pin mux and flextimer configuration and find no problem(actually it's from NXP example,I think it's totally right); 3.then I flash it into S32K116; 4.observe the waveform on PTD15 and find nothing,I tried for almost 2days; the zip file of my project is as below,thanks. Re: #ftm_pwm_S32K116 attach my project Re: #ftm_pwm_S32K116 Hi @Tracy_Lu
First, I noticed that you are using Processor Expert, so it seems that you are working with an older software version. If you are starting your development with S32K1 devices, we would recommend using the latest available software and tools, currently the S32K1_S32M24X Real-Time Drivers AUTOSAR R21-11 Version 3.0.0 (Real-Time Drivers for S32K1) together with S32 Design Studio for S32 Platform (S32 Design Studio | NXP Semiconductors).
However, if you would like to continue using the S32K1 SDK, the latest SDK version was provided with S32 Design Studio for S32 Platform 3.4.
Additionally, could you please let us know whether you are using an EVB or a custom board?
If you would like to remain with your current software setup, it would also be helpful if you could share the exact S32K1 SDK version you are using.
BR, VaneB Re: #ftm_pwm_S32K116 Hi,Dear NXP colleague: thanks for the quick and professional reply.I change to another project S32K116_Project_FTM from example and modify the code(with the assistance from gemini AI),I want to share these points to help the engineer like me to solve the problem during compile and debug: 1.I use the FTM function to respond the ESM(error signal monitoring)of my PMIC(TPS650366); 2.at first I use ftm_pwm_S32k116 project and failed to compile and debug,for around 2 days.I can't see any output PWM at the assigned pin.And I'm sure I make the right configuration and debug,with the assistance from Gemini AI; 3.then I find another example named S32K116_Project_FTM,I tried and compile it with no error.and I get the output of the configured pin which is PTD15(FTM0CH0)/16(FTM0CH1),though the initial frequency is 1Hz/5Hz,I know I'm close to the finish line; 4.actually,I need the pwm frequency around 40KHz,so I know the next step is to modify the system frequency prescaler,MOD value,CnV(duty cycle),but I find that I can't change the MOD value(I change the value but I can't write into the root place of MCU),I tried and tried,searching all the info which can help with me; 5.finally I find that if you want to change MOD value,you should satisfy several pre-condition,e.g.you should close the clock,release the write protection...; 6.here is my code after compile and operates normally(output around 48KHz at PTD16); int main(void) { /*! * Initialization: * ======================= */ WDOG_disable(); /* Disable watchdog */ SOSC_init_40MHz(); /* Initialize system oscillator for 40 MHz xtal */ RUN_mode_48MHz(); /* Init clocks: 48 MHz sys, core and bus, 24 MHz flash. */ FTM0_init(); /* Init FTM0 using 8 MHz SIRCDIV1_CLK */ //FTM0_CH0_OC_init(); /* Init FTM0 CH0, PTD15 */ FTM0_CH1_PWM_init(); /* Init FTM0 CH1, PTD16 */ FTM0_CH6_IC_init(); /* Init FTM0 CH6, PTE8 */ FTM1_Init(); FTM1_CH1_PWM_init(); PORT_init(); /* Configure ports */ start_FTM0_counter(); /* Start FTM0 counter */ /*! * Infinite for: * ======================== */ for(;;) { //FTM0_CH0_output_compare();/* If output compare match: */ /* Pin toggles (automatically by hardware) */ /* Clear flag 8 */ /* Reload timer */ //FTM0_CH6_input_capture(); /* If input captured: clear flag, read timer */ } } 7.the import code is as below(FTM0_init(),FTM0_CH1_PWM_init()) : void FTM0_init(void) {/** * FTM0 Clocking: * ================================================== */ PCC->PCCn[PCC_FTM0_INDEX] &= ~PCC_PCCn_CGC_MASK; /* Ensure clk disabled for config */ PCC->PCCn[PCC_FTM0_INDEX] |= PCC_PCCn_PCS(0b010) /* Clock src=1, 8 MHz SIRCDIV1_CLK */ | PCC_PCCn_CGC_MASK; /* Enable clock for FTM regs */ /*! * FTM0 Initialization: * =================================================== */ // 1. 第一步:确保 FTM 时钟彻底关闭(CLKS = 0),此时处于完全可配置状态 FTM0->SC = 0x00000000; // 2. 第二步:解除写保护并开启 FTM 完整模式 volatile uint32_t dummy = FTM0->MODE; FTM0->MODE |= FTM_MODE_WPDIS_MASK; /* 禁用写保护 */ FTM0->MODE |= FTM_MODE_FTMEN_MASK; /* 开启 FTM 完整模式 */ // 3. 第三步:在时钟关闭的安全状态下,顺利把 MOD 和比较值写进去 FTM0->CNTIN = 0U; FTM0->MOD = 166 - 1; /* 8MHz / 166 ≈ 48.19 kHz */ // 4. 第四步:配置通道 1 (PTD16) 为边沿对齐 PWM 模式 FTM0->CONTROLS[1].CnSC = FTM_CnSC_MSB_MASK | FTM_CnSC_ELSB_MASK; FTM0->CONTROLS[1].CnV = 83; /* 50% 占空比 (83 < 165) */ // 5. 第五步:极性和组合模式清零 FTM0->COMBINE = 0x00000000; FTM0->POL = 0x00000000; // 6. 最后一步:所有参数已经安稳写入后,才真正开启通道输出和时钟源! FTM0->SC = FTM_SC_PWMEN0_MASK | FTM_SC_PWMEN1_MASK | FTM_SC_PS(0) /* PS = 0 (不分频) */ | FTM_SC_CLKS(1); /* CLKS = 1 (最后启动计数器) */ } void FTM0_CH1_PWM_init(void) { /** * FTM0, Channel 1 in PWM Mode: * ================================================== */ FTM0->CONTROLS[1].CnSC = FTM_CnSC_MSB_MASK |FTM_CnSC_ELSB_MASK; /* FTM0 ch1: edge-aligned PWM, low true pulses */ /* CHIE (Chan Interrupt Ena) = 0 (default) */ /* MSB:MSA (chan Mode Select)=0b10, Edge Align PWM */ /* ELSB:ELSA (chan Edge/Level Select)=0b10, low true */ FTM0->CONTROLS[1].CnV = 46875; /* FTM0 ch1 compare value (~75% duty cycle) */ }
View full article