
Introduction
These labs highlight key features of the MCF51EM
microcontroller and are implemented as a standard
CodeWarrior project without an RTOS framework.
They are also intended to serve as software examples
of peripheral configuration and functional operation.
For code examples using the MQX RTOS, please refer
to the DEMOEM MQX Lab Tutorials document within the
documentation section of the Getting Started DVD.
Before You Begin
Complete the steps in the Quick Start Guide to install1.
CodeWarrior for Microcontrollers v6.3 Special Edition
(30-day evaluation version).
Ensure the DEMOEM board jumpers are configured in their2.
factory default positions, as described in the DEMOEM User
Manual within the documentation section of the Getting
Started DVD.
The demonstration code was programmed into the flash
memory of the MCF51EM MCU prior to shipment of the
DEMOEM kit. It should not be necessary to re-program
the device unless you have already completed the MQX
labs or have downloaded your own development code
to MCU flash.
Program the Demo Code to MCU Flash
In the event that flash has been over-written since the
arrival of your DEMOEM kit, download the project code
to the MCU as follows:
Select the ‘DEMOEM Project for CodeWarrior 6.3’ link under1.
the Software tab of the Getting Started DVD and save the
project to your hard drive.
Open CodeWarrior for Microcontrollers. From the Windows2.
Start menu, select “Programs>Freescale CodeWarrior>CW
for Microcontrollers V6.3>CodeWarrior IDE.”
Open the lab project by selecting the File>Open menu3.
option and navigating to the directory path where the
DEMOEM-CW63.mcp file was saved during Step 1.
In the project pane, select the “P&E Multilink/Cyclone Pro”4.
build target, as shown below:
Compile the project by pressing the F7 key or by5.
clicking the Make icon on the project pane.
Connect the DEMOEM board to your computer using the6.
USB cable included with the kit. Then power the board by
sliding switch K6 in the upper left corner of the board to the
left-most position. The red Power LED, the green USB LED,
and the QE8 Signal Generator LEDS should be on.
Now start the debugger by clicking the7.
Debug icon.
The P&E MCF51xx Connection Manager window will8.
now appear as shown below. Click the Connect button
and a dialog box will appear asking if you would like to
erase the flash and program it with the project code.
Select OK to proceed.
After the code has been programmed to flash, begin code9.
execution in one of several ways:
a. Press the debugger Run button.
b. Press the DEMOEM hardware Reset button.
c. Disconnect and reconnect the USB cable from the
DEMOEM board.
d. Toggle power switch K6 to power-down, then power-up
the MCU.
Once code is executing, you may close the True-Time10.
Simulator and Real-Time Debugger window.
You should now see a welcome message on the
DEMOEM LCD:
Demo Code Functional Structure
The demonstration code operates as a state machine
(see back page for program flow diagram).
Progression through the states is controlled via the
SW1 button. Once the Welcome state is exited, it is
impossible to return without a Reset/POR.
Familiarize yourself with the DEMOEM hardware and the
various user interfaces that will be used over the course
of the following lab exercises, many of which have been
labeled on the board diagram (see back page).
State
1
Measure Typical Power and
Energy Parameters of an Emulated
Three-Phase System Using the
MCF51EM ADC and PDB
This lab demonstrates the smart metering capability
of the MCF51EM microcontroller. Code configures the
ADC and uses the Programmable Delay Block (PDB)
to trigger conversions at precisely-timed intervals to
account for phase delay between voltage and current
measurements. The resulting conversions are stored to
a cyclic RAM buffer for calculation of RMS voltage (V)
and current (I), current at the fundamental frequency (IF),
power factor (PF), energy (E), active power (P), reactive
power (RP), apparent power (AP) and total harmonic
distortion (TH).
The DEMOEM 9S08QE8 signal generator circuit in the
lower right corner of the board must be configured
for normal mode operation, as indicated by one blink
every three seconds of the LED labeled “PTC2.” Use
push button SW5 to cycle the signal generator through
its operating modes until normal mode is achieved.
For more information regarding the signal generator
functionality, refer to the QE8 Signal Generator User
Manual within the documentation section of the Getting
Started DVD.
User Interface
• SW1 advances to the next state/demo.
• SW2 advances through the available measurements/
calculations as follows: RMS voltage (V) -> RMS current (I)
-> current at the fundamental frequency (IF) -> power factor
(PF) -> energy (E) -> active power (P) -> reactive power
(RP) -> apparent power (AP) -> total harmonic distortion
(TH) -> RMS voltage (V) ->
• SW3 and SW4 scroll backward and forward, respectively,
through the individual measurements/calculations:
line1<-> line2 <-> line 3 <-> total <-> line1
* Note that some parameters do not have a “total” field.
• Potentiometer W1 adjusts the amplitude of the voltage
waveforms all together (lines 1, 2, and 3 simultaneously).
• Potentiometer W2 adjusts the amplitude of the current
waveforms all together (lines 1, 2, and 3 simultaneously).
• Potentiometer W3 adjusts the phase delay between the
voltage and current waveforms.
Step by Step Instructions
Press SW1 until you see the “Measurement” state on1.
the display.
Press SW2 to enter the metering demo. RMS2. voltage for
line1 will be shown on the LCD.
Step the metering demonstration through all3. the calculated
parameters using SW2 and note the change in each
parameter as you vary the stimulus waveforms using the
signal generator’s potentiometers.
State
2
Use the IRTC Tamper Log Feature
to Track Hardware Tamper Events
The MCF51EM independent real-time clock (IRTC)
includes a feature that records the type and timestamp
when hardware tampering events, such as a change in
state of the Tamper device pin or removal of the IRTC
VBAT supply during normal operation, occur.
For this demonstration, install a CR2032 battery
(not included with the DEMOEM kit) in the appropriate
socket underneath the board to avoid continuous
tamper detection for missing VBAT source. Then install
a jumper at J37 to connect the MCU VBAT pin to the
CR2032 battery source.
User Interface
• SW1 advances to the next state/demo.
• Press (SW2 + SW3) or (SW2 + SW4) to clear the tamper log.
• SW3 and SW4 scroll backward and forward, respectively,
through the Tamper log entries recorded in MCU flash.
Step by Step Instructions
Press SW1 until you see the “Tamper Log” state on1.
the display.
Press SW2, SW3 or SW4 to view the contents of the log in2.
flash, which should be initialized to 00-00-00 on reset.
Press and hold the Tamper button (near Reset below the3.
LCD) for a few seconds before releasing it. You should see
new events recorded in the tamper log: one timestamp
with code “P” to indicate a tamper event due to a change
in state of the MCU Tamper pin, and another with
timestamp code “A” to indicate when the pin tamper
event was cleared. The recorded time of each tamper event
is displayed as HH-MM-SSC where HH=hours,
MM=minutes, SS=seconds, and C=tamper code.
Now remove the CR20324. battery and wait a few seconds
before you reinstall it. Again, you should notice two new
entries in the tamper log. One with a timestamp code “b”
to indicate a VBAT supply interruption during normal MCU
operation, and another with the “A” timestamp code to
again note when the battery tamper event cleared.
DEMOEM Lab Tutorial: V1 ColdFire MCU for smart metering