I am currently using the STM32F103C8 board, in this, I connect the OPTOCOUPLER input to the PA6 PIN of stm32 which is the PWM pin, and at the output side I connect the optocoupler's output to the driver's 10v + pin and optocoupler's output with 10v - pin, and I also generate the PWM signal using timer 3 ,and in this i want to control the led brightness using the pwm dutycycle but this is not proper working . give me suggestions what should i do in this case?
this is the pwm initialization code
void PWM_Init(void) {
// Initialization struct
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
TIM_OCInitTypeDef TIM_OCInitStruct;
GPIO_InitTypeDef GPIO_InitStruct;
// Step 1: Initialize TIM3
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
// Configure TIM3 base
TIM_TimeBaseInitStruct.TIM_Prescaler = 144;
TIM_TimeBaseInitStruct.TIM_Period = 499;
TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseInitStruct);
TIM_Cmd(TIM3, ENABLE);
// Step 2: Initialize PWM
TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OCInitStruct.TIM_Pulse = 0;
// Initialize OC1
TIM_OC1Init(TIM3, &TIM_OCInitStruct);
TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
// Initialize OC2
TIM_OCInitStruct.TIM_Pulse = 0;
TIM_OC2Init(TIM3, &TIM_OCInitStruct);
TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
// Initialize OC3
TIM_OCInitStruct.TIM_Pulse = 0;
TIM_OC3Init(TIM3, &TIM_OCInitStruct);
TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
// Initialize OC4
TIM_OCInitStruct.TIM_Pulse = 0;
TIM_OC4Init(TIM3, &TIM_OCInitStruct);
TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
// Step 3: Initialize GPIOA (PA6, PA7) and GPIOB (PB0)
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
// Initialize PA6 as push-pull alternate function (PWM output) for LED
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStruct);
// Initialize PB0 as push-pull alternate function (PWM output) for LED
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
}