# How to implement programmable Schmitt trigger?

I am trying to build a Schmitt trigger that would allow adjusting High and Low threshold values with a microcontroller.

simulate this circuit – Schematic created using CircuitLab

I could replace R1-R2 with a DAC, but how do I adjust the feedback resistor R3? Is the trigger going to work properly if I replace R3 with a digital potentiometer?

• why not use a dual comparator setup with two DAC/digital pot based setpoints (maybe DAC through a latched output analog multiplexer to get more set point channels) to get the hysteresis and lots of flexibility Nov 30, 2015 at 17:55
• ah nevermind, I was thinking one step too far ahead, each of the comparators I mentioned basically need to be schmitt triggers anyway. don't mind me.. Nov 30, 2015 at 17:57
• Hmm. If you're already using an MCU, can you just read the input signal with an ADC and produce the output with an MCU pin? Then, the threshold values could just be numbers in your code. Nov 30, 2015 at 17:57
• @Gregd'Eon there is merit in that, but offloading this sort of closed loop control onto hardware circuitry is better in the long run. just setting setpoints is an easy and low speed task, compared with fully monitoring an analog signal and being able to respond correctly every time Nov 30, 2015 at 17:59
• @Gregd'Eon - using an ADC would be the best option, unfortunately I'm dealing with relatively fast signals (~500kHz). This would require sampling rate of at least 2.5MSPs to get adequate results. Since all I need is to count pulses, I decided to go with hardware implementation. Nov 30, 2015 at 18:05

Completely replacing R1-R2 with a DAC may give you mixed results because the circuit saves a part by relying on the voltage divider's parallel impedance R1||R2. You'll need to ensure that the DAC has the same output impedance as seen from R3.

simulate this circuit – Schematic created using CircuitLab

That will adjust the threshold while keeping the hysteresis constant. To adjust the hysteresis, you can now replace R1||R2 and R3 with a digipot.

• Would it work if I omit the DAC and simply connect a digipot R1||R2 between Vcc and R3? Nov 30, 2015 at 18:09
• @AshtonH. Maybe. I assume you're turning the fixed divider into a pot? The hysteresis will depend on how close you are to a rail because the parallel impedance changes. (equivalent of R1||R2) Nov 30, 2015 at 19:26

This is a real proper way of doing it for the pedants amongst us (and that usually includes me).

Use two comparators (one for the high level threshold and one for the low level threshold). Use two DACs (or digipots) to set the thresholds for each comparator. Feed the input signal into both comparators.

The two comparator outputs can be used to set a flip flop and reset a flip flop respectively.

• I was kind of hinting at that in the question's comments, but this is way better, +1 Nov 30, 2015 at 22:35
• @KyranF so you did - great minds think alike (or is that fools?). I've recently had to implement something like this at work so it's fresh. You should have made an answer out of it (too late muhuhahaha). Nov 30, 2015 at 22:38
• The idea of two comparators driving a flip-flop isn't that new - actually it's implemented in the well-known NE555 timer chip. Using THR and TRIG as threshold inputs (driven by DAC outputs) and forcing the input voltage into CONT ("forcing" means working agains the resistor VCC/CONT) should solve the problem at hand. Remember that TRIG is compared to CONT/2, while THR is compared to CONT. Nov 30, 2015 at 22:54
• @MichaelKarcher yes, absolutely correct but you don't have such simple control of the individual thresholds but, point taken. Nov 30, 2015 at 22:55
• There is no reliance on the output level for determining absolute threshold levels. A single opamp creates two threshold levels by involving positive feedback and therefore the output level and power voltage level are factors that affect thresholds. Dec 1, 2015 at 19:08