/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / TIM and PWM Functions

Username:     
Password:     
             

Forum

# 1   2010-09-07 17:21:06 TIM and PWM Functions

vikram846
New member
Registered: 2010-08-25
Posts: 9

TIM and PWM Functions

Hi I am new to Primer 2 Hardware and am trying to generate a PWM signal to drive a MOSFET. Eventually I would like the frequency and load cycle to be input via touchscreen.


Does Circle OS provide this function? I didnot find any TIM_ or PWM keywords in the circleos documentation.

Which library should I use to access these functions? Can some one please provide me with an exact link to the documentation of this library?


Thanks in advance,

Vik

Offline

 

# 2   2010-09-08 06:30:37 TIM and PWM Functions

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: TIM and PWM Functions

CircleOS only provide functions for the embedded peripherals (LCD, MEMS, Audio...). For special needs, you have to write your own drivers, eventually with the help of the ST peripheral library, available here http://www.st.com/stonline/products/sup … ph_lib.zip.
Take a look at  the TIM examples.

Offline

 

# 3   2010-09-09 04:16:50 TIM and PWM Functions

vikram846
New member
Registered: 2010-08-25
Posts: 9

Re: TIM and PWM Functions

Hi,
Thanks for the link.
What is the procedure to add the .c library to the project ?
for example
even though I right click and add stm32f10x_gpio.c , I still get errors.
but If I use the given template (in the link you gave me) it works.

thanks
Vik

Offline

 

# 4   2010-09-09 05:54:46 TIM and PWM Functions

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: TIM and PWM Functions

For each peripheral you want to use, you effectively must add the ".c" file into your project, but also modify the "stm32f10x_conf.h" in order to include the corresponding ".h".
Take a look at the help file "stm32f10x_stdperiph_lib_um.chm" provided with the library.

Offline

 

# 5   2010-09-10 02:00:07 TIM and PWM Functions

rikubon
Member
Registered: 2009-08-21
Posts: 16

Re: TIM and PWM Functions

Hi vikram846,

I am also working on the completely same issue and I could get a PWM signal with the following code (only the main part). I added a call of InitPWM() in the Application_Ini() function and my Primer2 output a 144Hz PWM signal with a duty ratio of 0.8.

Of course, as yrt mentioned above, you have to add the ".c" files in your project first.
#It is only and the worst feature of the Ride 7 environment...

void InitPWM(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
  uint16_t PWM1_Width = 400;

  TIM_Cmd(TIM2, DISABLE);

  RCC_AHBPeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  RCC_AHBPeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

  // Configure PA.0 (TIM2_CH1_ETR)
  // TIM2_CH1_ETR is connected to the pin 14 of the ext. terminal of Primer2
  // as a floating input
  GPIO_StructInit (&GPIO_InitStructure);
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; // PA.0 = the pin 14 of the ext. terminal
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  /* Time base configuration */
  TIM_TimeBaseStructure.TIM_Prescaler = 999;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 72M/(0+1)=72M
  TIM_TimeBaseStructure.TIM_Period = 500; // generates 72M/(Prescaler+1)/(ClockDivision+1)/Period)
  TIM_TimeBaseStructur/500=e.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

  /* PWM1 Mode configuration */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
  TIM_OCInitStructure.TIM_Pulse = PWM1_Width;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC1Init(TIM2, &TIM_OCInitStructure);

  TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);

 
  /* TIM enable counter */
  TIM_Cmd(TIM2, ENABLE);

}

Offline

 

Board footer