cancel
Showing results for 
Search instead for 
Did you mean: 

TIM17 PWM

ybitton
Associate II
Posted on July 19, 2011 at 17:47

Hi,

I am trying to produce PWM signal by using TIM17 channel1 on PORTB-9,

but i can't get the PWM signal.

In debug mode i can see that TIM17 COUNTER register advanced and do overloop, but i just cant see the PWM signal on PORTB-9.

I configured RCC, GPIO and TIM (in this order as seen below).

Can any one give a hand?

THanks!

/************************************RCC***************************************************

  /* Setup the microcontroller system. Initialize the Embedded Flash Interface, 

     initialize the PLL and update the SystemFrequency variable. */

  SystemInit();

 

  /*Configures the AHB clock (HCLK).*/

  RCC_HCLKConfig(RCC_SYSCLK_Div2);

 

  /*Configures the Low Speed APB clock (PCLK1).*/

  RCC_PCLK1Config(RCC_HCLK_Div1);

 

  /* Enable DMA1 clock */

  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);

  

  /* Enable ADC1-Periph, and ADC-GPIO (as defined in MW_hw.h) clocks */

  RCC_APB2PeriphClockCmd(   RCC_APB2Periph_TIM17     |

                                                RCC_APB2Periph_GPIOB ,  ENABLE );

/************************************GPIO***************************************************

GPIO_InitTypeDef GPIO_InitStructure;

 

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

  GPIO_Init(MW_CONTROL_GPIO, &GPIO_InitStructure);  

/************************************TIM17**************************************************

/* Time base configuration */

  TIM_TimeBaseStructure.TIM_Period = 11999;                  TIM_TimeBaseStructure.TIM_Prescaler = 0;     TIM_TimeBaseStructure.TIM_ClockDivision = 0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM17, &TIM_TimeBaseStructure);

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse =11999*20/100; //20%

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;  

TIM_OC1PreloadConfig(TIM17, TIM_OCPreload_Enable);

   

  TIM_ARRPreloadConfig(TIM17, ENABLE);

  

  TIM_Cmd(TIM17, ENABLE);

  // Enable PWM signal.

  TIM_CCxCmd(TIM17, TIM_Channel_1, TIM_CCx_Enable);

 

#tim17 #tim-15-16-17-pwm
3 REPLIES 3
ybitton
Associate II
Posted on July 20, 2011 at 13:15

Hi,

I have overcome that problem and now it works.

What was the problem?

TIM15-16-17 are Timer group with complementary outputs and programmable dead-time, therefore PWM configuration is a bit different than  TIM2-3-4-5.

It mainly require 'BDTR' register configuration.

I have attached a working code example for your convenience.

  

Udi.
dan23
Associate
Posted on May 28, 2015 at 08:21

I have the same problem. Could anyone post an example code?

Thanks,

Posted on May 28, 2015 at 16:09

Make sure you initialize all the fields in the time base and output compare structures.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..