2012-08-27 11:01 AM
Is there a way to tell a TIMer on STM32 chips to do some number of steps and automatically stop after finished (and give an interrupt)? I can do it now with a counter in the ISR but a few pulses slip out before I can shutdown the PWM output or the timer.
2015-02-08 08:46 AM
Thanks again Clive.
One question, I can't figure out what one instruction will start the pulse sequence.I don't want to start the pulses immediately at initialization time and I want to repeat the sequence over and over.The code shown below works, but I think I could clean it up if I understood the timers as well as you.I am using the update interrupt to get additional cycles of 200 pulses /* Enable the TIM8 gloabal Interrupt */ NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); /* TIM Interrupts enable */ TIM_ITConfig(TIM8, TIM_IT_Update , ENABLE); ................//Interrupt Handlervoid TIM8_UP_TIM13_IRQHandler(void){ if (TIM_GetITStatus(TIM8, TIM_IT_Update) != RESET) { TIM_ClearITPendingBit(TIM8, TIM_IT_Update); tim8_counter--; if ( tim8_counter != 0) { TIM8_Restart(); } }} void TIM8_Restart(void) // This seems to work{ /* TIM8 Main Output Enable */ TIM_CtrlPWMOutputs(TIM8, ENABLE); /* TIM8 enable counter */ TIM_Cmd(TIM8, ENABLE);} //This is what I do the first time and when I want to send another series of 200 pulses// Some of these instructions were removed from the init code you posted tim8_counter = TIM8_INTERRUPTS; TIM_CtrlPWMOutputs(TIM8, ENABLE); TIM_Cmd(TIM8, ENABLE); TIM_Cmd(TIM3, ENABLE); TIM8_Restart();Any ideas on what is actually turn the pulses off and on?ThanksBarry2015-10-21 07:02 PM
I have this code running correctly for Timer 8 channel 1. When I try to use this code for other channels on Timer 8, I run into problems.
Channel 2n (complementary) does not work (i.e. no PWM output)Channel 3 continually outputs pulsesAll I have changed is the GPIO pin configurationand I use OCxInit for each channel.Does anyone know what else is channel dependent. Thanks