2015-03-03 10:06 AM
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-timer2015-03-03 10:43 AM
Define precision. A couple of microseconds?
Toggle mode would allow you to alternate the state. But remember you'd still need to keep advancing the Compare Register. ie TIMx->CCRx += 500; The timer only has one main counting element. Could you use the CCRx values to interrupt and turn OFF the GPIO. ie TIM3->CCR1 = TIM3->CNT + 500; GPIO = ON; at CC1 IRQ GPIO = OFF; Or perhaps slave another timer, or use one in On-Shot mode.2015-03-03 11:02 AM
I cant use toggle mod b/c I only want one pulse.
What I really want is a re-triggerable one shot..Is that possible ? I didn't see that in the documentation of the timer.. Toggle mode is no good b/c I don't want to haveto poll the timer to dis-able it after the first pulse.2015-03-03 12:19 PM
What I really want is a re-triggerable one shot..
Is that possible ? I didn't see that in the documentation of the timer.
You'll need another timer to do the one-shot, and you'll trigger than from your input capture on this current one, or an output compare with a phase setting wrt to other sensor. You'd have to check the reference manual to figure out the TIMx vs TIM3/ITRx master/slave trigger relationship. So you'd set the Trigger Output (TRGO) of TIM3, and the Internal Trigger (ITR) of the other.2015-03-03 12:41 PM
2015-03-03 02:24 PM
Ok, so let me re-iterate.
There is a single counting element (ignoring timebase prescaler, input prescaler, and repetition count) per timer peripheral. If you are rolling a timer 0 thru 65535 to measure delta ticks from your tachometer output of your paper roller, you are using the only ''counter'' in the timer. You can't zero basis a PWM pulse without resetting the counter, or use it for a One-Shot, and thus losing the tachometer function. I mentioned Toggle mode, you dismissed that, but it's quite effective at making variable length pulse, and ones at various phases to the rotation, using a singular timer. I mentioned driving a GPIO and have a interrupt catch the rotating counter further down the line. A lot of the motor control, multi-phase PWM modes require you to baby sit the timer, again something you don't want to do. I mentioned that you could have a slave timer do a one-shot output triggered by either the tachometer input, or a phase relationship to the timer. There are a great number of aspects of the STM32 design I find a bit retarded, the clocks and timers being at the top of my list. The timer documentation is awkward, I've worked with worse, but most all the salient detail is in there.2015-03-03 08:49 PM