Modular control system for embedded applications

This paper deals with hardware design of a modular control system intended for embedded applications demanding high computational power while maintaining low cost. The control system central unit is based on 32bit microcontroller MK60DN512 with ARM Cortex-M4 core manufactured by NXP Semiconductor. Module provides all the necessary signals on the two 2-row 40 pin headers and Ethernet communication interface in the form of a small daughter board. It is connected to the mainboard which must always contain 5 V stabilized power supply; other circuits are application specific. In our application the mainboard is equipped with SD card slot, RS232 and RS485 interface which is used for high speed interconnection with up to 15 expansion peripheral modules. This concept enables high flexibility to specific application demands without necessity of redesigning the control system. Controller is freely programmable in C language using any compatible integrated development environment – NXP Kinetis Design Studio, for example. Software development and debugging is simplified by our support program libraries including necessary routines for control and monitoring tasks.


Introduction
Present-day very rapid progress in electronics and computer science influences all areas of human activities.Production technology improvements of new microcontrollers lead to their miniaturization, increased central processor unit performance, decreased power consumption and price.Thus modern 8bit one-chip microcontrollers have enough computing power not only for simple control loops consisting of fixed parameters controllers like PS or PSD.They are able to handle tasks from the origin of modern control methods such as adaptive control [1].However the second mentioned area is on the memory and computational power limit of most 8bit microcontrollers for more complex algorithms.New possibilities in this area are brought by modern 32bit ARM core based microcontrollers which can provide Ethernet, USB and other interfaces for communication and data storage enabling data presentation using simple web server, data logging to SD card and many other useful functionality.
Due to some limitations, mainly in main memory capacity and computational power in double precision floating point format, microcontrollers cannot fully substitute powerful industrial PCs or special programmable logic controllers, which can work with number of control loops simultaneously and realize highly sophisticated control algorithms.However, area of microcontroller usage is a bit different -in embedded systems, that is in systems where the emphasis is on low price, compact dimensions, low power consumption, high reliability and immunity against environmental influences and other specific requirements.This work presents hardware design of a modular control system intended for embedded applications.The main idea is to combine advantageous properties of modular programmable logic controllers (configuration variability perfectly meets application requirements) and embedded systems (freely programmable in C language, very low cost).To fulfil main requirements of high computational power, Ethernet communication capabilities and low cost of the whole control system 32bit Kinetis microcontroller MK60DN512 with ARM Cortex-M4 core by NXP Semiconductor was chosen as a main part of the central unit.
First section of the paper describes hardware design of all the components of the control system -central unit, digital input / output and analog input / output extension modules representing basic configuration of the system.Last chapter deals with software support of the device which is necessary for effective programming of control and monitoring applications.

Control system hardware design
Design of the control system is adapted to easy functionality modification on the basis of the specific application requirements.This is achieved by splitting the whole control system to two main components: x Central unit consisting of mainboard and microcontroller daughter board.x Expansion modules which are connected with central unit using high speed RS485 communication bus.Control system structure is depicted in Figure 1.x Secure Digital Host controller (SDHC) x 66 general purpose I/O pins [2] Central unit consists of two separable printed circuit boards: microcontroller daughter board and mainboard connected together using two 2-row 40 pin headers.Complete block schematic of the unit is depicted in the Figure 2.
Daughter board contain main microcontroller MK60DN512 connected via RMII interface with Ethernet PHY DP83848 by Texas Instruments supporting auto-MDIX feature for communication speed of 10/100 Mb/s.Status of the interface is indicated by three LEDs with the following meaning: x D1 -Link good x D2 -Speed, ON = 100 Mb/s x D3 -Interface activity Clock source for the PHY in RMII mode must provide 50 MHz reference clock signal with frequency tolerance and stability of ±50 ppm to the X1 pin.This requirement fulfils for example crystal clock oscillator ACHL-50.000MHz-EK which is currently used in the circuit.Clock output pin named 25MHz_OUT (in RMII mode provides 50 MHz) is connected to clock input pin EXTAL0 of the main microcontroller.TD+, TD-and RD+, RD-signals of the PHY PMD interface are connected to LAN magnetics module (transformer) B78476A8065A003 with 1:1 turn ratio and inductance of min.350 μH followed by standard RJ-45 connector.Reference voltage of 2.5 V for A/D converter is provided by precision voltage reference REF03 by Analog Devices and connected to pin VREFH.Internal real-time clock is backed up when system power is down by lithium cell CR2032 with nominal voltage of 3 V.Microcontroller programming and application debugging can be done through 10 pin Kinetis debug port using compatible debug communication interface.Last part of the microcontroller daughter board is power supply circuit based on low drop linear voltage regulator AP1117D with output voltage of 3.3 V and 1 A current capability.Board power state is indicated by two LEDs for 3.3 V and 5 V rails separately.
The purpose of the mainboard is to provide to microcontroller daughter board stabilized 5 V supply voltage and necessary communication interfaces for the whole system functionality.Power supply was designed with respect to minimization of power losses as a stepdown converter based on controller MC34063.On its output is generated stabilized DC voltage of 5 V which is in the next stage regulated to 3.3 V using linear voltage regulator AP1117D.Input supply voltage of the central module can be due to utilization of step-down converter in the wide range from 12 V to 40 V DC.Nominal supply voltage of control system is 24 V DC.Physical layer of the RS485 communication interface is implemented by RS485 transceiver SN65HVD10 operating at 3.3 V supply voltage which supports communication speed up to 32 Mb/s.Bus connection pins A and B are on the chip internally protected against ESD and short circuit from -7 V to 12 V.Serial asynchronous interface RS232 utilizes standard voltage level converter MAX3232 which can operate with supply voltage in range from 3.0 V to 5.5 V.It supports communication speed up to 120 kb/s while maintaining RS232 output levels.Integrated dual charge pump requires four external 100 nF capacitors.

Analog input / output module
Analog input / output expansion module is based on 8bit microcontroller NXP MC9S08QE16 which was chosen due to integrated 12bit A/D converter [3].Input unified voltage signal with range from 0 V to 10 V first enters to resistor divider which adapts it to 0 V to 3.1 V range suitable for A/D converter of the microcontroller.After voltage divider follows non-inverting amplifier with gain set to 1 and simple first order low-pass filter for high frequency ripple rejection.Then the signal enters to the corresponding input channel of the A/D converter.Analog outputs are implemented using two 2 channel 12bit D/A converters MCP4822 [4] which are connected with microcontroller via serial peripheral interface (SPI).Analog signal from the converter is amplified using noninverted amplifier with gain of 4.9 to achieve unified output voltage signal in range from 0 V to 10 V. RS485 communication interface utilizes same bus transceiver type SN65HVD10 as central unit.

Digital input / output module
Digital input / output expansion module is based on microcontroller MC9S08SH32 by NXP Semiconductor.It is 8bit microcontroller with 32 KB of program FLASH memory and 1 KB of RAM memory.On the chip the following peripherals are integrated: 10bit A/D converter, analog comparator, serial communication interface (SCI), serial peripheral interface (SPI), I2C, timer subsystem, real-time counter and others [5].Digital inputs of the module are galvanically isolated by two 4 channel optocouplers TLP283-4 with output electrooptical transistor.Input voltage for logical 1 should be in wide range from 3.3 V to 24 V providing compatibility with both TTL and relay logic.Digital outputs of the microcontroller are connected with Darlington transistor array ULN2803A which makes possible directly switch loads with total current up to 500 mA -for example 24 V relays.Maximum voltage which can be connected to the outputs is 50 V DC.Communication interface and power supply is designed identically as in analog I/O module.
Photograph of the completed digital input / output module with removed top cover is in the Figure 5. Module properties: x 8 galvanically separated digital inputs x 8 digital outputs with open collector (NPN) x PWM signal generation support on digital outputs x Pulse counting support on digital inputs x RS485 communication interface for connection with central unit at speed of 625 kb/s x 24 V DC supply voltage

Control system software
The software for the control system is based on the library created at our institute, named UCP [6].This library was designed with three main requirements in mind: x Provide discrete controllers usable in many common MCU applications x Easy to use programming interface x Easily portable to different MCUs The library can be divided into three main parts: x controller modules (functions) x template code for user application x software-PWM generator x supporting code (drivers) There are three main software layers in the control application above the microcontroller hardware: user code, library template files and device drivers [7].Considering just the library code, there are two main parts: application (ucp_app) and hardware abstraction layer (ucp_hal).

Controller modules
Controller modules are the fundamental part of the software.By module we mean a set of functions and the data used by those functions enclosed into a source and header file.From the logical point of view a module is one type of a controller, e.g. a discrete PID controller.Typically it contains two C functions: one function which takes care of the initialization of the controller and one function which calculates the output of the controller in each step.

User application templates
The library also recommends a preferred way of using the controllers.This is accomplished by template files, which contain skeleton code of a control application.The user is advised to include these template files in his/her program and implement the application-specific and hardwarespecific code as outlined in the templates.Example applications are also provided which show how to implement this code.
However, the user is not required to use this application template or any other particular style of programming.He is free to use any part of the library separately, e.g.just the controller module(s), which are C functions and therefore can be simply called from any C program.

Utility code
There is also utility code, which was developed during the development of the library for testing its functions.An example of such a code is a driver for serial communication interface (UART).
The utility code can be used directly in user applications, or it may provide starting point and working examples of the code which will be very likely needed when using the library.

Conclusions
This paper presented design of a universal modular control system intended for embedded applications demanding high computing power, wide communication possibilities and configuration flexibility while preserving low cost.These requirements are best fulfilled by a system consisting of a central unit and individual functional modules which number and type depends on target application.Developed prototype control system central unit is based on 32bit microcontroller MK60DN512 with ARM Cortex-M4 core with DSP instructions providing computational power of 1.25 Dhrystone MIPS per MHz.It is a part of a small daughter board including Ethernet communication interface and two 2-row 40 pin headers for connection with mainboard.The purpose of the mainboard is to provide to daughter board stabilized 5 V supply voltage and the required communication interfaces (RS232, RS485, SD card slot) for the whole system functionality.The RS485 interface is used for high speed interconnection with up to 15 expansion peripheral modules.Two types of expansion modules are now available: analog input / output module and digital input / output module which can cover most process control applications.
The controller is freely programmable in C language using any compatible integrated development environment, for example, NXP Kinetis Design Studio.Software development and debugging is simplified by our support program libraries named UCP which include various modules for control and monitoring tasks.

Figure 3 .
Figure 3. Photograph of the central unit.
Firmware of the microcontroller can be updated via 6pin BDM interface.Input supply voltage with nominal value of 24 V is converted to 5 V by DC-DC converter Mean Well SMU01N-05 with power of 1 W.Because the digital circuits work with 3.3 V it is necessary to lower 5 V output from converter with low-drop linear voltage regulator AP1117D.Module address is selected in binary form by DIP switch with four positions.Valid address range is from 1 to 15 (address 0 is reserved for central unit only).Photograph of the completed analog input / output module with removed top cover is in the Figure4.Module properties:x 8 analog inputs with voltage range 0 V to 10 V x 4 analog outputs with voltage range 0 V to 10 V x 12bit resolution of A/D converter x 12bit resolution of D/A converter x RS485 communication interface for connection with central unit at speed of 625 kb/s x 24 V DC supply voltage

Figure 4 .
Figure 4. Photograph of the analog I/O module.

Figure 5 .
Figure 5. Photograph of the digital I/O module.