2020-11-12 08:11 AM
Hello
I am using a STM32L476VG. I want to use pin PC4 (named 'comp_negative') and PC5 (named 'comp_positve) for comparator inputs. Reading through 'stm32l4xx_hal_comp.c' it gives some idea how to set this up. I have also seen someone else has had a similar task to do on this forum (https://community.st.com/s/question/0D50X00009XkenRSAR/stm32f072rb-comparator-to-timer2-frequency-counter). Will their one work for my needs?
Any help is gladly appreciated
2020-11-12 04:24 PM
I don't use Cube/HAL, but the COMP and timer chapters are relatively clear. You need to set the pins in GPIO_MODER as Analog; in COMP1_CSR set INPSEL and INMSEL appropriately for the two pins; and in the selected timer set the respective Option Register to select the COMP1_OUT into ETR and use External Clock mode 2.
But, if the input signal is 0-3.3V square wave, why don't you use it directly as a digital signal?
JW