Saturday, January 27, 2024

Fail Safe

Recently a 15-year old gas water heater stopped working; the pilot could be lit and would not stay on.  It can found on the internet a diagram of the gas water heater controller.  It becomes clear that the thermocouple is the issue.  Commonly, we use thermocouples as temperature measuring devices, but here it is actually a fail-safe device, which seems ingenious.    The thermocouple is an electricity generating device.  The thermocouple is in contact with the flame of the pilot and generates electricity (rated for 30mV) for a solenoid coil to open a gas valve.  So in case the flame is out, the gas value is automatically closed.  When we light the pilot, we push down a switch to bypass the solenoid to get gas flow and once the pilot flame is lit and the thermocouple is heated sufficiently to open the valve we can release the switch.  

The whole thermocouple assembly costs less than $10.  It can be appreciated the simplistic yet robust and rugged solution.  It is self powered and the very thing energizes it is controlled by it.  When the thermocouple fails, it closes the valve to keep the system in a safe state.  It is amazing that it has lasted for 15 years bathing in the flame constantly.  The life time is longer than the average life of water heaters.  Ultimately, oxidation probably claimed its life.  It is relatively easy and inexpensive to replace.

Monday, January 22, 2024

Wireless Remote Control Switch

Wireless remote control switch modules can be purchased for a few US dollars (around $7 for one pair).  They come with coil antennas.  They controls 4-channel output with Learning Code 1527, and can be programmed (using button presses) to operate in the momentary, toggle and latched mode.  The Learning Code 1527 has 20-bit identifiers(for over 1 million possibilities) and followed by 4-bit button code (for 16 states).    Most of the inexpensive modules have no marking on the ICs, so there is little information about the circuitry.

We can capture the RF wave using a oscilloscope with a loop antenna.

It appears the modulation is OOK.  Every burst is about 30ms.  It continuously transmits as long as the button is pressed.  It can be observed that the last few bits change depending on which key is pressed.  It appears that the bits are decoded according to the pulse duration or PWM encoded.  The bit 0 is a short duration of 0.3ms, and the bit 1 is about 0.9ms.   The total bit time is 1.2ms.  I counted total of 25 bits instead of expected 24 bits. Possibly the first bit is for synchronization only.

Something is also interesting about the 20-bit identifier code.  I was able to turn on and off using a key FOB from a different vendor and the code pattern is clearly different, but the receiver decodes it nevertheless, so it may not actually enforce the code or only subset of the code, or there is a master code.


Wednesday, January 10, 2024

Carbon Composition Resistors

I got a box of carbon composition resistors which are perhaps 40 or 50 years old.  They are things of past, having been replaced by carbon film and metal film.  They are probably made by Allen-Bradley, which were the main supplier of discrete resistors.  They have the distinct dark brown base color with 4 to 5 color rings (some have a visible 5th ring for temp coeff, yellow for 25 ppm/C, most are probably 100ppm/C which is brown same as the background), and are of straight cylindrical shape with sharp ends.  (The carbon film resistors have light brown base color and have end-cap bulge then tapered shape at the end).  The most common ones have 1/4W power rating, with body length 0.25", diameter 0.090",  lead length 1.5", diameter 0.024".   The 1/2W has body length of 0.385", diameter 0.140", and 0.032" lead diameter; and 1/8W body length 0.150", diameter 0.062" and lead diameter 0.015".

One thing I noticed is that how badly they are out of tolerance.  There are 5% resistors as indicated by the gold color ring.  But a lot of them are more than +5% of the nominal values.   All resistances are larger than the nominal value.  Aging or environment conditions (such as moisture) might have a large influence, which causes at least +5% resistance value shift.  But carbon composition resistors, which are not film construction, are more robust and have good surge performance, low inductance, and good high frequency capability.

Thursday, January 4, 2024

Low Power Design

Here we discuss a few techniques that are useful in low power designs.  As an example, we design a remotely operated switch which upon detecting a button push transmits a RF signal to turn on or off a remote device.  This switch is powered directly off a small 110mAh lithium ion battery, whose discharging characteristics is shown in a previous post.  We use the 8-pin PIC16F17115 microcontroller, which can operate over the voltage range of a single cell lithium ion battery, no voltage regulator is needed.

The switch is inactive most of the time, so the microcontroller is placed in the sleep mode, drawing less than 1uA.  The microntroller is waken up on an I/O change interrupt.  The peripherals that operate on the system clock which is stopped during are not drawing much power, but it is necessary to explicitly disable some of the peripherals, such as the fixed voltage reference, brown-out reset, comparators, which have significant current draw.

The battery voltage needs to be monitored.  To minimize part counts and reduce power consumption, we use the battery voltage as the voltage reference for the ADC and do the analog to digital conversion on the reference voltage, to back calculate the battery voltage; no external connection is needed and no power is wasted on a resistor divider.  When the battery is low (around 3.6V),  a warning is issued with a low duty cycle LED blink or a piezo buzzer beep.

We can eliminate the quiescent power consumption of the RF transmitter by powering the transmitter with an I/O pin (saving a power switch).  Note that the output drive is stronger when driving low.  So we set the I/O pin to open-drain and power up the transmitter by driving the output low.   This works for 10s mA; for larger current, a  power switch is needed.

For the button press detection, we use an external pull-up resistor of 1MOhms, instead of the internal pull-up which is about 30KOhms.  Pressing the switch on triggers a negative edge, which wakes up the microcontroller to transmit a turn-on RF signal.   And pressing the switch off triggers a positive edge, which powers up the RF transmitter to send a turn-off signal.    Here 4uA current is consumed.  The leakage current is 125nA (85C); the pull-up resistor can be increased to 4MOhms, reducing the current to 1uA, which would be.  We must be mindful of the slow rise time (with pin capacitance of 5-10pF), and use the Schmitt trigger input. 

In the awake state, after the microcontroller sets up the ADC to check the battery voltage, drives an output pin high to turn on the transmitter and drives another open-drain output low to transmit.  Here to save power, we put the microcontroller in the IDLE mode, so the microntroller CPU is halted but the peripherals continue to run.  We set up the timer to interrupt in 200ms, which would bring the microcontroller out of the IDLE state to turn off the transmitter.  Then the microcontroller goes into the sleep mode

If it is necessary to wake up from sleep periodically,  the watchdog timer can be used.  Here it may be necessary to wake up periodically to check the battery and beep when the battery is low as reminder to charge the battery.


Sunday, December 31, 2023

"Analog" Microcontrollers

Even the smaller microcontrollers continue to strive.  One direction of expansion is the analog domain.   Analog to digital converters (8 to 12-bit)  have long been integrated into microcontrollers.  Some microcontrollers have gone further in analog functions such as Cypress has an innovative line of PSOC microcontrollers with programmable analog and digital functions and Analog Devices has Precision Microcontrollers with 16-bit ADC, DAC and amplifiers which have perhaps the better spec than others.  The venerable PIC microcontrollers has the PIC16F171xx family with ADC, DAC, voltage reference, comparator and Op-Amp.   In particular, PIC16F17115 comes in a 8-pin package (DIP, SOIC and 4x4mm DFN), which is the size of a normal Op-Amp, but it still has 14KB Flash (8K words), 1KB SRAM, timers, I2C/SPI/UART,  configurable logic cells and internal oscillator up to 32MHz and it costs less than $1 in small quantity.  With essentially 6 pins to work with, it has the flexibility of mapping almost all peripherals to any I/O pins (some analog input pins are fixed).   If in-circuit programming is needed, 3 I/O pins have to be used during the programming, so care has to be taken not to have adverse effect when the programming signals are applied.  In order to use the MCLR pin as a general input pin (it cannot be used as an output pin), the high voltage programming mode (LVP=0) has to be used and the voltage on this pin can go up 9V.  The microcontroller can be put into the sleep mode for less than 1uA current draw; it can be waken up with a IO pin change or the watchdog timer.

It is commonly understood that the integrated analog functions are of poor performance compared to dedicated opamp, ADC ICs.   

Voltage Reference

There are two independent programmable gain amplifiers, with gains of 1, 2, and 4 for reference voltages of 1.024V, 2.048V and 4.096V.  The spec tolerance is +/-4 to 5% over the entire temperature range of -40C to 85C.  The reference voltages do not go to the pins, so we cannot measure them directly.  Indirectly, we use it as the DAC reference and measure the DAC output.    The reference is set to 2.048V and the DAC is set to the middle (0x80); the DAC output is measured 1.023V.

Op-Amp

For the 8-pin device, the output of the opamp is not brought out to a pin.  The input voltage is constrained by the maximum 5.5V supply voltage, which is better than most of the modern microcontroller.   Being a newer device, the datasheet is sketchy all parameters are characterized but not tested for VDD at 3V.  The typical offset is +/-1mV, GBW 2.3MHz, slew rate 9V/us, input noise 28nV/sqrt(Hz) at 10KHz (it is called low-noise) and while the input is rail-to-rail, but the output is within 0.15*VDD.   One of the advantages of being a programmable device is that the offset can be calibrated.  

We can set the opamp in the inverting configuration.  The positive input is set to the DAC output, which we can measure.  We measure the negative input; the difference is the offset voltage, which is measured to be 2.6mV, somewhat worse than expected.  We can also measure the gain set resistor values.   When pulling the negative input to ground, it draws about 15uA, so the resistance is about 68K for 8 resistive elements, or 8.5K each.

ADC

It is common to monitor supply voltage with a resistor divider.  When we operate on a single lithium ion battery cell directly for low power operation, we want to minimize the power draw.  We can use one IO pin to switch off the resistor divider.  There is another way that does not require the extra IO pin: use the supply voltage as the ADC reference, and digitize the fixed internal reference and back calculate the supply voltage.  Because this microcontroller supports differential ADC inputs,  it provides still another way: we can set the battery voltage as the positive input and the internal voltage reference 2.048V as the negative input and use the 2.048V reference as the ADC reference voltage.  We can sense the voltage up to 4.096V.