2013-01-01 05:08 AM
I want to generate a PWM signal to control a servo motor. The servo has a dead band width of 10?s. I have tried doing this using the '7_PWMOutputs' example.
Code so far: _______________________________________________________________________ TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_OCInitTypeDef TIM_OCInitStructure; uint16_t TimerPeriod = 0; uint16_t Channel1Pulse = 0, GPIO_InitTypeDef GPIO_InitStructure; RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP ; GPIO_Init(GPIOA, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_2); TimerPeriod = (SystemCoreClock / 17570) - 1; /* With variable 'x'*/ Channel1Pulse = (uint16_t) (((uint32_t) 25 * (TimerPeriod - 1)) / 100); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE); TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_Period = TimerPeriod; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; TIM_OCInitStructure.TIM_Pulse = Channel1Pulse; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_Pulse = Channel1Pulse; TIM_OC1Init(TIM1, &TIM_OCInitStructure); TIM_OCInitStructure.TIM_Pulse = Channel1Pulse; TIM_OC1Init(TIM1, &TIM_OCInitStructure); TIM_Cmd(TIM1, ENABLE); TIM_CtrlPWMOutputs(TIM1, ENABLE); while(1){ } _______________________________________________________________________ How and where should I change or what should I add more to output a PWM signal with a 25% duty cycle and a 10?s dead band width. Thanks in advance! #pwm2013-01-01 10:30 AM
The PWM Frequency is controlled by the Prescale and Period values, divided into the timer source clock, the width is controlled by Pulse in units in the range of the Period value, and quanta of timer source divided by Prescale.
Prescale and Period are in the form N-1, where N is the divisor. Here is a 50 Hz Servo example for the VL Discovery, I have something similar for the F4[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32VLDiscovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32VLDiscovery/Servo%20control%20using%20STM32VLDiscovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000491D59B8574F8049B5DFA3E8B21CBA51¤tviews=1106]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32VLDiscovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32VLDiscovery%2FServo%20control%20using%20STM32VLDiscovery&FolderCTID=0x01200200770978C69A1141439FE559EB459D758000491D59B8574F8049B5DFA3E8B21CBA51¤tviews=11062014-05-16 09:18 AM
2014-05-16 09:22 AM
could you please send me the source code forPWM signal generation for a servo motor for stm32F4.
2014-05-16 01:40 PM
Thank you for the code but it didn't work i use microservo TowerPro 9g and it has only one input
2014-05-16 03:45 PM
Thank you for the code but it didn't work i use microservo TowerPro 9g and it has only one input
Then just use one output.... If you think there is a problem with the signal inspect it with a scope and report.2015-04-13 12:05 PM
2015-04-13 12:08 PM