cancel
Showing results for 
Search instead for 
Did you mean: 

PWM frequency and duty cycle control - problem

hhachem00
Associate
Posted on October 15, 2012 at 19:56

Hi,

I'm trying generate a PWM signal whose frequency and duty cycle are controllable by 2 potentiometer on a STM8S105 Board. However, I am still unable to get the variables to update their values. Here is the code:

//GPIO:
GPIO_Init(GPIOB, GPIO_PIN_0, GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOB, GPIO_PIN_1, GPIO_MODE_IN_FL_NO_IT);
//ADC_Config:
ADC1_DeInit();
ADC1_Init(ADC1_CONVERSIONMODE_CONTINUOUS,ADC1_CHANNEL_1,ADC1_PRESSEL_FCPU_D2,ADC1_EXTTRIG_TIM,DISABLE,ADC1_ALIGN_LEFT, ADC1_SCHMITTRIG_ALL,DISABLE);
ADC1_ScanModeCmd(ENABLE);
ADC1_ITConfig(ADC1_IT_EOCIE,ENABLE);
enableInterrupts();
ADC1_Cmd(ENABLE);
ADC1_StartConversion();
//ADC1 ISR:
Value0 = ADC1_GetBufferValue(0);
Value1 = ADC1_GetBufferValue(1);
TIM2_DeInit();
TIM2_TimeBaseInit(TIM2_PRESCALERR_512,Value0+1000);
TIM2_OC1Init(TIM2,OCMODE_PWM2,TIM2_OUTPUTSTATE_ENABLE,Value1+500,TIM2_OCPOLARITY_LOW);
TIM2_Cmd(ENABLE);
ADC1_ClearFlag(ADC1_FLAG_EOC);
ADC1_StartConversion();

Value0 and Value1 are not updating their values once I turn the potentiometers. They simply maintain the values provided by the very first conversion. Any help will be very much appreciated.
0 REPLIES 0