2016-03-10 10:21 AM
I would like use the stm32f100 for buck loop control.
In first, I reach to configure the timer and gpio to get a fixe PWM. But I don't know, for the moment, adjust or modify the duty cycle with a command. Before I use arduino, and it wa svery easy just with a command digitalwrite(pin, value). Thank you if anybody can help me.2016-03-10 10:34 AM
int Period = 5000;
int DutyPercent = 50; // Percentage 0 to 100, 0 Always Off, 100 Always On// Quick configuration /* Time base configuration */ TIM_TimeBaseStructure.TIM_Prescaler = 0; TIM_TimeBaseStructure.TIM_Period = Period - 1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseStructure.TIM_ClockDivision = 0; TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure); /* TIM PWM1 Mode configuration */ TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_Pulse = Period / 2; // 50% TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset; /* Output Compare PWM1 Mode configuration: Channel1 */ TIM_OC1Init(TIM1, &TIM_OCInitStructure); /* TIM1 Main Output Enable */ TIM_CtrlPWMOutputs(TIM1, ENABLE); /* TIM1 enable counter */ TIM_Cmd(TIM1, ENABLE);// Then all require to change duty isTIM1->CCR1 = (Period * DutyPercent) / 100;2016-03-10 11:08 AM
Thank you clive1 for your fast reply. I 'll try tomorrow and give you informed as soon as possible.
2016-03-10 11:22 PM
Dear clive1,
it works fine. thank2016-03-11 01:21 AM
2016-03-11 03:55 AM
But I'm still stopped by an error of compilation.
Ok, the error says what exactly? The error itself usually provides some specificity. If it is complaining about library functions being missing, those would need to be added to the project/workspace. Not a big CooCox fan, but standard rules of C should permit you to break things into subroutines, or migrate them into separate files2016-03-11 04:30 AM
Hi clive1,
what type of software you use ? free software ? the errors are : error: 'ADC_InitStructure_InitStructure' undeclared (first use in this function) error: 'ADC_InitTypeDef' has no member named 'ADC_ScanMode' error: 'ADC_InitTypeDef' has no member named 'ADC_continuousConvMode'2016-03-11 05:06 AM
My troubles are syntax error
the lines involved and corrected are : ADC_InitStructure.ADC_Mode = ADC_Mode_Independent ; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConv= ADC_ExternalTrigConv_None ; From: baptiste.thierryPosted: Friday, March 11, 2016 1:30 PMSubject: stm32f100 pwm duty cycleHi clive1,
what type of software you use ? free software ? the errors are : error: 'ADC_InitStructure_InitStructure' undeclared (first use in this function) error: 'ADC_InitTypeDef' has no member named 'ADC_ScanMode' error: 'ADC_InitTypeDef' has no member named 'ADC_continuousConvMode'2016-03-11 05:52 AM
what type of software you use ? free software ?
Working properly tends to rank higher on my scale. I mainly use Keil, but use GNU/GCC via makefiles, where appropriate. Rowley is a reasonably priced tool chain. The SPL really needs you to have some defines passed to the compiler's command line, and the peripheral include files usually get pulled via stm32f1xx_conf.h Defines like USE_STDPERIPH_DRIVER, STM32F10X_HD_VL See also STM32F10x_StdPeriph_Lib_V3.5.0\Project\STM32F10x_StdPeriph_Template2016-03-11 07:47 AM
Thank you clive1 for your help.
I had a look on the Keil website, software looks interresting. I'm a beginner in sofware, so I'll certainly comeback in a short delay to make a sos software... Thierry