AnsweredAssumed Answered

TIM_OCMode_Toggle PWM Duty Controll

Question asked by willy.stm32 on Oct 5, 2013
Latest reply on Apr 27, 2014 by willy.stm32
I'm an absolutely beginner in microcontrollers.
I want to create a PWM signal wave signal  to drive main power switch at 100Khz
TIM1CH1&TIM1CH1N of   STM32F103VC.
I change duty (CCR1_Val) but the duty stay same at 50%.
Can anybody tell me what I'm doing wrong?
Thank You
Photo to Attachments


vu16 CCR1_Val = 90 ;




  TIM_DeInit(TIM1);

  /* Time Base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseStructure.TIM_Period = 360 - 1 ; // 72 MHz / 360 = 200 kHz
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);

  /* Channel 1, 2,3 and 4 Configuration in PWM mode */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Toggle ;
  TIM_OCMode_PWM1
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCNPolarity_Low;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCNIdleState_Set;
    
    TIM_OCInitStructure.TIM_Pulse = CCR1_Val;  // 25%
    TIM_OC1Init(TIM1,&TIM_OCInitStructure);
  TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
 
  /* TIM1 counter enable */
  TIM_Cmd(TIM1,ENABLE);

  /* Main Output Enable */
  TIM_CtrlPWMOutputs(TIM1,ENABLE);


Attachments

Outcomes