Bang-Bang

I took a break from working with a “big” microcontroller to work with a little one. The PIC12C671 is definitely little when compared with the PIC18F66K80 I am using in the GenPIC utility PCB. With less than 2k of program space and a mere 128 bytes of RAM it is definitely limited. Consider that the chip only has eight pins, two of which are power and ground, leaving six I/O pins to get the job done. No problem, I only need two I/O pins for this task and that few bytes of RAM is more than enough!

A simple heater using a bang-bang controller.
A simple heater using a bang-bang controller.
This project is pretty basic… A bang-bang heater controller. This simple form of controller simply turns on and off as the temperature (or some other controlled parameter) goes up and down, there is no attempt to vary the output, all or nothing. Bang on, bang off, or simply a bang-bang controller as it is known in the trade.

A bang-bang controller is inherently reliable and stable because it uses two different control setpoints, a high and a low. Because these control points are separated by a large margin, called hysteresis, the controller will not oscillate or rapidly turn on and off. In this case the heater will not turn on until the temperature falls below 10°C and will not turn back off until the temperature rises above 15°C. That five degree margin is called hysteresis, and ensures a good period of time between on and off.

Continue reading “Bang-Bang”

Taming a Rotary Encoder

The rotary encoder is a popular input device for many microcontroller devices. A knob that can be used to increase or decrease a setting with a nice tactile click for each increment. You can even get an integral pushbutton, just rotate for the setting then press the same knob to enter. With some clever programming you can create a one device user interface using only the encoder.

GenPIC Development Setup
The development setup in use generating the first software release for the GenPIC utility PCB

I have integrated a rotary encoder in the GenPIC utility board. With the combination of an LCD display and the rotary encoder you have all the ingredients for a functional user interface arranged neatly for a panel mount unit.

In the past I have simply set an interrupt to fire on the edge of one channel, then sampled the opposite channel to detect the direction. With the addition of a small delay to debounce the result. This worked well in previous devices, but this time I encountered trouble, the direction sampling was erratic, the value going up when it should have gone down and vice-versa.

Breaking out my logic analyser I found out why, this particular encoder proved to be somewhat noisier than I had seen in the past, with notable periods of bouncing signals.

Continue reading “Taming a Rotary Encoder”