Skip to main content
stm3223
Associate II
October 5, 2013
Question

TIM_OCMode_Toggle PWM Duty Controll

  • October 5, 2013
  • 15 replies
  • 3784 views
Posted on October 05, 2013 at 08:36

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);

    This topic has been closed for replies.

    15 replies

    Tesla DeLorean
    Guru
    October 7, 2013
    Posted on October 07, 2013 at 23:03

    The code was for an F4 rather than an F1 part, you will likely need to use a different interrupt designator, like TIM1_UP_IRQn, or TIM4_IRQn, etc, as appropriate, see stm32f10x.h and startup_stm32f10x.s

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    waclawek.jan
    Super User
    October 8, 2013
    Posted on October 08, 2013 at 09:16

    > One might suppose, but I've never had much joy with the dead-time settings, so an example doing this would be welcome.

    Do you mean ''I tried but it did not work as I expected'', or ''I never had an opportunity/reason to try''?

    I don't have the reason, but as this is what one would expect as a driving waveform for a bridge, I'd be very surprised if ST wouldn't pay attention to its working. I'd even expect an example to exist somewhere. STM32F10x_StdPeriph_Lib_V3.4.0\Project\STM32F10x_StdPeriph_Examples\TIM\ComplementarySignals\ appears to be such, but as I said, so far I  haven't had the reason to go there.

    JW

    stm3223
    stm3223Author
    Associate II
    October 8, 2013
    Posted on October 08, 2013 at 12:39

    Not problem JW,

    thanks anyway

    for help intention

    when

    you have a question

    ,

    any ideas

    welcome

    to evaluate

    or

    test

    Tesla DeLorean
    Guru
    October 8, 2013
    Posted on October 08, 2013 at 17:05

    Do you mean ''I tried but it did not work as I expected'', or ''I never had an opportunity/reason to try''?

    Mostly the former, I have experimented with the timers, and tried to digest the documentation/diagrams. The timers only have a singular timing value, and I'm really not sure that I can combine say channel 1&2 and 3&4 to express a start/stop comparison with respect to the time base. I have experimented with dead-time settings, and had more frustration than success.

    Looking at the motor/pwm, multiple interrupt handlers for TIM1, I've concluded that they expect a much more dynamic interaction with the TIM parameters, rather that being able to set the hardware up once to perform some simple function generation automatically.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    stm3223
    stm3223Author
    Associate II
    April 27, 2014
    Posted on April 27, 2014 at 19:27