Wytec Dragon12 Development Board

Code Examples

 

This page provides links to a number of useful code examples for on the Wytec Dragon12 development board (freescale MC9S12DP256B/C) and/or the Wytec MiniDragon+ board.

 

 

Quick links:

HCS12 Serial Monitor  --  Using Freescale’s HCS12 Serial Monitor on Wytec Dragon-12 boards

Protected programs  --  Installing HCS12 Serial Monitor with protected user programs on the Dragon-12

SerMon on MiniDragon  --  Installing HCS12 Serial Monitor with protected user programs on the MiniDragon+

RTMC9S12-Target  --  A MATLAB/Simulink real-time target for MC9S12DP256 based systems

Laboratory handouts  --  8 introductory laboratory handouts

Lecture notes  --  8 introductory laboratory handouts

CodeWarrior Stationery  --  A CodeWarrior stationery for the Dragon-12 with the HCS12 Serial Monitor

Example programs  --  A collection of CodeWarrior sample projects for the MC9S12DP256 (C-language)

GNU gcc examples  --  GNU gcc based examples (m6812-elf-gcc)

 

 

HCS12 Serial Monitor

This link provides instructions for replacing the on-board monitor program DBug-12 by Motorola’s HCS12 Serial Monitor. The latter is useful when working within the Metrowerks CodeWarrior IDE. The HCS12 Serial Monitor provides full access to CodeWarrior’s source level debugger Hi-Wave. A sample project (test_led) has also been included

 

HCS12 Serial Monitor on Dragon-12

HCS12 Serial Monitor on Dragon-12  --  Instructions

 

Protected programs

This extension of the above project allows the installation of two ROM resident system programs which can be launched via the on-board switch SW7\2 of the Dragon12 board. SystemProgram1 provides a comprehensive self-assessment of the MC9S12DP256B/C – this program uses features of a protective circuit board we have developed to safeguard our Dragon12 boards against the worst student abuse. The protective circuit board features two serially loaded D/A converters which are used to test the A/D converter unit of the microcontroller. The circuit diagrams as well as the PCB layout have been included with the documentation. SystemProgram2 simply displays the board ID on the LCD-display of the Dragon12. Both programs are in the protective area of Flash ROM (extended to 8 kByte); the total size of both programs must be less than 6 kByte. It is possible to extend this to a maximum of 14 kByte.

 

HCS12SerialMonitor_Dragon12_SysProg6K_2

HCS12SerialMonitor_Dragon12_SysProg6K_2  --  Instructions

 

 

SerMon on MiniDragon

This is an adaptation of the above project for the MiniDragon+ board. Two ROM resident system programs can be launched via the on-board switches SW1 and SW2 of the MiniDragon+ board. At present, SystemProgram1 simply displays a ‘1’ on the 7-segment display; SystemProgram2 displays a ‘2’. Both programs are in the protective area of Flash ROM (extended to 8 kByte); the total size of both programs must be less than 6 kByte. It is possible to extend this to a maximum of 14 kByte.

 

HCS12SerialMonitor_MiniDragon_SysProg6K_2

HCS12SerialMonitor_MiniDragon_SysProg6K_2  --  Instructions

 

 

 

RTMC9S12-Target

Recent changes and extensions:

 

(17/05/05)        Both communication ports (SCI0, SCI1) can now be used as FreePorts. This implies switching off the External Mode interface.

(11/05/05)        Updated all 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 blocks.

(02/05/05)        Added FreePort 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 reversed).

(02/05/05)        Fixed a bug in the Digital Input block. (All channels used to tied to bit ‘0’ – they are now independent).

(21/04/05)        New block: Servo Motor PWM. Also fixed up the help system.

(19/04/05)        Added accidentally missing file – code should not have compiled without this. My apologies... :)

(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

 

This project opens the door to inexpensive rapid prototyping of real-time control systems on MC9S12DP256 based hardware. The present version works with MATLAB 6.5.1 (Release R13.1). A Simulink block diagram is turned into C-code using MathWorks’ Real-Time Workshop and Embedded Coder. The builder then 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. Once installed, the real-time code can be controlled using Simulink’s ‘External Mode Interface’. This fully integrates the target code and the initial model file. Target data is uploaded by a background task through the serial interface SCI1 and displayed through the regular Simulink block (e.g. Scope, Display, etc.). 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, e.g. both A/D converter units (ATD0, ATD1), the PWM unit, digital inputs and digital outputs as well as the two D/A converters on the protective circuit boards we use in our laboratory (Analog Devices, AD5311). 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 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 (1.5 MB) for further details. A higher resolution version of this document can be downloaded here (3.4 MB).

 

The current release of this toolbox should be considered a ‘beta release’. A small number of known problems will still have to be addresses. The toolbox may also be ported to MATLAB 7.0 (R14) in the near future. Nevertheless, the present release runs reasonably well. At this stage, the Wytec Dragon-12 board as well as the MiniDragon+ can be targeted. The use of the toolbox on other target boards should be unproblematic. Most target specific parameters can be defined using the Real-Time Workshop options page (e.g. communication ports, supported baudrates, etc.). We will use this toolbox for undergraduate teaching in Mechatronics and Advanced Automatic Control as well as in a number of final year projects. Any feedback on what may still not work or what could be improved is highly valued and always welcome.

 

Real-time target toolbox rtmc9S12-Target for MATLAB 6.5.1 (R13.1) and Metrowerks CodeWarrior

 

 

 

Laboratory handouts

The following lab handouts have been written for and tested with the Dragon12 boards:

 

LMP1 – Introduction to the KEIL IDE mVision (Infineon C167 microcontroller)

LMP2 – Introduction to the Metrowerks CodeWarrior and the Hi-Wave debugger/simulator

LM3 – Programming the A/D converter of the MC9S12DP256B/C

LM4 – Programming the Enhanced Capture Timer (ECT) unit of the MC9S12DP256B/C

LMP5 – Interfacing a serially loading D/A converter (Analog Devices AN5311, 10-bit, I2C) to the MC9S12DP256B/C

LM6 – Design and implementation of a FIR band-pass filter on the MC9S12DP256B/C

LM7 – Design and implementation of a fuzzy logic speed controller for a DC motor

LMP6 – The serial communication interface

LMP7 – Driving stepper motors

LMP8 – Driving DC motors and DC servos

 

 

 

Lecture notes

The following lecture notes complement the above laboratory sessions. The make reference to the Infineon C167 microcontroller. However, all introduced topics can easily be transferred to Freescale 9S12 based systems (e.g. the Dragon-12). The accompanying programs can be run in simulation mode using the KEIL Integrated Development Environment mVision (3.0); a code-size limited evaluation version of this IDE can be downloaded from the KEIL web site.

 

Lecture MP2:         Powerpoint slides             Printable version (black and white, pdf, 458 kB)

Lecture MP3:         Powerpoint slides             Printable version (black and white, pdf, 1012 kB)

Lecture MP4:         Powerpoint slides             Printable version (black and white, pdf, 417 kB)

Lecture MP5:         Powerpoint slides             Printable version (black and white, pdf, 1209 kB)

Lecture MP6:         Powerpoint slides             Printable version (black and white, pdf, 633 kB)

Lecture MP7:         Powerpoint slides             Printable version (black and white, pdf, 374 kB)

Lecture MP8:         Powerpoint slides             Printable version (black and white, pdf, 291 kB)

Lecture MP9:         Powerpoint slides             Printable version (black and white, pdf, 2068 kB)

Lecture MP10:       Powerpoint slides             Printable version (black and white, pdf, 986 kB)

Lecture MP11:       Powerpoint slides             Printable version (black and white, pdf, 876 kB)

 

 

 

CodeWarrior Stationery

The above programs are all based on the following CodeWarrior stationery:

 

Metrowerks CodeWarrior Stationery for Dragon12, flat memory model

 

 

 

Sample programs

The following sample programs accompany the above lab handouts:

 

Latest modifications and additions:

06/05/05  --   Fixed Pulse-Width Modulation program (didn’t run properly at faster rates)

03/05/05  --   Fixed serial communication at low speeds (now works down to 300 bps)

28/03/05  --   Added sample programs to demonstrate the use of ring buffer based background communication

28/03/05  --   Added sample programs to demonstrate the use of the PWM unit

28/03/05  --   Added sample programs to demonstrate multi-channel A/D conversions

28/03/05  --   Updated all A/D based projects to use the corrected A/D complete conditions (CCF0 for single channel conversions)

17/02/05  --   IIC bus interface of all projects involving the D/A converters now actually clears the IBIF flag.

17/02/05  --   Stepper motor driver program (requires hardware driver circuit).

17/02/05  --   Sample project for the LCD module (code: Prof. Louis Bertrand, Durham University, Canada).

17/02/05  --   Serial communication routines for SCI1 now include support for signed and unsigned data types.

12/08/04  --   Serial communication tidied up… both ports now work at all baud rates up to 115 kbps.

 

Simple LED program

Hello world on SCI0

Hello world on SCI1

Simple terminal on SCI1

Simple terminal on SCI1 using background communications (ring buffer version 1)

Simple terminal on SCI1 using background communications (ring buffer version 2)

Simple timer (TOC7)

A/D conversion using polling

A/D conversion using interrupts

A/D conversion and timer (1)

A/D conversion and timer (2)

A/D conversion and timer (3)

A/D conversion, data displayed on SCI1

A/D multi-channel conversion, data displayed on SCI1

A/D conversion, data displayed on SCI1, data sent to D/A converter (AN5311, 10-bit, I2C communication interface)

A/D conversion, data sent to D/A converter (AN5311, 10-bit, I2C communication interface), 3000 Hz

Pulse-Width Modulation example

Simple FIR filter (128 coefficients)

Slightly more efficient FIR filter

Simple IIR filter (transfer function realisation)

Reliable IIR filter (using second-order sections)

Fuzzy logic speed control for a DC motor

LCD display (slightly modified copy of Prof. Louis Bertrand’s LCD code)

Stepper motor driver (requires corresponding hardware driver circuit)

 

 

 

GNU gcc examples

Banked memory access

Banked memory access, version 2

Banked memory access, automatic linker scripts

 

 

 

 

 

Frank Wornle ()

The University of Adelaide

School of Mechanical Engineering

 

March, 2005