An OpAmp Saves the Day – Schmitt Trigger

Lately I have been working on an impractical project – to animate an ancient Imation tape cartridge I found. The tape has a clear face and an aluminum plate back, with very clean and precise reels. One of my colleagues at work promised a hundred bucks to me if I could animate it. Ha! Challenge! (not that I would take his money)

Seemed like a simple project – small motor, some pwm for speed control and see it roll. Never is that simple. I quickly came to the conclusion that setting a PWM for the speed is not enough, it would be best if I can set an absolute speed and automagically adjust power as needed. To do this, I dug into my parts bin for an IR detector. A handful of these came from a very expensive baby rocker – one of those that simulates the rocking motions of a mother’s arms.

In theory, the operation of the IR sensor is quite simple. An IR led shines light on the target and the sensor measures the reflected light. If the target is reflective (white) the signal is high and if the reflected light is low (black) the signal is low. Dump the sensor output to an interrupt pin on the Atmega and count each falling edge to calculate RPM. The signal should be something similar to a sine wave and if the peak and low voltages are +5 to zero, it should work. In an ideal world.

Motor with IR sensor

IR sensor reads black tape patches on motor spindle.

On the scope everything looked good, and initial testing also seemed good, but every once in a while something would go nuts in the control software and stop the motor. It wasn’t until I dumped the rotation count to a serial port that I discovered the problem. In place of the expected 10-60 ticks per interval, I was getting a few thousand ticks per interval. I tried shielding the sensor from light, double checked all my wiring, even moved the sensor wires away from possible interference sources. Still garbage output.

Schmitt Trigger circuit

The signal quality improved marginally with the addition of a resistor in series and I also tried some small ceramic caps to filter the noise. No luck. The tick count went down a little, but was still garbage. A bit of digging in Google reminded me to use an OpAmp to filter the signal – a Schmitt Trigger.

A Schmitt trigger sets the output voltage high or low depending on the input signal being higher or lower than the threshold voltage set by R1 and R2. In order to keep the output noise down, R3 adds or subtracts from the threshold voltage. If the output is high, it increases the relative threshold voltage, and if the output is low, it decreases the threshold voltage. R3 can be adjusted with a potentiometer to set the desired trigger sensitivity.

Scope top trace shows analog signal, bottom trace shows OpAmp output.

Scope top trace shows analog signal, bottom trace shows OpAmp output.

After I added the Schmitt Trigger circuit between the IR detector and the interrupt pin, a quick check on the scope showed a nice square wave output heading to the Atmega controller. Yay! The Atmega was happy too, reporting a sane hit count corresponding to the frequency count shown on the frequency counter.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s