A Simulink target for real-time control using Freescale MC9S12 microcontrollers
RTMC9S12-Target is a MATLAB/Simulink block-set for
real-time control on Freescale
MC9S12 microcontrollers. This contribution opens the door to inexpensive rapid prototyping of real-time control systems on MC9S12DP256 based hardware.
A Simulink block diagram is translated into C-code using MathWorks Real-Time Workshop and Embedded Coder. The present version of this toolbox was built with MATLAB 7.4 (R2007a), but should work with newer versions. The builder calls upon Metrowerks CodeWarrior to compile the generated C-code into a real-time executable file which can be downloaded into the Flash ROM of the chip. Presently, Wytecs Dragon-12 as well as the slightly smaller MiniDragon+ development boards are supported. Adaptations to other MC9S12DP256 based target boards should be straight forward.
Once installed, the real-time code can be controlled using Simulinks External Mode Interface. This fully integrates the target code and the initial model file. Target data is uploaded by a background task through one of the two serial interface (e.g. SCI1) and displayed using regular Simulink blocks (e.g. Scope, Display, etc.).
In addition to this, the model parameters of the Simulink model can be modified while the code is running. Every time a parameter is changed, Simulink updates the parameter record on the target. This on-the-fly parameter tuning capability makes it very easy to experiment with different controller settings.
A number of hardware specific blocks have been provided to give access to the various hardware units of the microcontroller. At present, the following units are supported: both A/D converter units (ATD0, ATD1), the PWM unit, digital inputs and digital outputs, the timer unit (Output Compare mode as well as Input Capture mode) and the serial port SCI0, SCI1.
In addition, there are a number of blocks which make use of the underlying hardware to provide extra functionality, e.g. support for serially loaded D/A converters (connected to the I2C/IIC bus, e.g. Analog Devices, AD5311), support for the fuzzy control engine of the microcontroller (Mamdani fuzzy inference with up to three inputs),
support for Devantech ultrasonic range finders and support for Nordic nRF24L01 radio modules (reliable wireless communications for less than US$20, e.g. Spark Fun).
User communication blocks allow the exchange of short user telegrams between the code running on the target and a second Simulink block diagram. The latter is completely independent of the target code. It allows the output of host-based Simulink models or m-files to be interfaced to the target. User communication blocks are useful in applications which rely on the download of high-level control data such as reference trajectories or information provided by a host-based vision system, etc. See the user manual (3.05 MB) for further details.
RTMC9S12-Target is distributed as Free Software
under the terms of the GNU Public License Agreement (GPL). The spirit
of free software incorporates the users freedom to run, copy,
distribute, study, change and improve the software. Commercial
developments based on RTMC9S12-Target are permitted within the limits of
At our institution we have successfully used this toolbox for undergraduate teaching in Mechatronics and Automatic Control as well as in a number of final year projects, e.g. Edgar - a self balancing scooter, Soccer robots or RoboFiddler - a robotic violin player. Any feedback on bugs and suggestions for improvements are highly valued and should be directed to Frank Wornle.
The RTMC9S12-Target has been included in a text Introduction to MATLAB & Simulink: A Project Approach, 3/E. published by Infinity Science Press.
The University of Adelaide, July 2009
- A commercial alternative to the rtmc9s12 toolbox for programming the 9s12 family of microcontrollers is QuantiPhi.
- Development of the RTMC9S12 toolbox has been moved to SourceForge. The latest version can be downloaded here.
- To download the base files of the RTMC9S12-Target for the Metrowerks Codewarrior compiler suite and MATLAB 7.4 and 7.5 (R2007a and R2007b) click here.
- The compiled library files to suit MATLAB 7.4 (R2007a) can be found here.
- The compiled library files to suit MATLAB 7.5 (R2007b) can be found here.
- The user manual can be found here (pdf, 3.05 MB).
Recent changes and extensions:
|06/07/09||Development of the toolbox moved to SourceForge.
|18/02/08||Various bug-fixes for Matlab r2007b. For more details see the RELEASE NOTES.
|27/11/07||Release of the toolbox that also supports Matlab r2007b. The libraries are now distributed separately, and it will work in a read-only install environment.
|14/09/07||General code cleanup. Projects can now be built without External Mode. Note that if you are planning to do this, it is a good idea to turn the inline parameter optimisation on. Banked memory model and RF Comms now working. Fixed library linking issue for dsplib. Ensured all example models use 400B FIFO buffers, and a 6500B memory pool.
|15/08/07||Release of the toolbox for MATLAB R2007a.
|26/09/06||Release of V2 of the toolbox. Many additions, including wireless communications, fuzzy control blocks, timer blocks, extended FreePort communications, etc.
|29/10/05||Freeport communication now works properly with all data types (single, int32, int16, etc.). This important fix has been provided by George Wong.
|29/10/05||Additional option which allows the code to be launched upon reset, i. e. without having to connect through Simulink. This is useful in many robotics applications which require autonomous operation, e.g. EDGAR the scooter or the RoboCup project.
|28/08/05||Fixed bug in the build
process; previously, starting a model from scratch (e.g. the tutorial
example) caused the build process to exit with an error message. All
sample models have been updated and tested - should work now.
ports (SCI0, SCI1) can now be used as FreePorts. This implies
switching off the External Mode interface.|
FreePort sample programs to the new blocks.|
|(10/05/05)||Added a raw data
feature to the FreePort communication blocks; this makes it possible
to interface external sensors / devices which use serial communication
to transmit / receive data.|
|(04/05/05)||Fixed a bug in the
build process that was introduced with the FreePort communication
communication blocks - these blocks provide serial communication
using the free SCI port of the 9S12 (this port is not used by the
MATLAB External Mode interface). Supports baudrates ranging from 300
bps to 115200 bps. The (pdf) documentation has been updated to include
these new blocks. The online help system still needs fixed and there
is a known bug in the transmission of all 4-byte data types such as
single precision data, int32, etc. (order of bytes needs
|(02/05/05)||Fixed a bug in the
Digital Input block. (All channels used to tied to bit 0 - they are
|(21/04/05)||New block: Servo
Motor PWM. Also fixed up the help system.|
missing file - code should not have compiled without this. My
|(13/04/05)||Updated version of
the manual including (slightly) more detailed installation
instructions which also cover the necessary increase of heap
space as defined in the CodeWarrior libraries. Also, a path
problem occurred during installation on some machines|