Electrical Engineering Asked by John Jin on February 22, 2021
I need to enable a general timer interrupt after generating each pulse in PWM mode. I wrote this program. I will be grateful if you kindly let me know how to enable timer interrupt. This my SPL schematic code:
void PWMControl(unsigned int Freq){
TIM_TimeBaseInitTypeDef TimeStructureure;
TIM_OCInitTypeDef TIMOCStructureure;
TimeStructure.TIM_Prescaler=Prescale;
TimeStructure.TIM_CounterMode=TIM_CounterMode_Up;
TimeStructure.TIM_Period=Period;
TimeStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TimeStructure.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM4, &TimeStructure);
TIM_Cmd(TIM4, ENABLE);
TIMOCStructure.TIM_OCMode=TIM_OCMode_PWM2;
TIMOCStructure.TIM_OutputState=TIM_OutputState_Enable;
TIMOCStructure.TIM_OCPolarity=TIM_OCPolarity_Low;
TIMOCStructure.TIM_Pulse=Pulse;
TIM_OC1Init(TIM4, &TIMOCStructure);
//TIM_OC1PreloadConfig(TIM4, TIM_OCPreload_Enable);
TIM_ITConfig(TIM4,TIM_IT_Update,ENABLE);
}
According to this post I need to generate N pulse without/ the least CPU workload. (Max Frequency=1MHz)
Are you using CubeMX?
If yes then you have to first enable it in NVIC after configuring TIM4.
Next, inside your logic you have to enable the timer as HAL_TIM_IC_Start_IT(&htim4, TIM_CHANNEL_1);
Correct answer by Juggernaut Panda on February 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP