Sensors and Actuators

Chapter 11
Embedded Interfacing and Industrial Communication

Bachelor Program in Mechatronics Engineering
Sensors and Actuators   •   Bachelor

Embedded Interfacing and Industrial Communication

Introduction

A sensor or actuator becomes useful in an engineered system only when its information or energy can be exchanged reliably with a controller. Embedded interfacing is the discipline of connecting transducers, signal-conditioning circuits, microcontrollers, programmable logic controllers (PLCs), field-programmable gate arrays (FPGAs), and embedded computers so that measurements are acquired, decisions are made, and physical actions are commanded.

The interface is more than a wiring connection. It includes electrical compatibility, timing, data representation, protocol rules, error detection, electromagnetic compatibility, diagnostics, safety, and software architecture. A temperature sensor may provide an analogue voltage, an I²C data stream, or an IO-Link message; each option imposes different requirements on the controller. Similarly, a motor may be driven by a PWM signal, a fieldbus command, or a safety-rated drive interface.

Industrial communication extends these ideas from a single circuit board to machines and factories. Protocols such as UART, SPI, I²C, CAN, Modbus, IO-Link, and industrial Ethernet provide increasingly structured methods for exchanging data. The correct choice depends on distance, speed, determinism, wiring, diagnostics, topology, cost, and safety requirements.

Learning Objectives

After studying this chapter, the reader should be able to:

  1. Select suitable electrical and logical interfaces for sensors and actuators.
  2. Configure timing, interrupts, PWM, capture units, ADCs, and digital I/O.
  3. Explain the operation and limitations of I²C, SPI, UART, CAN, Modbus, IO-Link, and industrial Ethernet.
  4. Design basic sensor-feedback and actuator-control architectures using microcontrollers, PLCs, FPGAs, and embedded computers.
  5. Analyse communication reliability, latency, determinism, grounding, isolation, and diagnostics.
  6. Apply good engineering practice to commissioning, cybersecurity, safety, and maintenance.

1. Interface Architecture

A typical mechatronic control chain is:

physical variable → sensor → signal conditioning → data conversion → controller → output interface → actuator → physical process

The interface must preserve the meaning of the signal while satisfying electrical and temporal constraints. Important interface layers are:

  • Physical layer: voltage levels, current, connectors, shielding, isolation, termination, and protection.
  • Data-link layer: framing, addressing, arbitration, acknowledgements, and error detection.
  • Application layer: interpretation of registers, commands, scaling, units, and device states.
  • Control layer: sampling, filtering, feedback, limits, and fault response.

A signal specification should identify range, resolution, update rate, accuracy, latency, allowable noise, and failure behaviour. For an ADC with reference voltage Vref and N-bit resolution, the ideal voltage increment is

q = Vref / 2N

where q is the quantisation step in volts. This is an ideal result; gain error, offset error, reference variation, noise, and nonlinearity may dominate in practice. A unipolar ADC normally represents 0 to Vref, while a bipolar input requires suitable analogue conditioning or a differential ADC.

Electrical compatibility

Before connecting devices, verify:

  • logic-high and logic-low voltage thresholds;
  • input and output current limits;
  • pull-up or pull-down requirements;
  • open-drain or push-pull behaviour;
  • common-ground requirements;
  • maximum cable length and frequency;
  • transient and reverse-polarity protection;
  • galvanic isolation and permissible voltage differences.

A 5 V output must not automatically be connected to a 3.3 V input. Level shifters, resistive dividers, translators, or isolated interfaces may be needed. Analogue signals require attention to source impedance, ADC acquisition time, anti-alias filtering, and grounding.

2. Timing and Real-Time Behaviour

A controller does not merely read values; it reads them at defined times. Sampling too slowly can miss events or destabilise a control loop. Sampling irregularly introduces timing variation, or jitter. A periodic task with sampling period Ts has frequency fs = 1/Ts. For a sampled signal, the sampling frequency should exceed twice the highest relevant signal frequency to avoid ideal Nyquist aliasing:

fs > 2fmax

where fmax is the highest frequency component of interest. In engineering systems, a margin and an analogue anti-alias filter are required because real signals are not perfectly band-limited.

A control system also has latency: the time between a physical event and the corresponding controller action. Latency includes sensor conversion, communication, task scheduling, computation, and actuator response. Determinism concerns the boundedness and predictability of this delay. A slower but deterministic network may be preferable to a faster network with unpredictable contention.

Interrupts

An interrupt temporarily transfers processor execution to an interrupt service routine (ISR). Interrupts are appropriate for urgent, short events such as an encoder edge, timer expiration, ADC completion, or communication reception. An ISR should capture essential information, clear the interrupt source, and defer lengthy processing to a task or queue.

Poor ISR design can cause missed events, priority inversion, race conditions, and excessive jitter. Shared variables should be protected using atomic operations, critical sections, or appropriate real-time operating-system mechanisms. A hardware timestamp is often more accurate than reading a software clock after the ISR begins.

Polling and DMA

Polling is simple and predictable when the required rate is low. It becomes inefficient when a processor repeatedly checks inactive devices. Direct memory access (DMA) transfers ADC samples or communication frames without requiring the CPU to handle every byte. DMA improves throughput but requires careful buffer ownership, cache coherency, alignment, and overrun detection.

3. PWM, Capture, and Actuator Control

Pulse-width modulation (PWM) controls average power by varying the duty ratio D:

D = ton / T

where ton is the high-time and T is the period. For an ideal low-pass load supplied by a unipolar voltage Vs, the average voltage is approximately

Vavg ≈ D Vs

This approximation applies when the load or an external filter sufficiently attenuates switching ripple. It does not directly describe instantaneous motor current, torque, or a switching converter under all operating conditions.

PWM frequency must be selected according to actuator dynamics, switching losses, acoustic noise, and electromagnetic interference. A motor drive may require complementary PWM outputs with dead time to prevent simultaneous conduction in a half bridge. Hardware fault inputs should be capable of disabling outputs independently of software.

Input-capture peripherals record a timer value when an edge occurs. For a periodic signal with measured timer interval Δn, timer clock frequency ft, and prescaler P, the period is

Tsignal = (P Δn) / ft

and frequency is fsignal = 1/Tsignal. This method is useful for tachometers, flow sensors, ultrasonic echo timing, and encoder measurement. Overflow, missing edges, false transitions, and quantisation must be handled.

Quadrature encoders provide two signals, A and B, phase-shifted by approximately 90°. The transition sequence indicates direction. Hardware decoder units are preferred at high speed because software edge processing can miss transitions.

4. Feedback Acquisition and Control Integration

A feedback channel should define sensor range, scaling, filtering, sampling period, saturation limits, and fault status. A linear conversion from a measured ADC code c to a physical quantity x may be written as

x = xmin + (c − cmin)(xmax − xmin)/(cmax − cmin)

where cmin and cmax are calibrated endpoint codes and xmin and xmax are corresponding physical values. The formula assumes a linear calibrated relationship. Sensors with nonlinear characteristics require a polynomial, lookup table, or device-specific compensation.

Filtering reduces noise but adds delay. A first-order discrete exponential filter is

yk = αxk + (1 − α)yk−1

where xk is the current sample, yk is the filtered output, and 0 < α ≤ 1. Larger α responds faster but smooths less. Filtering must not conceal a dangerous fault or create unacceptable control delay.

A robust feedback implementation includes:

  • plausibility checks and range limits;
  • rate-of-change checks;
  • sensor-disconnection detection;
  • watchdog supervision;
  • actuator saturation and anti-windup;
  • defined safe states;
  • timestamping and quality flags;
  • diagnostic records.

5. Board-Level Serial Interfaces

I²C

I²C uses a two-wire serial clock line (SCL) and serial data line (SDA). Devices commonly use open-drain outputs, so pull-up resistors create the logic-high state. Multiple devices share the bus using addresses. A transaction consists of a START condition, address and read/write indication, data bytes with acknowledgements, and a STOP condition.

The pull-up value must balance rise time, bus capacitance, voltage, and sink current. Excessive resistance produces slow edges; excessive current may violate device limits. I²C is convenient for short PCB connections to sensors, EEPROMs, and expanders, but it is not normally suitable for long industrial cables without specialised transceivers.

SPI

SPI generally uses SCLK, MOSI, MISO, and one chip-select line per slave. It is usually full duplex and has no inherent addressing, acknowledgement, or error-checking mechanism. Clock polarity and phase must match the slave mode. SPI is fast and simple for ADCs, displays, memory, and converters, but board-level wiring and chip-select management limit scalability.

UART

UART transmits asynchronous framed characters using a configured baud rate, data length, optional parity, and stop bits. A common frame contains a start bit, data bits, optional parity, and one or more stop bits. UART normally connects two endpoints; RS-232 and RS-485 transceivers adapt the electrical layer for different applications. RS-485 supports differential, multi-drop communication and longer cables than single-ended logic, but termination, biasing, grounding, and driver control remain important.

6. CAN and Industrial Sensor Networks

Controller Area Network (CAN) uses message identifiers rather than device-specific addresses. Nodes compete for access using nondestructive bitwise arbitration: a dominant bit overrides a recessive bit. A lower numerical identifier generally has higher priority, assuming the identifier interpretation and arbitration field are considered.

CAN frames include an identifier, control information, data, and a cyclic redundancy check (CRC). Error detection and automatic retransmission provide strong robustness. CAN bus load must be controlled because high-priority traffic can delay low-priority frames. A design should calculate worst-case latency, not merely average throughput.

CAN requires correct bus termination, usually at the two physical ends of a linear bus. Stubs should be short relative to the bit time and cable characteristics. CANopen and DeviceNet are examples of higher-level systems built on CAN, adding device profiles, network management, and application conventions.

7. PLC Communication and Modbus

PLCs combine cyclic program execution, discrete I/O, analogue modules, diagnostics, and industrial communication. A PLC scan commonly reads inputs, executes logic, updates outputs, and performs communication or diagnostics. The exact order and timing depend on the PLC platform.

Modbus is a simple request-response protocol widely used with PLCs, meters, drives, and remote I/O. Modbus RTU commonly runs over RS-485, while Modbus TCP runs over Ethernet. Data are organised into coils, discrete inputs, input registers, and holding registers. The register map, byte order, scaling, signedness, and exception responses must be documented; a register number alone does not define the physical unit.

For example, if a drive reports motor speed as an integer equal to speed in 0.1 rpm, a register value of 1,250 represents 125.0 rpm. This scaling is an application convention, not an inherent property of Modbus.

8. IO-Link

IO-Link is a point-to-point communication system for intelligent sensors and actuators. It uses a standardised device interface and permits cyclic process data plus acyclic parameter and diagnostic data. A master communicates with devices through dedicated ports; IO-Link is not a general multi-drop bus.

Compared with a conventional binary sensor, IO-Link can provide measurement values, device identification, configuration, quality information, and detailed diagnostics. Device descriptions support commissioning and parameter management. Its value is particularly strong in predictive maintenance and replacement of devices without manually reproducing every parameter.

9. Industrial Ethernet

Industrial Ethernet systems use Ethernet physical media and higher-level mechanisms adapted to automation. Examples include PROFINET, EtherNet/IP, EtherCAT, and Modbus TCP. They differ in scheduling, real-time mechanisms, configuration models, diagnostics, topology, and device profiles.

Ordinary office Ethernet is generally best-effort and may have variable delay. Industrial systems can add prioritisation, synchronisation, scheduled traffic, ring redundancy, or specialised processing. Selection should consider required cycle time, jitter, topology, interoperability, engineering tools, installed base, and maintenance capability.

Network design must address electromagnetic compatibility, cable category, connector quality, switch behaviour, redundancy, time synchronisation, and separation of control and enterprise traffic. A network that works on a laboratory bench may fail in a factory because of motor drives, welding equipment, poor shielding, or ground potential differences.

10. Platform Selection: Microcontrollers, PLCs, FPGAs, and Embedded Computers

A microcontroller integrates CPU, memory, timers, ADCs, PWM units, communication peripherals, and GPIO. It is economical and well suited to deterministic local control.

A PLC provides industrial packaging, certified programming environments, modular I/O, diagnostics, and maintenance-oriented operation. It is often preferred for machine sequencing and plant integration.

An FPGA implements parallel hardware logic and precise timing. It is appropriate for high-speed acquisition, encoder processing, custom protocols, and multiple simultaneous control loops, although development and verification require specialised skills.

An embedded computer offers high computing capacity, operating systems, graphical interfaces, databases, and advanced analytics. It may have less deterministic timing unless supported by real-time extensions and suitable hardware.

Many modern systems combine these platforms: an FPGA or microcontroller performs hard real-time I/O, a PLC coordinates machine operation, and an embedded computer provides visualisation, data logging, or optimisation.

11. Diagnostics, Safety, and Cybersecurity

Communication failure must produce a defined response. Common mechanisms include CRCs, parity, sequence counters, timeouts, heartbeat messages, watchdogs, redundant measurements, and plausibility checks. A timeout should not merely generate a message; it should place the process in a controlled state appropriate to the hazard.

Functional safety is distinct from ordinary reliability. Safety-related systems require hazard analysis, risk reduction, independence, diagnostic coverage, and validated safety functions according to applicable standards and jurisdictional requirements. Emergency stopping, guard monitoring, and torque removal should not depend solely on a general-purpose application task.

Cybersecurity is increasingly relevant because industrial controllers are connected to wider networks. Good practice includes asset inventories, authenticated access, least privilege, network segmentation, secure update procedures, logging, backup, vulnerability management, and controlled remote access. Protocols such as Modbus do not inherently provide authentication or encryption; protection must be implemented by the surrounding architecture.

Data governance also matters. Sensor data may reveal production rates, worker behaviour, or equipment condition. Collection should be justified, access controlled, retained appropriately, and protected from unauthorised alteration.

12. Worked Example: Encoder-Based Conveyor Control

A conveyor uses an incremental encoder producing 1,024 pulses per revolution. The controller counts four quadrature transitions per pulse, so the effective resolution is 4,096 counts per revolution. The roller diameter is 100 mm. Determine the conveyor displacement per count and the count rate at 0.80 m/s.

The roller circumference is

C = πd = π(0.100 m) ≈ 0.31416 m

The displacement per count is

Δx = C/4096 ≈ 0.31416/4096 ≈ 7.67 × 10−5 m

Thus, Δx ≈ 0.0767 mm per count. At velocity v = 0.80 m/s, the count rate is

fcount = v/Δx ≈ 0.80/(7.67 × 10−5) ≈ 10,430 counts/s

The selected microcontroller must therefore process at least about 10.4 kcounts/s, with margin for maximum speed, acceleration, noise, and diagnostic events. A hardware quadrature decoder is preferable to a low-priority software interrupt. If the encoder is connected through CAN, communication latency must also be included in the positioning design.

13. Applied Case: Illustrative Packaging Cell

Background

An illustrative packaging cell contains a photoelectric sensor, a rotary encoder, a pneumatic valve, a variable-speed conveyor drive, a PLC, and an embedded diagnostic computer.

Problem

The original system used discrete wiring for basic states. Operators could not distinguish a blocked beam, damaged cable, misaligned sensor, or failed input module. Product spacing also varied because encoder feedback was processed in a slow cyclic task.

Analysis

The engineering team separated the requirements into layers. The safety stop remained on a safety-rated circuit. The photoelectric sensor was replaced by an IO-Link device to obtain signal quality and diagnostic information. The encoder was connected to a high-speed PLC input module. The drive used industrial Ethernet for cyclic speed commands and status. The embedded computer collected diagnostic and production data without participating in the safety function.

Approach and solution

The PLC generated a conveyor position reference from encoder counts and triggered the pneumatic valve at a defined position. A hardware input-capture mechanism timestamped the product-detection edge. A watchdog declared the sensor invalid if expected cyclic communication stopped. The valve output was interlocked with guard and pressure conditions. Network switches and cables were selected for the factory environment, and all device parameters were backed up.

Outcome

The architecture improved fault localisation, reduced dependence on manual measurements, and made replacement-device commissioning faster. Position repeatability improved because event timing was tied to encoder counts rather than only to a slow scan. The computer supplied trends and maintenance information, but the machine continued to reach a safe state if the diagnostic computer or network connection failed.

Learning points

  1. Use the fastest appropriate hardware for time-critical events.
  2. Keep safety functions independent from non-safety analytics.
  3. Treat diagnostics as part of the interface specification.
  4. Document scaling, units, timing, and failure states.
  5. Select protocols according to the complete system, not popularity alone.

14. Design and Commissioning Practice

A disciplined workflow is:

  1. Define variables, ranges, units, update rates, and failure responses.
  2. Select the physical layer and verify electrical compatibility.
  3. Calculate sampling, bandwidth, bus load, latency, and worst-case timing.
  4. Design protection, isolation, termination, grounding, and shielding.
  5. Define message formats, scaling, byte order, diagnostics, and versioning.
  6. Implement hardware protections and watchdogs before optimisation.
  7. Test normal, boundary, disconnected, shorted, noisy, and overloaded conditions.
  8. Record measured timing and error rates during commissioning.
  9. Secure configuration files, credentials, firmware, and backups.
  10. Maintain a clear interface control document for future technicians.

Challenges and Limitations

No protocol eliminates system-level engineering problems. Fast interfaces may increase EMI and processing burden. Wireless or Ethernet systems may be convenient but introduce cybersecurity and timing concerns. Filtering improves measurement quality but adds delay. Higher-level diagnostics increase device cost and configuration complexity. Proprietary ecosystems may provide excellent integration but reduce supplier flexibility. Finally, nominal protocol compliance does not guarantee interoperability; physical installation, firmware interpretation, data scaling, and timing must also agree.

Contemporary Developments

Current systems increasingly combine edge computing, time-sensitive networking, digital device descriptions, condition monitoring, and machine-learning-based anomaly detection. AI can help identify unusual vibration or current signatures, but it should not replace deterministic interlocks or validated safety functions. The quality of an AI model depends on representative data, correct labelling, drift monitoring, and secure data pipelines. Deterministic control and safety should remain supported by transparent, testable mechanisms even when analytics are added.

Chapter Summary

Embedded interfacing connects physical sensors and actuators to computational platforms through electrical, timing, data-link, and application-layer decisions. Reliable systems match voltage levels, current capability, sampling rate, latency, and protection to the application. Timers, interrupts, DMA, PWM, input capture, ADCs, and encoder hardware provide the foundation for responsive control.

I²C and SPI are primarily board-level interfaces; UART and RS-485 support simple serial links; CAN provides robust arbitration and error handling; Modbus offers widely adopted register-based communication; IO-Link adds parameterisation and diagnostics to point-to-point sensors; and industrial Ethernet supports plant-scale integration with differing real-time properties. Microcontrollers, PLCs, FPGAs, and embedded computers are complementary rather than interchangeable.

Professional implementation requires diagnostics, defined safe states, cybersecurity, documentation, validation, and attention to electromagnetic and installation conditions. Protocol choice should follow the required performance, maintainability, interoperability, safety, and lifecycle objectives.

Key Terms

ADC: Analogue-to-digital converter that represents an analogue quantity as a digital code.

Arbitration: Method by which competing network nodes determine which message gains access to a shared medium.

CAN: Controller Area Network, a robust message-oriented industrial bus.

DMA: Direct memory access, allowing peripherals to transfer data with limited CPU intervention.

Duty ratio: Fraction of a PWM period for which the signal is active.

EMC: Electromagnetic compatibility; ability to operate correctly without causing or suffering unacceptable interference.

I²C: Two-wire addressed serial bus using clock and data lines.

IO-Link: Point-to-point industrial interface for intelligent sensors and actuators.

Interrupt: Event that temporarily transfers processor execution to an ISR.

Jitter: Variation in the timing of an otherwise periodic event.

Latency: Delay between an event and the associated response.

Modbus: Request-response industrial protocol commonly implemented over RS-485 or Ethernet.

PWM: Pulse-width modulation used to control average power or command actuators.

PLC: Programmable logic controller designed for industrial control.

Pull-up resistor: Resistor that establishes a default logic-high level, commonly on open-drain buses.

SPI: Synchronous serial peripheral interface using clock, data, and chip-select signals.

UART: Asynchronous serial communication peripheral using framed characters.

Watchdog: Timer that detects failure of expected software or communication activity.

Review Questions

Short Answer Questions

  1. Why must voltage levels and input-current limits be checked before connecting two devices?
  2. Distinguish polling, interrupts, and DMA in an embedded controller.
  3. What is the purpose of dead time in complementary PWM outputs?
  4. Why is termination important on a CAN bus?
  5. State two advantages of IO-Link over a conventional binary sensor connection.

Long Answer Questions

  1. Explain the physical, data-link, application, and control layers of an embedded sensor interface.
  2. Compare I²C, SPI, UART/RS-485, and CAN in terms of topology, addressing, robustness, and typical application.
  3. Discuss how sampling rate, filtering, latency, and jitter influence feedback-control performance.
  4. Compare microcontrollers, PLCs, FPGAs, and embedded computers for a high-speed machine-control application.
  5. Explain how diagnostics, functional safety, and cybersecurity should be incorporated into an industrial communication design.

Analytical / Application Questions

  1. A 12-bit ADC uses a 3.3 V reference. Calculate its ideal quantisation step and discuss two practical effects that may make the actual accuracy worse.
  2. Design a communication and control architecture for a conveyor containing an encoder, photoelectric sensors, a motor drive, and a maintenance dashboard. Justify the platform and protocol choices.
  3. A sensor value is transmitted by Modbus as an integer in units of 0.01 °C. Explain how the receiving controller should convert, validate, diagnose, and safely use the value in a control loop.

Multiple Choice Questions with Answers

Question 1

For an ideal N-bit ADC with reference voltage Vref, which expression gives the quantisation step?

A. Vref × 2^N

B. Vref / 2^N

C. N / Vref

D. 2^N / Vref

Correct Answer: B. Vref / 2^N

Question 2

Which peripheral is most suitable for measuring the period of an encoder or tachometer signal with precise edge timing?

A. Input capture

B. DAC

C. GPIO output latch

D. EEPROM

Correct Answer: A. Input capture

Question 3

What is the principal reason for using dead time in complementary half-bridge PWM signals?

A. To increase ADC resolution

B. To prevent simultaneous conduction of opposing switches

C. To assign CAN identifiers

D. To remove the need for grounding

Correct Answer: B. To prevent simultaneous conduction of opposing switches

Question 4

Which statement best describes I²C?

A. A point-to-point asynchronous interface with start and stop bits

B. A two-wire addressed bus commonly using open-drain outputs

C. A message bus using nondestructive identifier arbitration

D. An Ethernet protocol with mandatory encryption

Correct Answer: B. A two-wire addressed bus commonly using open-drain outputs

Question 5

In CAN arbitration, what generally happens when two nodes transmit different identifier bits?

A. The node transmitting the dominant bit loses

B. Both frames are discarded immediately

C. The lower-priority transmission withdraws without corrupting the winning frame

D. A central master selects the winner

Correct Answer: C. The lower-priority transmission withdraws without corrupting the winning frame

Question 6

What is a defining feature of IO-Link?

A. It is a point-to-point interface supporting process data and device diagnostics

B. It is exclusively a wireless multi-drop protocol

C. It replaces all safety circuits

D. It is an analogue current loop with no digital data

Correct Answer: A. It is a point-to-point interface supporting process data and device diagnostics

Question 7

A PWM signal has a period of 2 ms and an active time of 0.5 ms. What is its duty ratio?

A. 10%

B. 25%

C. 40%

D. 75%

Correct Answer: B. 25%

Question 8

Which practice is most appropriate for a long RS-485 installation?

A. Use arbitrary star wiring without termination

B. Use differential wiring with appropriate termination and biasing

C. Connect all transmitters directly to a single-ended CMOS input

D. Disable all error checks

Correct Answer: B. Use differential wiring with appropriate termination and biasing

Question 9

Why should a lengthy computation normally be avoided inside an interrupt service routine?

A. It changes the ADC reference voltage

B. It can increase latency and cause other time-critical events to be missed

C. It prevents PWM from operating at any frequency

D. It automatically reverses CAN arbitration

Correct Answer: B. It can increase latency and cause other time-critical events to be missed

Question 10

A Modbus register represents speed in units of 0.1 rpm. What physical speed corresponds to a register value of 1,250?

A. 12.5 rpm

B. 125 rpm

C. 1,250 rpm

D. 12,500 rpm

Correct Answer: B. 125 rpm

Sensors and Actuators
Chapter 11 of 14