Question
Timer_PWM
Hi people,
I am looking for a help please
I am working on a boosting up a voltage and works in a closed control if it exceeds the Max_UC_volt the duty cycle should vary..
void run_ucboost(void)
{
uint16_t mainsfail=1;
uint16_t uctimer = 0;
uint16_t pwm_ucboost = 0;
uint16_t regulate = 0;
/* mains off so boost */
if(mainsfail == 1)
{
if(uctimer == 0)
{
/* start pwm at preset value*/
if(regulate == 0)
{
pwm_ucboost = DEFAULT_UC_PWM;
Start_UCboostPWM(pwm_ucboost);
uctimer = UCSTART_TIME;
regulate = 1;
}
/* regulate */
else
{
if(Battmon > MAX_UC_VOLT)
{
if(pwm_ucboost != 0)
{
pwm_ucboost--;
}
}
else if(Battmon < MIN_UC_VOLT)
{
if(MAX_UC_PWM > pwm_ucboost)
{
pwm_ucboost++;
}
}
Play_boostPWM(pwm_ucboost);
}
}
else
{
uctimer--;
}
}
/* mains ok so stop PWM boost */
else
{
Stop_UCboostPWM();
regulate = 0;
uctimer = 0;
}
}
void Start_UCboostPWM(uint16_t pwmvalue)
{
TIM3->ARR=pwmvalue;
TIM3->CCR2= pwmvalue*0.2;
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
}
void Play_boostPWM(uint16_t boostval)
{
TIM3->ARR=boostval;
TIM3->CCR2= boostval*0.2;
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2);
}
void Stop_UCboostPWM(void)
{
TIM3->CCR2 = 0;
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
}
I am getting my boost voltage but duty cycle doesn't have the control on loading.how can i use Set compare on this
