AnsweredAssumed Answered

Need help with STM32F072 timer 3 output compare unit

Question asked by faustini.lou on Mar 3, 2015
Latest reply on Mar 4, 2015 by faustini.lou
Hello. Thanks for helping.

  I have a need to generate fairly precise output pulses at
somewhat irregular intervals.  I have timer 3, Ch1 set up for
input capture, and it works great. I have the timer set to roll over
at 0xFFFF -->0000 and it works fine. I can read the input
captures all day long, they work great. (I am measuring a 
frequency on this Chanel)  On Ch2, I need to drive a solenoid
that will have a varying pulse length (This is a paint-injector
that will be used to make a "precision" length strip of
paint on a roll of paper going by, (Roll speed is the frequency
input)


 
   The need I have is that on occasion I want CH2 to be used
to output a pulse. My idea is, when this pulse is needed I will
read the value of timer3, add my pulse length, and put that value
into Timer 3, Ch 2 output compare.  I want the OC2 pin to
go high for XXX miliseconds, and then be set low by the
output compare reaching its targeted value. I need to do this
many times per minute. I have this working, but it
only 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 that
I 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);






Outcomes