2998

Embed Size (px)

Citation preview

  • 7/27/2019 2998

    1/6

    Towards a Rapid Control Prototyping Toolbox for the Stellaris LM3S8000Microcontrollers

    Radu Duma 1), Petru Dobra 2), Mirela Trusca 3), Dorin Petreus 4) and Daniel Moga 5) 1, 2, 3, 5) Automatic Control Department, 4)Applied Electronics Department

    Technical University of ClujNapoca(e-mail: 1)[email protected], 2)[email protected], 3)[email protected], 4)[email protected],

    5)[email protected])

    Abstract: The paper presents a Rapid Control Prototyping (RCP) toolbox for Matlab/Simulink, which isused to generate real-time C code for the Stellaris LM3S800 family of microcontrollers from TexasInstruments (TI). The toolbox, Target for Stellaris LM3S800 , contains Simulink blocks, which implementdrivers and algorithms specific for the Stellaris LM3S800 family of microcontrollers. The paper presentsan ongoing work. For the moment the toolbox contains four libraries: I/O drivers , Digital Motor Control (DMC) , Controller Area Network (CAN) and LM3S8000 Target Preferences . A practical application for aComputer Numerical Controlled (CNC) machine is presented.

    Keywords : rapid control prototyping, microcontroller, closed-loop control, CNC machine, PID control

    1. INTRODUCTION

    Developing controllers for applications (electrical drivesystems) means large expenditure, when performed withusual development methods. The workload comprisesdevelopment of a mathematical model as well as algorithmdesign and implementation, off-line simulation, andoptimization. The whole process has to be restarted on

    occurring errors or divergences, which makes thedevelopment process time consuming and costly (Hanselman,1996). Rapid Control Prototyping (RCP) is a way out of thissituation, especially if the control algorithm is complex and alot of iteration steps are necessary.

    RCP requires two components: a Computer Aided ControlSystem Design (CACSD) software and a dedicated hardware,capable of running tasks in real-time (Fig.1).

    Fig. 1. The general architecture of a RCP system.

    CACSD tools are extensively used to generate real time codeautomatically. The graphical programming approach removesthe need to write software by hand and allows the engineer to

    focus instead on improving functionality and performance.Complete system design is carried out within the simulationenvironment.

    With the great diversity of applications, a developmentenvironment must be flexible and provide exactly thefunctionality necessary for efficient problem solving.Mathworks' Simulink (Mathworks, 2010) software is such agraphical modelling tool.

    In Fig. 2 is presented the block diagram for the informationflow (from concept to model) and for the data flow (between

    PC and the Stellaris LM3S8000 microcontroller) for theimplemented toolbox.

    Fig. 2. Block diagram for the information and data flows for the Target for Stellaris LM3S8000 RCP toolbox.

    Control algorithms for the LM3S8000 microcontrollers can be developed using blocks from the Target for Stellaris LM3S8000 toolbox and predefined blocks from Simulink or user defined blocks. After the validation of the model, codecan be generated using Real-Time Workshop. At the end of the code generation process the Code Composer Studio(CCS) Integrated Development Environment (IDE) is

    automatically started, a new CCS project is created, thegenerated code source files are added to the project, the project is compiled and the binary file is downloaded to the

    Preprints of the 18th IFAC World CongressMilano (Italy) August 28 - September 2, 2011

    Copyright by theInternational Federation of Automatic Control (IFAC)

    1965

  • 7/27/2019 2998

    2/6

    target processor. The execution of the code can be monitoredin real-time using the implemented CAN drivers.

    2. RELATED WORK

    In this section is briefly presented some of the researchliterature related to RCP. MathWorks developed toolboxesfor some wildly used targets: Motorola MPC555, InfineonC166, C2000 and C6000 DSP families from TexasInstruments. Rebeschiess (Rebeschiess, 1999) developed theMICROS toolbox for standard 80C166 micrcontrollers. ADSP based RCP system for engineering education andresearch using as CACSD tool Matlab/Simulink is presentedin (Hercog et al., 2006). Duma and Dobra have implementeda RCP toolbox for the Renesas M32C87 microcontroller (Duma et al., 2010).

    Microchip (Microchip, 2009) developed a Matlab RCPtoolbox for the dsPIC33 Digital Signal Controllers (DSC),while Kerhuel (Kerhuel, 2009) developed a toolbox whichoffers support for several Microchip microcontrollers andDSCs.

    National Instruments LabVIEW graphical code can be usedto develop ARM microcontroller embedded applications for the Stellaris LM3S88962 using the LabVIEW EmbeddedModule for ARM Microcontrollers (National Instruments,2010).

    A free, open source, RCP solution is based on Scilab/Scicos(Campbell et al., 2009) and Linux-RTAI (Bucher et al.,2004), which uses the processor of a general purposecomputer for executing real-time tasks. A real-time patch is

    applied to the standard Linux kernel. A modified version of the Scicos code generator, RTAI-Lab, generates hard real-time code compatible with Linux-RTAI. Acquisition cardscan be directly integrated into the Scicos scheme and into thegenerated code using drivers provided by the COMEDI([Comedi]) project.

    Ravn (Ravn, 2006) implemented an adaptive control toolbox,for Scilab/Scicos, which can be used for RCP. A targetsupported in Scilab/Scicos is the Microchip dsPIC DSCmicrocontroller. Duma (Duma et al., 2009) presented asystem identification and control RCP toolbox for Scilab/Scicos.

    3. CODE COMPOSER STUDIO

    It is important for an RCP toolbox to offer support for acomplete build process. A full post-code generation build

    process includes: compilation of generated code, linking of compiled code and runtime libraries into an executable

    program module, downloading the executable to targethardware with a debugger or other utility, initiating executionof the downloaded program. Supporting a complete build

    process is a complex task, because it involves interfacing tocross-development tools and utilities that are external to theReal-Time Workshop software (Mathworks, 2008).

    CCS is the integrated development environment for TI'sDSPs, microcontrollers and application processors. CCS is

    based on the Eclipse open source software framework and isa file system based model IDE.

    There are command-line utilities that come with CCS tocreate, build and import a CCS project. Using thesecommands at the end of the code generation process CCS isautomatically started, a new CCS project is created, thegenerated code files are copied into the project directory andthe project is build. In the final version of the implementedRCP toolbox Debug Server Scripting (DSS) will be used for the automated download of the generated binary file on thetarget processor.

    4. TARGET FOR STELLARIS LM3S8000

    The Simulink library for the Stellaris LM3S8000microcontrollers is presented in Fig. 3. For the moment thetoolbox contains four libraries: I/O drivers , DMC , CAN and

    LM3S8000 Target Preferences .

    Fig. 3. The Target for Stellaris LM3S8000 Simulink toolbox.

    The target processors for the implemented toolbox are theStellaris LM3S8000 family of microcontrollers. The Stellarisfamily of microcontrollers - the first ARM Cortex-M3 basedcontrollers - brings high-performance 32-bit computing tocost-sensitive embedded microcontroller applications. TheStellaris LM3S8000 series combines Bosch Controller Area

    Network (CAN) technology with both a 10/100 EthernetMedia Access Control (MAC) and Physical (PHY) layer.

    The LM3S8000 microcontrollers are targeted for industrialapplications, including remote monitoring, electronic point-of-sale machines, test and measurement equipment, network appliances and switches, factory automation, HVAC and

    building control, gaming equipment, motion control, medicalinstrumentation and fire and security.

    Simulink blocks are defined by two functions: a MEXfunction written in the C language and a Target Language

    Preprints of the 18th IFAC World CongressMilano (Italy) August 28 - September 2, 2011

    1966

  • 7/27/2019 2998

    3/6

    Compiler (TLC) implementation. The MEX functionconfigures the number of inputs/outputs ports of the block and transfers the parameters specified in the graphical user interface of the block in the code generation process. TheTLC implementation initializes the I/O device, computes thevalue for the output of the block and terminates the program

    by setting the hardware to a neutral state. For each block of the toolbox the two files were implemented.

    In the following sections the libraries of the toolbox are briefly described.

    5. I/O Drivers Library

    The I/O drivers (Fig. 4) library contains drivers for the I/O peripherals of the target processor.

    Fig. 4. I/O drivers library.

    For the moment the library contains two blocks, one for thegeneration of PWM signals and one for input capture. In thefuture we plan to implement drivers for the following

    peripherals of the microcontroller: analog to digital converter,digital input, digital output, quadrature encoder interface.

    In Fig. 5 is presented the Function Block Parameters windowfor setting the parameters of the LM3S000 PWM block. The

    window contains several tabs which are described below.Timer - in this tab the desired PWM generator can be selectedand timer related options can be specified ( Up-Down or

    Down count mode). The period of the PWM signal can be setthrough the dialog (if it is fixed during program execution) or through input port (if it is variable during programexecution). This option is useful because there are processeswhich are controlled using a PWM signal with fixed dutycycle and a variable frequency.

    Output each PWM generator can generate two PWMsignals. In this tab one or both PWM outputs can be enabled,the duty cycle of the PWM signals can be specified via dialogor through input port. The PWM outputs can be

    enabled/disabled through input ports. This feature is usefulfor the control of three phase bridges.

    Fig. 5. Function Block Parameters window of the LM3S000

    PWM block.

    Signal generator in Count-Down mode, there are four events that can affect the PWM signal: zero, load, matchcomparator A down and match comparator B down. In Count-Up/Down mode, there are two supplementary events that canaffect the PWM signal: match comparator A up and andmatch comparator B up. These actions can be used togenerate a pair of PWM signals of various positions and dutycycles, which do or do not overlap.

    Dead band - if dead band is enabled, the second output PWMsignal is the inversion of the first PWM signal with a

    programmable delay added between the falling edge and therising edge of the PWM signals. This tab allows thespecification of the rising and falling edge delays between thetwo PWM signals. The PWM signals with dead band areused for driving a halfH bridge in order to avoid a shortcircuit condition.

    Synchronization this tab allows the specification of theupdate mode for the timers and for the comparators used togenerate the PWM signals; the update mode for the PWMgenerators and the dead band update mode.

    ADC trigger specifies the events that generates ADCtrigger.

    6. CAN library

    Controller Area Network (CAN) is a multicast, shared serial bus standard for connecting electronic control units. CANwas specifically designed to be robust in electromagnetically-noisy environments. Originally created for automotive

    purposes, it is also used in many embedded controlapplications. Bit rates up to 1Mbps are possible at network lengths less than 40 meters.

    An important feature which should be implemented by anRCP toolbox is the real-time observation of the code

    executed on the embedded processor (Mathworks, 2008).One industry standard is the use of the CAN bus. For this

    Preprints of the 18th IFAC World CongressMilano (Italy) August 28 - September 2, 2011

    1967

  • 7/27/2019 2998

    4/6

    purpose the CAN library presented in Fig. 6 wasimplemented.

    Fig. 6. CAN library.The library contains three blocks which are used for theconfiguration of the CAN module:

    CAN Configure the block specifies the CAN module used,the operating mode and the baud rate.

    CAN Transmit the block configures the slot of a CANmodule for the transmission of a message with a certainidentifier.

    CAN Receive the block configures the slot of a CANmodule for the reception of a message with a certainidentifier.

    7. Digital Motor Control Library

    The DMC library (Fig. 7) contains blocks which implementdigital motor control algorithms.

    Fig. 7. DMC library.

    The implemented algorithms are optimized for theLM3S8000 microcontrollers, which are fixed point

    processors. Only integer variables are declared, and thesingle-cycle multiply instruction and the hardware dividefeatures of Stellaris microcontrollers are used in order toobtain the lowest sampling rate without breaking the real-time constrains.

    For the moment the library contains only a block whichimplements a PID controller with antisaturation. Thestructure of the controller is described in detail below. In thefinal version of the toolbox the DMC Library will contain

    blocks for three phase motor control and for BLDC motor control.

    More than 90% of the control loops are of PI and PID type.The reason for which the PID controller is so widely used isits simple structure which has proved to be very robust withregard to many commonly control problems.

    The standard equation of a PID controller is presented below:

    t

    d i

    p dt t d T d

    T t K t u

    0)()(1)()(

    where )()()( t yt yt sp is the error signal, sp y is theset point and y is the output of the process.

    The discrete equations used for the implementation of thePID algorithm are described below:

    ))()(()( n yn y K n P sp p

    ))()1(()1()( n yn yn Dn D d d (1))()()()( n Dn I n P nv

    ))()(())()(()()1( nvnun yn yn I n I t spi

    where NhT T d d d , NhT N T K d d pd ,i s pi T T K and t st T T .

    Equations (1) were used for TLC implementation of the LM3S8000 PID block.

    For the PID controller the following parameters have to bechosen: K p, proportional gain; T i, integration time; T d ,

    derivative time; , fraction of command signal; N, highfrequency limiter of derivative action; umin, minimumsaturation value; umax, maximum saturation value; and T s , sampling time. The block has two input ports: the referenceand the feedback signal and one output: the command signalfor the controlled process.

    8. APPLICATION EXAMPLE

    In order to test the implemented toolbox a practicalapplication for a Computer Numerical Controlled (CNC)machine was implemented. The stepper motors of an oldCNC machine are replaced with Brushless Direct Current

    (BLDC) motors, in order to obtain higher positioningaccuracy. For BLDC motor control, three PWM signals andthree activation signals are needed. Unlike a DC motor, the

    Preprints of the 18th IFAC World CongressMilano (Italy) August 28 - September 2, 2011

    1968

  • 7/27/2019 2998

    5/6

    BLDC motor must be commutated electronically. In order tosimplify the control of the BLDC motor, a control logiccircuit was implemented. Using this control logic circuit, aBLDC motor can be controlled similarly to a DC motor. Asingle PWM signal and a single feedback signal are needed.The description of the control logic circuit is out of the scope

    of this paper.A Stellaris LM3S8962 Ethernet+CAN evaluation kit,equipped with a LM3S8962 microcontroller is used as target

    processor. The motor which is controlled is a Hurst-EmersonBLDC motor ([Emerson]). In order to communicate betweenthe embedded processor and the PC, an USB to CANconverter produced by Systec-Electronic ([SystecElectronic])is used. The test setup is presented in Fig. 8.

    Fig. 8. The test setup.

    The closed loop Simulink model for the control of an axis of the CNC machine is presented in Fig. 9. The model of the

    control algorithm implements a cascade control topology. For the position loop a PI controller is used and for the speedloop a P controller is used. The parameters of the controllersare computed using the method introduced by Kessler (Kessler, 1958). The position reference is a rectangular signal, which is applied on the reference port of a LM3S8000

    PID bock. The output of the position controller sets thereference of the speed controller. The speed controller computes the duty cycle of the PWM signal which is used for the control of the BLDC motor of the axis of the CNCmachine.

    A configuration LM3S8000 CAN Configure block is added tothe model. It does not connect to any other blocks, but standsalone to configure the selected CAN module.The reference

    position, the measured position and the speed areconcatenated into an array and are sent over the CAN bususing a LM3S8000 CAN Transmit block.

    A target preference block has to be added to the model. The LM3S8000 Target block does not connect to any other blocks, but stands alone to set the target preferences for themodel. After the validation of the model the code generation

    process is invoked, and the generated executable file isdownloaded to the LM3S8962 processor

    The positioning of the axis of the CNC machine is shown inFig. 10 and the speed in Fig 11.

    9. CONCLUSIONS

    A contribution of the paper is the implementation of a RCPtoolbox for the Stellaris LM3S8000 family of

    microcontrollers, using as CACSD tool Matlab/Simulink.Until now, for these microcontrollers there was not a RCPtoolbox. The RCP approach removes the need to writesoftware by hand and allows the engineer to focus instead onimproving the performance of the control algorithm.

    Fig. 9 Simulink block diagram for the control of an axis of the CNC machine.

    CNC axis LM3S8000 Evaluation Kit USB-CAN Converter Driver Control Logic

    Preprints of the 18th IFAC World CongressMilano (Italy) August 28 - September 2, 2011

    1969

  • 7/27/2019 2998

    6/6

    Fig. 10. The positing of the axis of the CNC machine.

    Fig. 11. Speed profile of the axis of the CNC machine.

    In our opinion, the Traget for Stellaris LM3S8000 RCPtoolbox has some advantages over the code generationsolution offered by NI. First, the toolbox is targeted for allthe microcontrollers of the LM3S8000 family of ARMmicrocontrollers, while in LabView only the LM3S8962microcontroller is supported. Second, the developed RCPtoolbox is dedicated for the LM3S8000 processors, whichmakes the graphical programming approach much easier thanin LabView, which offers support for several ARM

    microcontrollers, among which the Stellaris LM3S8962microcontroller.

    The Stellaris microcontrollers are suited for motor controland communication applications because motion plusconnectivity is possible only with a deterministic architecturelike ARM Cortex-M3. In the selection of the target processor it is recommended to choose a widely available evaluation

    board. The LM3S8962 Ethernet+CAN Evaluation Kit used inthe practical application presented is such an evaluation

    board.

    ACKNOWLEDGMENT

    This paper was supported by the project Progress anddevelopment through post-doctoral research and innovationin engineering and applied sciences PRiDE - Contract no.POSDRU/89/1.5/S/57083", project co-funded from European

    Social Fund through Sectorial Operational Program HumanResources 2007-2013.

    REFERENCES

    Bucher, R., Dozio L. and Mantegazza P. (2004). Rapidcontrol prototyping with Scilab/Scicos and Linux RTAI.Scilab Conference .

    Campbell, S. L., Chancelier, J.-P., and Nikoukhah, R. (2009). Modeling and simulation in Scilab/Scicos with ScicosLab4.4 , Springer.

    Duma, R., Dobra, P., Trusca, M., Dumitrache, D., and Sita, I.V. (2009). Rapid control prototyping educationaltoolbox for Scilab/Scicos, in Proc. of European Control Conference 2009 , pp. 4611-4616.

    Duma, R., Trusca, M., and Dobra, P. (2010). BLDC Motor Control using Rapid Control Prototyping, in Journal of Control Engineering and Applied Informatics , vol. 12,nr. 1.

    Hanselman, H. (1996). Automotive control: from concept toexperiment to product, Proc. IEEE International Symposium on Computer-Aided Control System Design ,

    pp. 129-134, Sept. 15-18.Hercog, D., Curkovic, M., and Jezernik, K. (2006). DSP

    Based Rapid Control Prototyping Systems for Engineering Education and Research, Proceedings of the 2006 IEEE Conference on computer Aided Control Systems Design, Munich, Germany, October 4-6.

    Kerhuel, L. (2009). Simulink - Embedded Target for PIC .Kessler, C. (1958) Das symmetriche optimum.

    Regelungstetechnik, 6, 395-400 , 432-436.Mathworks (2008), Real-Time Workshop Embedded Coder 5

    Developing Embedded Targets .Mathworks (2010), Simulink users guide .Microchip (2009), MATLAB/Simulink device blocksets for

    dsPIC DSCs . National Instruments (2010). Getting started with the NI

    LabVIEW embedded module for ARM microcontrollers .Ravn, O. (2006). Adaptive control using the adaptive

    toolbox-TAT for Scilab/Scicos, 14th IFAC Symposiumon System Identification , Newcastle, Australia.

    Rebeschiess, S. (1999).MIRCOS- microcontroller-based realtime control system toolbox for use withMatlab/Simulink. Proc. IEEE Int. Symp.Computer

    Aided Control System Design , pp. 267-272.

    ([Comedi]) Comedi. URL http://www.comedi.org .([Emerson]) Emerson. URL http://www.emersonmotors.com .([SystecElectronic]) SystecElectronic. URL

    http://www.systec.com

    Preprints of the 18th IFAC World CongressMilano (Italy) August 28 - September 2, 2011

    1970