AnsweredAssumed Answered

Change PWM pulse

Question asked by lapiana.francesco on Sep 14, 2015
Latest reply on Sep 14, 2015 by Clive One
Hi,
I'm using a servo with a pwm connection and this is a part of code:
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 
 
GPIO_PinAFConfig(GPIOB, GPIO_PinSource4, GPIO_AF_1);
 
GPIO_InitTypeDef GPIO_InitStructure;
 
 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
 
GPIO_Init(GPIOB, &GPIO_InitStructure);
 
 
TIM_TimeBaseInitTypeDef TIM_BaseStruct;
 
 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
 
 
TIM_BaseStruct.TIM_Prescaler = 48-1;
 
TIM_BaseStruct.TIM_CounterMode = TIM_CounterMode_Up;
 
 
TIM_BaseStruct.TIM_Period = 20000-1;
TIM_BaseStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_BaseStruct.TIM_RepetitionCounter = 0;
 
TIM_TimeBaseInit(TIM3, &TIM_BaseStruct);
 
TIM_Cmd(TIM3, ENABLE); 
 
 
TIM_OCInitTypeDef TIM_OCStruct;
 
 
TIM_OCStruct.TIM_OCMode = TIM_OCMode_PWM2;
TIM_OCStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCStruct.TIM_OCPolarity = TIM_OCPolarity_Low;
 
 
/* 50% duty cycle */
TIM_OCStruct.TIM_Pulse = 10000;
TIM_OC1Init(TIM3, &TIM_OCStruct);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
How can I change dinamically  TIM_Pulse?  (I'm using ST32F0xx)

Outcomes