AnsweredAssumed Answered

PWM mode output case

Question asked by shrestha.durgesh on Dec 26, 2011
Latest reply on Dec 27, 2011 by shrestha.durgesh
I want to generate a signal of frequency 250 kHz with a duty cycle of 50%. after 100 cycle the output has to be low continuously until next fifty cycle and again the trend is to be continued.
Can anyone suggest me how can i implement with the PWM Mode counter implementation.

It should be taken into consideration that during the gap of fifty cycle the interrupt service routine has to be free (i.e. ISR of the timer should leave at the end of 100th cycle and come back after fifty cycle and do the same for next 100 cycle).

For the startup (the prescalers could be as follows with system freq 72 Mhz):

  TIM_TimeBaseStructure.TIM_Period = 287;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  /* PWM1 Mode configuration: Channel2 */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = 144;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;

  TIM_OC2Init(TIM2, &TIM_OCInitStructure);
  TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

  TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);

  TIM_ARRPreloadConfig(TIM2, ENABLE);
  /* TIM2 enable counter */

I would be glad if someone could help me.