2021-10-20

1. Extra hardware

In addition to the initial kit of MCU devboards, you should also have the following parts readily available for course work:

  • SG90 servo (handed out on day19)

  • EN12-HS22AF20 rotary encoder + switch

  • HC-SR04 ultrasonic range finder module

  • (handed out later) ATtiny85 MCU

This hardware gives us a uniform set of input and output thingies to have a reason to use timers and interrupts and GPIO (Digital IO). …​ and the MSP430 Family Users Guide :)

2. Quadrature rotary encoder

en12 encoder mech
en12 encoder signals
  • ON means a connection between A-C or B-C terminals.

  • Detent is the click resting position. Note that it’s possible to have the shaft position NOT in a detent — this is a potential source of problems in your code!

This construction then requires pull-up resistors on A and B up to the I/O supply voltage.

Check out the EN12 datasheet. Things that should (and will) terrify you:

  • sliding noise

  • contact bounce

Also be mindful of the contacts' max ratings: contact vs. switch. This lets you compute the smallest-value pull up resistor to be safe. (What is the largest safe value then??)

Example:

  • 3.3V supply implies that Rpull-up

  • 5V supply? Rpull-up ≥ Which R value to use?


Quadrature (two signals orthogonal to each other, e.g. 90°) signals are best represented using a state machine.

  • Draw the state machine for the [A, B] values starting from one detent and rotated CW (clockwise) until the next detent.

Search The Ganssle Group for articles about encoders:

We are covering UARTs next, so for a good time, Ctrl-F for "warned" in this article and notice that interrupts are involved: http://www.ganssle.com/articles/aserial.htm

3. Servo driver