Hello Everyone,
I am using the MKE15Z256 microcontroller and using the Analog Comparator module to do some logic checks and calculations on an external signal, which is a half sinusoidal signal, and I can successfully use it, but under a noisy environment, the situation of this calculation is very bad.
Is it possible or some way or workaround to increase the Hysteresis of the Analog Comparator, so that I can configure it for at least 0.5V instead of a few millivolts?
At the moment I am using Hysteresis 3 which means 33mV for Low-Speed Mode.
My problem can be depicted as shown in the below image, since the hysteresis value is very less, I am getting a lot of glitches in a noisy environment as shown in the left side image.
I have used the "acmp_interrupt" example as a base for my project.
Let me know if there is a way to solve or further improve this situation. Thanks in advance.
Hi,
Sometimes it is the easiest just to make an external comparator with an opamp and use a GPIO.
However, since the MKE15Z256 seems to have two comparators built in, you can configure one (CMP0) that acts on rising edge with a high reference voltage. The other (CMP1) you can configure to act on falling edge with a reference voltage 0.5V lower than the other comparator.
In the ISR for CMP0, you disable CMP0 and enable CMP1. In CMP1 ISR you disable CMP1 and enable CMP0. I'd give both CMP0 and CMP1 the same interrupt priorities.
Hope it helps.
Kind regards,
Troels
Thank You for your response.
Actually in our old designs we have used the external comparator using opamp and things were just fine, but to save few more cents, we thought to use the internal comparator of MKE15Z, as technically they both looks same.
Regarding the second suggestion of using two comparator, maybe in future I will try this, but as of now this not possible. (Reason is that we have two variants and another variant of this product uses the MKE15Z64, which only has one comparator, plus hardware change is also not possible at this moment)
So I understand that it is not possible to increase the hysteresis. In the past I tried to follow the following approach.
More information is available in the below post.
This method works really well in noisy environment, but in normal environment there is some problem at some point of time, maybe due to re-configuring, but I couldn't figure out what exactly it is.
If you have any other suggestions, please let me know.
I will also try to create a separate project, and try to share here. Thanks in advance.