2023-05-30 11:21 PM
Hi. I get a STM32H5 Nucleo board (MB1814) and configured comparator with neccessary settings using CubeIDE and LL library and got next generated piece of code.
int main(void)
{
NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
SystemClock_Config();
MX_GPIO_Init();
MX_COMP1_Init();
LL_COMP_Enable(COMP1);
SET_BIT(COMP1->CFGR1, COMP_CFGR1_ITEN);
while (1){}
}
void COMP1_IRQHandler(void)
{
LL_EXTI_ClearRisingFlag_0_31(LL_EXTI_LINE_29);
LL_EXTI_ClearFallingFlag_0_31(LL_EXTI_LINE_29);
SET_BIT(COMP1->ICFR, COMP_ICFR_CC1IF);
}
static void MX_COMP1_Init(void)
{
LL_COMP_InitTypeDef COMP_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_COMP);
LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA);
GPIO_InitStruct.Pin = LL_GPIO_PIN_0|LL_GPIO_PIN_5;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
NVIC_SetPriority(COMP1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
NVIC_EnableIRQ(COMP1_IRQn);
COMP_InitStruct.PowerMode = LL_COMP_POWERMODE_HIGHSPEED;
COMP_InitStruct.InputPlus = LL_COMP_INPUT_PLUS_IO2;
COMP_InitStruct.InputMinus = LL_COMP_INPUT_MINUS_IO3;
COMP_InitStruct.InputHysteresis = LL_COMP_HYSTERESIS_NONE;
COMP_InitStruct.OutputPolarity = LL_COMP_OUTPUTPOL_NONINVERTED;
COMP_InitStruct.OutputBlankingSource = LL_COMP_BLANKINGSRC_NONE;
LL_COMP_Init(COMP1, &COMP_InitStruct);
__IO uint32_t wait_loop_index = 0;
wait_loop_index = (LL_COMP_DELAY_VOLTAGE_SCALER_STAB_US * (SystemCoreClock / (1000000 * 2)));
while(wait_loop_index != 0)
{
wait_loop_index--;
}
LL_EXTI_EnableFallingTrig_0_31(LL_EXTI_LINE_29);
LL_EXTI_EnableRisingTrig_0_31(LL_EXTI_LINE_29);
LL_EXTI_ClearRisingFlag_0_31(LL_EXTI_LINE_29);
LL_EXTI_ClearFallingFlag_0_31(LL_EXTI_LINE_29);
LL_EXTI_DisableEvent_0_31(LL_EXTI_LINE_29);
LL_EXTI_EnableIT_0_31(LL_EXTI_LINE_29);
}
Using Power Supply
INM : 1.5V
INP : 1.8V
I can use function(LL_COMP_ReadOutputLevel(COMP1)) checking status when INM > INP or INM < INP,
but interrupts keep coming when the INP pin voltage is fixed).
Solved! Go to Solution.
2023-05-31 03:35 AM
I don't use the 'H503 but from the RM it appears, that COMP has two outputs: one direct to EXTI, which in turn provides edge sensitivity; and second, a dedicated interrupt (dedicated NVIC input) through a latch in COMP itself, see RM.
So, you probably want to use the former, rather than latter.
JW
2023-05-31 03:35 AM
I don't use the 'H503 but from the RM it appears, that COMP has two outputs: one direct to EXTI, which in turn provides edge sensitivity; and second, a dedicated interrupt (dedicated NVIC input) through a latch in COMP itself, see RM.
So, you probably want to use the former, rather than latter.
JW