2023-12-06 01:59 AM
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
2023-12-06 02:26 AM
Hello @meena
Can you add breakpoints in your regulate loop and visualize the content of your register TIM3_CCR2 contains the new computation value that you apply in the Play_boostPWM() function?
Also, restarting the TIM3 at each iteration (HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_2)) is this really useful? You could simply update your duty cycle using the API, __HAL_TIM_SET_COMPARE() without restarting the TIM3.
Regrads,
Romain,
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-12-06 05:54 AM
if I use this I am getting an error undefined reference
2023-12-06 06:05 AM
Without more detail, it will be difficult to help you.
However, can you provide more informations related to your STM32G0 firmware environment?
Do you use STM32Cube_G0_FW? do you include STM32 all used peripherals headers in your code such stm32g0xx_hal_tim.h?
Are you working on custom board? Nucleo? Other...?
Regards.
Romain,
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-12-06 06:13 AM
i am working on a prototype which uses stm32g030k8
2023-12-06 06:15 AM
I AM IN TRANSLATING STM8 CODE TO STM32 STM8 CODE IS HERE
void run_uc_boost(void)
{
static uint8_t uctimer = 0;
static uint16_t pwm_ucboost = 0;
static bool regulate = FALSE;
/* mains off so boost */
if(mainsfail == TRUE)
{
if(uctimer == 0)
{
/* start pwm at preset value*/
void StartUCBoostPWM(uint16_t pwmval)
{
TIM1_SetCompare1(pwmval);
TIM1_CCxCmd(TIM1_CHANNEL_1, ENABLE);
}
/**
void PlayUCPWM(uint16_t pwmvl)
{
TIM1_SetCompare1(pwmvl);
}
/**
**
void StopUCBoostPWM(void)
{
TIM1_SetCompare1(0);
TIM1_CCxCmd(TIM1_CHANNEL_1, DISABLE);
}
if(regulate == FALSE)
{
pwm_ucboost = DEFAULT_UC_PWM;
StartUCBoostPWM(pwm_ucboost);
uctimer = UCSTART_TIME;
regulate = TRUE;
}
/* regulate */
else
{
if(getadcvalue(UC_BOOST_SEL) > MAX_UC_VOLT)
{
if(pwm_ucboost != 0)
{
pwm_ucboost--;
}
}
else if(getadcvalue(UC_BOOST_SEL) < MIN_UC_VOLT)
{
if(MAX_UC_PWM > pwm_ucboost)
{
pwm_ucboost++;
}
}
PlayUCPWM(pwm_ucboost);
}
}
else
{
uctimer--;
}
}
/* mains ok so stop PWM boost */
else
{
StopUCBoostPWM();
regulate = FALSE;
uctimer = 0;
}
}
2023-12-06 06:25 AM
Thank you, but the code for STM8 doesn't help me to understand what problems you are facing.
You wrote "if I use this I am getting an error undefined reference", I suppose you have compiler error when you are using this API: __HAL_TIM_SET_COMPARE()
Is it correct?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-12-06 07:31 AM
yes...I am boosting my voltage with my code I posted first i boosting with a 20% duty cycle but if the voltage increases i need to increase the dutycycle on fly but it couldnt be possible
2023-12-06 07:39 AM - edited 2023-12-06 07:46 AM
Update TIMER PWM duty cycle on the fly is of course possible, it is designed for that.
Do you debug your firmware and read the Timer3 register to see if their value are changing during execution?
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.