2020-08-16 03:49 AM
Using CUBEMX 6 to configure the two comparators in STM32L053 in window mode this initialization code is generated:
COMP_HandleTypeDef hcomp1;
COMP_HandleTypeDef hcomp2;
/* COMP1 init function */
void MX_COMP1_Init(void)
{
hcomp1.Instance = COMP1;
hcomp1.Init.InvertingInput = COMP_INPUT_MINUS_DAC1_CH1;
hcomp1.Init.NonInvertingInput = COMP_INPUT_PLUS_IO1;
hcomp1.Init.LPTIMConnection = COMP_LPTIMCONNECTION_DISABLED;
hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp1.Init.Mode = COMP_POWERMODE_ULTRALOWPOWER;
hcomp1.Init.WindowMode = COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON;
hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_FALLING;
if (HAL_COMP_Init(&hcomp1) != HAL_OK)
{
Error_Handler();
}
}
/* COMP2 init function */
void MX_COMP2_Init(void)
{
hcomp2.Instance = COMP2;
hcomp2.Init.InvertingInput = COMP_INPUT_MINUS_IO1;
hcomp2.Init.NonInvertingInput = COMP_INPUT_PLUS_IO1;
hcomp2.Init.LPTIMConnection = COMP_LPTIMCONNECTION_DISABLED;
hcomp2.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
hcomp2.Init.Mode = COMP_POWERMODE_ULTRALOWPOWER;
hcomp2.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
hcomp2.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING;
if (HAL_COMP_Init(&hcomp2) != HAL_OK)
{
Error_Handler();
}
}
But this is not working, because the initial setting of window mode made in line 14:
hcomp1.Init.WindowMode = COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON;
is cleared by the setting in line 32:
hcomp2.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
To fix the bug I had to change the CUBEMX generated code, changing line 32 into:
hcomp2.Init.WindowMode = COMP_WINDOWMODE_COMP1_INPUT_PLUS_COMMON;
It seems a bug of the HAL libraries, because in STM32L053 there is not a window mode setting bit in the register COMP2_CSR.
An alternate, weaker, solution would be to exchange the order of the init sequence between the two comparators.
No other has had this issue?
2020-10-19 09:10 AM
Hello @RCapr.1
Could you please share your ioc file to check the issue.
Best regards,
Nesrine