I have an embedded system based on a STM32 ARM Cortex M0+ microcontroller (STM32L051K6) and want to use it to convert an analog sinusoidal input signal into a digital pulse signal and do some SW calculations on the number of pulses (for additional digital busses, like I2C). For the application, it is very important to count every pulse without any loss and forward each pulse with a minimal delay of not more than few tens of microseconds to a digital output pin. One other limitation is the power consumption, and this was one reason for choosing this MCU and operating it only at 4 MHz.
My first approach was to use the ADC with DMA for the input signal to empower a discrimination with a lower and upper threshold, in order to be as flexible as possible for the future, since later in the field, in terms of amplitude (300mV-5V) and frequency (0.5Hz-20kHz) the input signal can vary widely. In other words, it should act as a dynamically programmable Schmitt-Trigger:
For this, I used the STM32 HAL library. It worked seamless, but quite too slow for my application, the delay between one input and output pulse is significant over 100us and with a quite wide jitter... I also had the idea to use an external circuit to trigger a comparator input of the MCU, but I wanted to evaluate the performance of all available possibilities first, before changing the PCB layout.
What are your impressions of my approach? Does anyone know a better/more performant solution with this kind of MCU?