Sensors are a key element for the highly-connected ‘Internet of Things’ (IoT) networks that are increasingly being used in ‘smart city’ and ‘smart grid’ designs. Digital interfaces for the latest sensors, from temperature sensors from Analog Devices and pressure sensors from Measurement Specialties to humidity sensors from GE Sensing, are simplifying the interface to the IoT to enhance the reliability and functionality of systems.
The Internet of Things starts with measurement. Being able to take data from devices anywhere in the world, linked up via the Internet to ‘big data’ information systems, provides the foundation for control and optimization. This is at the heart of smart city and smart grid developments around the world.
Connecting sensors up to the Internet of Things is relatively simple in some cases, and in others needs more consideration. The improvement in CMOS process and packaging technology is allowing higher levels of integration so that sensors can provide regulated digital outputs with protocols that are acceptable to microcontrollers. The data is then packetized for the Internet of Things, ideally using the IPv6 protocol for direct connection. Interim steps packetize this data for a local network that then uses a local gateway to convert the header data of the packet into IPv6 for wider access over the Internet.
The connection from the microcontroller can be handled in a number of ways, from wired Ethernet to power-line links over the existing power cabling. However, the most common approach is to use a wireless transceiver connected to the microcontroller to provide a link back to a central hub and then onto the Internet. While this has been a common approach to date, the emphasis of the Internet of Things is to have more direct access to the sensor node. This allows sensors to be added to a network more easily, rather than be limited by the address space of a hub device. The different architectures have an impact on the choice of the microcontroller. Simple 8-bit devices can be used for direct links to a wired network to a hub, but for handling higher-level protocols such as Ethernet or IPv6, 32-bit processor cores able to handle a protocol stack are required. These are increasingly common and are now adding general-purpose analog-to-digital converters (ADCs), which can be used to simplify the design of the sensor node.
However, the sensors can have their own ADCs that are optimized to the resolution of the sensor data and assist with minimizing the power consumption of the node. These can then be interfaced to the microcontroller via a serial UART or general-purpose I/O pins, or through an I²C two-wire interface. This then delivers the data direct into the registers in the controller where it can be accessed by the protocol stack.
One example is the ADT7320, a high-accuracy digital temperature sensor with the wide industrial temperature range (−40°C to +150°C), which is necessary for IoT applications as the sensor may be placed in extremely hostile environments.
The sensor is housed in a 4 × 4 mm LFCSP package and contains an internal band gap reference, a temperature sensor, and a 16-bit ADC to monitor and digitize the temperature to a resolution of 0.0078°C. The ADC resolution is set to 13-bits by default, giving a resolution of 0.0625°C, but this can be changed by the user through the serial interface.
The sensor output is digitized by a sigma-delta (Σ-Δ) modulator, which is also known as the “charge balance” type ADC (Figure 1). This type of converter uses time-domain oversampling and a high-accuracy comparator to deliver 16-bits of resolution in an extremely-compact circuit.
Figure 1: The ADT7320 temperature sensor uses a Σ-Δ modulator to convert analog data for the SPI output to a microcontroller.
The Σ-Δ modulator consists of an input sampler, a summing network, an integrator, a comparator, and a 1-bit digital-to-analog converter (DAC). This architecture creates a negative feedback loop and minimizes the integrator output by changing the duty cycle of the comparator output in response to changes in the input voltage. The comparator samples the output of the integrator at a much higher rate than the input sampling frequency. This oversampling spreads the quantization noise over a much wider band than that of the input signal, improving overall noise performance and increasing accuracy for the sensor data. The modulated output of the comparator is encoded using a circuit technique that results in the temperature data output via an SPI pin.
For data converters there are generally four operating modes: normal mode, one-shot mode, 1 SPS mode, and shutdown mode. These modes apply generally to any data-capture device, and are a key design element for developing an IoT sensor node.
In continuous-conversion mode (the default power-up mode), the ADT7320 runs an automatic-conversion sequence. During this automatic-conversion sequence, a conversion takes 240 ms to complete and the ADT7320 is continuously converting. This means that as soon as one temperature conversion is completed, another temperature conversion begins. Each temperature conversion result is stored in the temperature value register and is available through the SPI interface, and the read operation provides the most recent converted result.
There are two key pins for the operation of the sensor. The CT pin is an open-drain output that becomes active when the temperature exceeds a programmable critical-temperature limit. The INT pin is also an open-drain output that becomes active when the temperature exceeds a programmable limit. The INT and CT pin can operate in either comparator or interrupt mode.
On power-up, the first conversion is a fast conversion, taking typically 6 ms. If the temperature exceeds 147°C, the CT pin is asserted low. If the temperature exceeds 64°C, the INT pin is asserted low, and this fast conversion temperature accuracy is typically within ±5°C. The conversion clock for the part is generated internally, so no external clock is required until reading from and writing to the serial port.
The measured temperature value is compared with a critical temperature limit (stored in the 16-bit TCRIT setpoint register), a high temperature limit (stored in the 16-bit THIGH setpoint register), and a low temperature limit (stored in the 16-bit TLOW setpoint register). If the measured value exceeds the high or low temperature limits, the INT pin is activated; if it exceeds the TCRIT limit, the CT pin is activated. The polarity of the INT and CT pins is programmed through the configuration register, which is also used to program the interrupt mode.
This can be used to provide a flag to an IoT monitoring application when temperature thresholds are exceeded. The continuous mode runs on a low duty cycle to reduce the power consumption, and when the threshold is exceeded (either too hot or too cold) a packet can be sent to the monitoring application with the temperature data.
While continuous conversion is the default mode, it may be more appropriate for an IoT application to use a one-shot reading when the node is queried by the remote monitoring application.
When one-shot mode is enabled, the ADT7320 immediately completes a conversion and then goes into shutdown mode to save power. This is enabled by setting Bits [6:5] of the configuration register (Register Address 0x01) to 01.
After writing to the operation-mode bits, wait for at least 240 ms before reading back the temperature from the temperature value register. This delay ensures that the ADT7320 has adequate time to power up and complete a conversion. To obtain an updated temperature conversion, reset Bits [6:5] of the configuration register to 01.
All the data is linked to the microcontroller via a four-wire SPI interface (Figure 2). The interface has a data input pin (DIN) for writing data to the device, a data output pin (DOUT) for reading data back from the device, and a serial data clock pin (SCLK) for clocking data in and out. A chip-select pin (CS) enables or disables the serial interface. CS is required for correct operation of the interface.
Data is clocked out on the falling edge of SCLK, and data is clocked into the device on the rising edge of SCLK. All the data transactions on the bus begin with the master taking CS from high to low and sending out the command byte to indicate whether the transaction is a read or a write and provide the address of the register for the data transfer.
Figure 2: The interface from the ADT7320 digital temperature sensor to a microcontroller in an IoT sensor node.
Bit C7, Bit C2, Bit C1, and Bit C0 of the command byte must all be set to 0 to successfully begin a bus transaction, as the interface does not work correctly if a 1 is written into any of these bits.
Bit C6 is the read/write bit where 1 indicates a read, and 0 indicates a write. Bits [C5:C3] contain the target-register address and one register can be read from or written to per bus transaction.
The same approach can be taken with digital humidity sensors such as the HTU21D from Measurement Specialties. This is embedded in a reflow-solderable Dual Flat No-leads (DFN) package of 3 x 3 mm footprint and 1 mm height and provides calibrated, linearized signals in digital, I²C format.
The HTU21D sensors are dedicated low-power humidity and temperature plug-and-play transducers for OEM applications, where reliable and accurate measurements are needed with a direct interface to a microcontroller for an IoT sensor node.
For humidity sensing, the calibration is vital, and every sensor is individually calibrated and tested, with the lot identification stored on the chip so that it can be read out by command. The resolution can be changed by command (8/12-bit up to 12/14-bit for RH/T), low battery can be detected, and a checksum is included to improve communication reliability.
The serial clock input (SCK) is used to synchronize the communication between microcontroller and HTU21D sensor (see Figure 3). As the interface consists of fully-static logic, there is no minimum SCK frequency.
Figure 3: Interfacing the HTU21D humidity sensor to a microcontroller via I²C in an IoT sensor node.
The DATA pin is used to transfer data into and out of the device. For sending a command to the HTU21D sensor, DATA is valid on the rising edge of SCK and must remain stable while SCK is high. After the falling edge of SCK, the DATA value may be changed. For safe communication, DATA is valid for tSU and tHD before the rising and after the falling edge of SCK. For reading data from the HTU21D sensor, DATA is valid for tVD after SCK has gone low and remains valid until the next falling edge of SCK.
An external pull-up resistor (e.g. 10 kΩ) on SCK is required to pull the signal high only for open-collector or open-drain technology microcontrollers. In most of the cases, the pull-up resistors are internally included in I/O circuits of the microcontroller. After power-up, the device needs at most 15 ms while SCK is high for reaching idle state (sleep mode), in order to be ready to accept commands from the controller. No command should be sent before that time. Soft reset is recommended at the start, lowering the DATA line while SCK is high followed by lowering SCK. To stop transmission, a stop bit has to be issued. It consists of pulling the DATA line high while SCK is high preceded by pulling SCK high.
When HTU21D sensors are run by communicating with the standard I²C protocol, an 8-bit CRC can be used to detect transmission errors for all the read data transmitted by the sensor. The default resolution is set to 12-bit for the relative humidity and 14-bit for temperature readings. Measured data are transferred in two-byte packages, in frames of 8-bit length where the most significant bit (MSB) is transferred first (left aligned). Each byte is followed by an acknowledge bit. The two status bits, the last bits of LSB, must be set to ‘0’ before calculating physical values.
Another sensor with an I²C is GE Sensing's NPA range of differential pressure sensors. Packaged in a 14-pin surface-mount SOIC, the NPA series is available in Gauge, Absolute, or Differential pressure ranges with either mV, amplified analog, or digital outputs.
The NPA-700 series provides digital output data using the industry-standard I²C protocol. Bit rates up to 400 kHz are supported, compatible with the Standard-mode (Sm) and Fast-mode (Fm) standards. Devices are supplied with a slave address of 0x28 as standard. To read data from the NPA sensor, the I²C master device sends 8-bits, the 7-bit slave address (0x28 for standard devices) and the 8th bit = 1 to designate a read request. The NPA sensor then sends acknowledge (ACK) to indicate success.
The NPA has three I²C read commands:
- Read_DF2: Pressure (2 bytes)
- Read_DF3: Pressure (2 bytes) + Temperature (1 byte)
- Read_DF4: Pressure (2 bytes) + Temperature (2 bytes)
The number of data bytes returned by the NPA sensor is determined by when the I²C master device sends the NACK and stop conditions. The sensor first transmits the high byte of pressure data, followed by the low byte. The data resolution is 14-bits, so the upper two bits of the high byte are always zero padded. There is a half-stop bit time between bytes in a packet. That means, for the time of half a bit width, the signal level is high. Combining the high and low data bytes provides a 14-bit number corresponding to the pressure reading.
Figure 4: The NPA700 pressure sensor showing the digital interface.
It is best to connect the digital signal to a pin on the microcontroller that is capable of causing an interrupt on a falling edge. When the falling edge of the start bit occurs, it causes the microcontroller to branch to its ISR (Interrupt Service Routine). The ISR enters a counting loop incrementing a memory location (Tstrobe) until it sees a rise on the digital signal. When Tstrobe has been acquired, the ISR can simply wait for the next nine falling edges (8-data, 1-parity). After each falling edge, it will wait for Tstrobe to expire and then sample the next bit. The digital line is driven by a strong CMOS push/pull driver; the parity bit is intended for error checking when the digital signal is driving long (>2 m) interconnects to the microcontroller in a noisy environment. For systems in environments without noise interference, the user can choose to have the microcontroller ignore the parity bit.
Many sensors do not have digital interfaces, often as a result of the sensor technology being incompatible with general-purpose CMOS processing. For devices such as a Hall-Effect sensor, the connection to the Internet of Things can be done through a data converter and amplifier. These are now combined in a single chip with a simple output to a microcontroller that can interface to a wireless connection.
Analog Devices' AD7176-2 is a fast-settling, highly-accurate, high-resolution, multiplexed ∑-Δ ADC for low-bandwidth input signals such as sensors. Its inputs can be configured as two fully-differential or four pseudo-differential inputs via the integrated crosspoint multiplexer. An integrated, precision, 2.5 V, low-drift (2 ppm/°C), band-gap internal reference (with an output reference buffer) adds functionality and reduces the external component count.
The maximum channel-scan data rate is 50 kSPS (with a settling time of 20 µs), resulting in fully-settled data of 17 noise-free bits. User-selectable output data rates range from 5 SPS to 250 kSPS with resolution increases at lower speeds.
The AD7176-2 offers three key digital filters. The fast-settling filter maximizes the channel scan rate. The Sinc3 filter maximizes the resolution for single-channel, low-speed applications. For 50 Hz and 60 Hz environments, the AD7176-2 specific filter minimizes the settling times or maximizes the rejection of the line frequency. These enhanced filters enable simultaneous 50 Hz and 60 Hz rejection with a 27 SPS output data rate (with a settling time of 36 ms).
The AD7176-2 (Figure 5) has a three- or four-wire SPI interface that operates in SPI Mode 3 and can be operated with CS tied low. In this mode, the SCLK idles high, the falling edge of SCLK is the drive edge, and the rising edge of SCLK is the sample edge. This means that data is clocked out on the falling/drive edge and data is clocked in on the rising/sample edge.
Figure 5: The AD7176-2 for interfacing analog sensors to a microcontroller in an IoT sensor node.
An 8-bit write-only communications register controls access to the full register map of the ADC. On power-up or after a reset, the digital interface defaults to a state where it is expected a write to the communications register, so all communication begins by writing to the communications register.
The data written to the communications register determines which register is being accessed and if the next operation is a read or write. The register address bits (RA[5:0]) determine the specific register to which the read or write operation applies.
When the read or write operation to the selected register is complete, the interface returns to its defaults state, where it expects a write operation to the communications register. This can be used to capture the analog data from the sensor and deliver it to the microcontroller via the SPI interface so that the data can be accessed remotely. This allows a wider range of sensors to become part of the Internet of Things.
Improvements in digital process technology and packaging are allowing sensors to have digital interfaces either integrated onto the same silicon or included in the same packaging. This is allowing simplified interfaces, and opening up the sensor technology for the Internet of Things. Interfacing directly to a microcontroller and networking interface, allowing access from anywhere on the Internet, takes a different approach, requiring more programming and knowledge of the register structures of the device and protocols such as SPI and I²C than has been necessary in the past. Using a stand-alone ADC can allow analog devices that do not have the same digital interfaces to also be included in the development of sensor nodes for the Internet of Things.