Question
Need help with STM32F072 timer 3 output compare unit
Posted on March 03, 2015 at 19:06
Hello. Thanks for helping.
I have a need to generate fairly precise output pulses atsomewhat irregular intervals. I have timer 3, Ch1 set up forinput capture, and it works great. I have the timer set to roll overat 0xFFFF -->0000 and it works fine. I can read the inputcaptures all day long, they work great. (I am measuring a frequency on this Chanel) On Ch2, I need to drive a solenoidthat will have a varying pulse length (This is a paint-injectorthat will be used to make a ''precision'' length strip ofpaint on a roll of paper going by, (Roll speed is the frequencyinput) The need I have is that on occasion I want CH2 to be usedto output a pulse. My idea is, when this pulse is needed I willread the value of timer3, add my pulse length, and put that valueinto Timer 3, Ch 2 output compare. I want the OC2 pin togo high for XXX miliseconds, and then be set low by the output compare reaching its targeted value. I need to do thismany times per minute. I have this working, but itonly works ONE time, I cannot seem to re-arm the output compare unit. What is the ''trick'' to setting output compare pin high again? Here is how I set up the output compare unit.. TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Active; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_Pulse = 5000; //default pulse length value TIM_OC2Init(TIM3, &TIM_OCInitStructure); Then, in my ''paint'' function, I have this code thatI WANT to have put OC2 high, but it never goes high again..void start_paint_injector(){.. .. I_paint_lenght_count = 500; // test code! I16_present_capture_count = TIM_GetCapture1(TIM3); TIM_SetCompare2(TIM3,I16_present_capture_count+ I_paint_lenght_count); } What is the trick to getting OCx to ''go high'' again? Thank you!!!! /* TIM enable counter */ TIM_Cmd(TIM3, ENABLE); #stm32f072-timer