Power and Versatility in Small Packages

By European Editors

Contributed By Publitek Marketing Communications

Many thought that the growth of reasonably priced 16- and 32-bit microcontrollers could lead to the end of 8-bit MCUs. However, recent years have seen an explosion of uses that are ideal fits for the 8-bit products, boosted by the spread of M2M-type applications. With the Internet of Things predicted to grow rapidly in the coming years, it seems that the 8-bit products could find more and more markets.

What is exciting about this resurgence is the versatility of the 8-bit parts. Whatever the application, if a small amount of processing power is needed, there can be an 8-bit unit to fit the bill. The Internet of Things is destined to see more requirements for such processing at the edge of networks, where devices are small but the tasks are no less crucial. This is a perfect environment for 8-bit microcontrollers to flourish.

Examples and applications

This article will look at three very different examples that show this versatility with 8-bit microcontrollers. In the first case, it will look at how the STM8S207 from STMicroelectronics can provide the decoding needed to form a smartcard interface. The article will then show how the PIC16F1947 from Microchip can help control lighting in commercial and industrial buildings. Finally, the article will consider how an Atmel ATTiny20 microcontroller can provide the processing necessary for a proximity sensor in smartphones and other wireless devices.

Smartcard interface

Using the smartcard mode of the STMicroelectronics’ STM8S207, it is possible to develop a smartcard-based application using reduced firmware and hardware resources. The STM8S207 is a 24 MHz 8-bit MCU with up to 128 kbyte of Flash, integrated EEPROM, 10-bit analog-to-digital converter, timers and two UARTs, with SPI, I²C and CAN interfaces.

This application uses the device’s UART1 smartcard mode, which supports asynchronous protocol smartcards as described in ISO 7816-3, Class A, which covers cards operating at 5 V; devices operating at 3 V are categorized as Class B while those at 1.8 V are Class C. The standard describes the relationship between the smartcard and the reader as one of slave, referring to the smartcard itself, and master, referring to the reader. Communications start by the reader signaling the smartcard and continue when the smartcard responds. The communications channel is single threaded, in that once the reader sends a command to the smartcard, it is blocked until the response is received.

With the smartcard mode enabled, the UART1 must be configured as eight data bits plus parity and 0.5 or 1.5 stop bits. A 5-bit prescaler and the smartcard clock generator provide the clock to the smartcard. GPIO pins and software provide the rest of the functions needed to interface to the smartcard.

ISO 7816-3 defines the bit timers for the asynchronous protocol in terms of elementary time units (ETUs). These are related to the clock frequency input to the card. The length of an ETU is a bit time. The UART1 transmitter output and receiver input are internally connected. To transmit data from the STM8S207 to the smartcard, UART1 must be set up in smartcard mode.

The smartcard clock generator provides a clock signal to the connected smartcard. The smartcard uses this clock to derive the baud rate clock for the serial I/O between the smartcard and another UART1. The clock is also used for the CPU in the card, if present. Operation of the smartcard interface requires that the clock rate to the card be adjusted while the CPU in the card is running code so the baud rate can be changed or the performance of the card be increased. The clock is used as the CPU clock for the smartcard, therefore updates to the microcontroller clock rate must be synchronized to the smartcard clock. The clock high or low pulse widths must not be shorter than either the old or the new programmed value.

An analog interface is needed for 3 and 5 V smartcards. In this application, the ST8024 was used for this purpose and placed between the smartcard and the STM8S207. This interface is shown in Figure 1.

Image of smartcard interface hardware connection

Figure 1: Smartcard interface hardware connection. 

Error handling is performed on each byte by looking at the parity bit. If this does not correspond to the parity of the transmitted data, then an error must have happened. The receiving side will then signal that it wants the byte to be retransmitted. This is done by holding the I/O line low, rather than high as is normal. When the transmitting side detects this, it resends the byte. With data sent from the card to the reader, the STM8S207 can detect a parity error on received data via hardware by pulling down the data line during the stop bit. With data sent from the reader to the card, the smartcard pulls down the I/O line to signal that parity has occurred. In this case, the STM8S207 detects a frame error via software. The smartcard library checks whether a parity error has occurred and, if so, manages it.

After a byte is sent from the microcontroller to the card, the smartcard captures the data sent on the I/O line. If a parity error is detected from the card, the I/O line is pulled down during the stop bits. A frame error event occurs and the error-handling function resends the last data.

Power is not applied to the contacts when a card is first inserted into the reader as the card’s chip can be damaged if power comes through the wrong contacts. Power is only started once an edge detector determines that the card is correctly aligned with the contact points. The contacts are then brought to a coherent idle state before a reset signal is sent to the card. An initial voltage setting of 5 V is always applied despite some microprocessors operating at 3 V when in an I/O state. The I/O contact is set to reception mode on the reader side and a stable clock is applied. The reset line is in a low state, in which it must remain for at least 40,000 clock cycles before a valid reset sequence can be started by the reader, raising the reset line to a high state. Data transfer between the reader and the card takes place through the concerted action of the clock and I/O lines.

Industrial and commercial lighting control

Finding a standard way to control lighting in commercial and industrial buildings has led to the creation of DALI – the digital addressable lighting interface – in Europe. This is an open standard for forming lighting control networks as part of a building automation system. A typical DALI network consists of a controller and various lighting devices such as electrical ballasts and dimmers. The controller monitors and controls each light through bidirectional data exchange. DALI-type ballasts can run at lower power levels than standard magnetic ballasts, hence the interest in the technology from the industrial and commercial sectors.

Via a two-wire serial bus, the controller sends 16-bit Manchester encoded data packets and the ballasts respond using an 8-bit data packet. There can be more than one controller in a system and there are sixty-four channels (individual addresses) for ballasts to be connected to one interface line.

Unlike analog systems, DALI does not require hard-wired power circuit control groups. The combination of individual ballast addressing with digital switching eliminates vertical switch wiring. DALI has a free-form layout. Daisy chain, star topology and multi-drop are all allowed, as is combining two or more topologies.

The physical low level or active state for DALI has been defined with the interface voltage of less than 9.5 V. The high-level condition, or DALI idle, is an interface voltage between 9.5 and 22.5 V, the most common being 16 V. Maximum system current is limited to 250 mA. Response time of the current limiter circuit is less than 10 µs. Each component connected to the interface can consume a maximum of 2 mA. Connectors are non-polarized at the receiver. DALI is usually optically isolated from the microcontroller and has a data transfer rate of 1200 bit/s. The microcontroller can be an 8-bit unit, such as the PIC16F1947 from Microchip. There are no specifications or recommendations on how to implement the circuit design for DALI, but the optically-isolated circuit shown in Figure 2 will interface a PIC16F1947 to the DALI bus.

Image of isolated communications circuit diagram

Figure 2: Isolated communications circuit diagram. 

The PIC16F1947 is a 64-pin Flash-based 8-bit CMOS microcontroller. The RISC CPU has only forty-nine instructions to learn. Operating speed is from DC to 32 MHz with a DC to 125 ns instruction cycle. Standby current is typically 60 nA at 1.8 V and operating current typically 7.0 µA at 32 kHz, 1.8 V.

DALI uses Manchester (bi-phase) encoding to send the start bit and the information bits. The information rate is 1200 bit/s with an acceptable range of ±10%. One bit time is 833.33 µs. The most significant bit (MSB) is sent out first. Any packet sent between the control device and control gear is a bi-phase encoded packet. The packet is then decoded, and the address and messages are processed accordingly. The lighting communication board discussed here has a PIC16F1947 microcontroller unit along with an isolated DALI communication circuit interface and a simple power supply.

Since the signal from the DALI bus is inverted by the optocoupler, the PIC microcontroller views the Manchester encoding and decoding in the following way: the Manchester code is a digital encoding format in which the symbol ‘1’ is represented by a falling edge (high followed by low), and the symbol ‘0’ is represented by a rising edge (low followed by high). Both the high and low pulses have equal width, which is equal to half the bit period. The outgoing message is encoded using a timer, and the packet is sent out using one of the pins. An interrupt is generated using the timer every 416.67 µs, or half-bit time, and this is where the phase of the signal needs changing. If it was sending out a ‘1’ as the bit, the first half is ‘1’ and at the interrupt the signal is reversed and vice versa. As a result, the output is a Manchester-encoded packet, ready to be decoded by the control gear if sent by the control device, or decoded by the control device if sent as a response by the control gear back to the control device.

The decoding is more complicated. As the reception starts, the receiver, whether it be the control gear or the control device, makes sure the packet is received in its entirety starting with the start bit, then an 8- or 16-bit message and, finally, at least two idles to indicate the stop bit. The decoding is done using the external interrupt pin on the PIC16F1947. This pin is specially used to generate an interrupt every time the phase of the incoming signal changes. The timer is used to generate an interrupt every 3/4th of the bit, so the value is measured at that point, and that decides whether the bit is a ‘0’ or a ‘1’. The timer is reset and reloaded in the middle of the bit when the external interrupt happens, and that keeps errors due to drifting in check.

This DALI circuit with a simplified power supply and Manchester-encoded communications implemented with the PIC16F1947 can form the foundation for implementing DALI commissioning and commands for both the control device and the control gear.

Proximity sensing for RF energy

One of the ongoing effects of the increased use of smartphones and other wireless devices is the worry of the health damage to humans of increased exposure to radio frequency (RF) energy. As the number of wireless-based M2M devices grows, these worries are likely to increase. Various telecommunications agencies have thus set limits on what they regard as safe exposure to RF energy. These limits are referred to as the specific absorption rate (SAR), which is the amount of RF energy absorbed by the body when using an RF device. Manufacturers have to comply with these limits. Designers must then reduce the RF output of the device when it is close or in contact with the human body. This application uses an Atmel TinyAVR device in a circuit to detect whether a device is close to the user.

The Atmel ATTiny20 is an 8-bit AVR RISC-based microcontroller that combines 2 kbyte ISP Flash memory, 128 byte SRAM, 12 general-purpose I/O lines, sixteen general-purpose working registers, an 8-bit timer-counter with two PWM channels, a 16-bit timer-counter with two PWM channels, internal and external interrupts, and an eight-channel 10-bit analog-to-digital converter. Additionally, the device includes a programmable watchdog timer with internal oscillator, a slave two-wire interface, a master-slave serial peripheral interface, an internal calibrated oscillator, and four software-selectable power-saving modes. The device operates between 1.8 and 5.5 V. By executing instructions in a single clock cycle, the device achieves throughputs approaching 1 MIPS per MHz, balancing power consumption and processing speed.

Various materials can be used to form the proximity sensor, the simplest being a piece of copper tape or a few centimeters of wire. The sensor needs to be placed as close as is mechanically possible to the surface of the device that will be in contact with the user. For a smartphone, this would be the screen side near the earpiece. It also needs to be kept away from metal structural components and large areas of ground, as these can reduce the sensitivity. The electric field from a flat disc sensor is evenly projected away from both sides of the sensor at right angles. The top and bottom surfaces are equally sensitive to an object entering the field, but if the sensitivity in one direction needs to be reduced then a mesh-filled ground plane can be used on that side.

The shape of the sensor is not important. In this example, a rectangular copper tape sensor is being used. This is about 8 mm high by 25 mm long and mounted on the bottom side of a 1 mm thick piece of polycarbonate, which in turn is mounted on standoffs to provide some isolation from the surface of the desk. The size and sensitivity of the electric field are affected by the size of the sensor; the larger the sensor, the larger the field and the greater the sensitivity. A larger sensor though takes more time to charge, increasing power consumption and response time. However, in the case of smartphones and other wireless devices, the size of the device will be limited by the space available. A single-channel proximity sensor design for developing and tuning a capacitive proximity sensing system is shown in Figure 3.

Image of capacitive proximity sensing system

Figure 3: Capacitive proximity sensing system. 

This design, based on an Atmel ATTiny20 MCU, provides headers for device programming and touch system debug data to simplify proximity sensor tuning. The proximity sensor is connected to a port pin via a 10 kΩ series resistor. The firmware comes from Atmel’s free QTouch library, which provides sensor support for most of the company’s MCUs.


The spread of more and more connected devices has and still is providing opportunities for the use of 8-bit microcontrollers. As the Internet of Things revolution continues, processing power is going to be needed at the edge, in small devices. Often the processing required is well below the capabilities of 16- and 32-bit devices, and it is here that a resurgence of the use of 8-bit microcontrollers is expected. This article has given three widely different examples of the way these units can be deployed, showing a versatility that could prove invaluable in the years to come.

Publitek Logo

Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of Digi-Key Corporation or official policies of Digi-Key Corporation.