STM32 PWM ON/OFF

OP (Firma: mumu) #3459100
Lesenswert?

What is the best way to switch the output of a pin between  PWM ON and 
PWM OFF (Pin state high)?

Basically what I want to get is:

High(10ms) -- PWM(20ms) -- High(50ms)...

The time tells the Duration of the pins state. I have the PWM working as 
it should but just do not know how to switch it ON and OFF.

This is the way I initialized the timer:

  TIM_TimeBaseStructure.TIM_Period = TIM_ARR;
  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

The channel:
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = TIM_CCR;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

Is it the right way to use something like:

  TIM4->CCR4=0;
or
  TIM_SetCompare1(TIM4,0);

But this was not working for me. Thanks for your ideas.
Gast #3459173
Lesenswert?

1. put an external pull-up resistor on your pwm-output pin.
2. use (systick) timer for a at least msecs-based timer functions
3. switch by software between pwm-out mode and dio input mode at your 
desired msecs interval.
4. have fun

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren