More Sensors

From CCRMA Wiki
Revision as of 13:22, 13 August 2007 by Wikimaster (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Piezo Pickups

Piezo elements are used like a contact microphone. The material (crystal) forces electrons to move when it is shocked or vibrates. We connect two leads to it, which then can be amplified and smoothed with filters, making it more usable.


Are used to sense motion and acceleration.

Quadrature Encoder


The above diagram demonstrates two signals in a quadrature relationship. The most common sensor we use that has this kind of signal is a rotary encoder or shaft encoder. Rotary encoders are normally optical (expensive) or mechanical (cheap). A mechanical encoder works simply by connecting the Phase A and Phase B pins (pins 1 and 3 in the diagram below) to a common pin (pin 2), according to a quadrature pattern. Wired up as in the diagram, pins 1 and 3 will go to ground when when connected to pin 2, and will be high when they are not. Mechanical contacts inside the encoder create the quadrature signals as above. An optical encoder may function similarly using LEDs and phototransistors as in the IR sensor above, with alternating dark/light patterns applied in quadrature.

Note that Phase A leads Phase B by 90 degrees when looking from left to right. Looking from right to left the opposite is true. We use quadrature encoders with the external interrupt on a microcontroller. By connecting the Phase A pin to an interrupt, we can generate an interrupt SIGNAL (function call) every time it transitions from low to high. In the interrupt, we can check the state of the Phase B pin. If B is low when A goes high, then we have moved to the right. If B is high when A goes high, then we know we have moved to the left. Shaft encoders are rated with a number of counts or ticks per complete rotation. Note that if we attach both Phase B and Phase A to external interrupts, we can double the resolution.

Encoder filter.png

This filter circuit helps to stabilize the output of the shaft encoder and reduces noise by introducing pull-up resistors and low pass filters with cut-off frequency of ~ 1.6kHz on each of the two output pins.


Shaft encoders normally turn infinitely. If we know the number of counts, we can keep track of the absolute position of the shaft. By measuring the time between ticks (or between some number of ticks), we can calculate velocity. Also, using an IR reflective object sensor and some custom printed paper, for example, you can build your own quadrature encoder. There is NO A/D conversion involved in using a shaft encoder! Shaft encoders are commonly used in automation and robotics conjunction with motors to achieve accurate positioning. They are also ubiquitous on volume knobs in stereo equipment.


Motors can also be controlled my the AVR. There are some extra parts involved. Foremost of course is a DC motor. It also needs a motor controller, which supplies the needed voltage and current to the motor, including the direction of current. The direction of current through the motor determines the rotational direction of the motor: clockwise or counter clockwise.

Pulse Width Modulation (PWM) is a technique that we use to control the speed of the motor. A DC motor's speed is determined by now much current is flowing through it. Intuitively, if we supply a low DC current, the motor will spin slowly. It will spin more quickly with a higher current. As it turns out, it is difficult to create a circuit that supplies a varying current like this. So, we use PWM. Pulse Width Modulation used two discrete values of current (none and full) in pulses that average to the desired current value you need to make the motor act as you want. The longer the pulse, more average current flows through the motor, and the faster it goes. We speak of the length of the pulse in terms of something called the Duty Cycle.

PWM can be used to control the output intensity of LED's, too!