Docsity

Lab 1 - Project Creation and Debugging | ELEC 3040, Lab Reports of Electrical and Electronics Engineering

Toggle sidebar
bg1
ELEC 3040 – Electrical Engineering Lab IV
ELEC 3050 – Computer System Design Lab
Lab Session 1 – Project Creation and Debugging
The objective of this laboratory session is to become familiar with the process for
creating, executing and debugging application programs, using the CodeWarrior
Development Studio for the Freescale MC9S12C32 or MC9S12C128 microcontroller,
mounted on a “DragonFly” development module. (These two microcontrollers are
identical, except for containing 32K and 128K of flash memory, respectively. They will
be referred to as simply the HCS12 in the rest of this document.) Two “projects” will be
created and tested, one in assembly language and the other in C. This will demonstrate
the basic setup of an application project in each language, as well as the process for
transferring the program to the HCS12 and debugging the program.
The second objective of this laboratory session is to begin utilizing the engineering
communication skills discussed in the lecture. Specifically, an engineering notebook is
to be maintained, documenting all designs, lab procedures utilized, observations of the
results of each test or procedure, and notes on any errors detected and their solutions.
Also, a two-page memo documenting the activities of the lab session is to be written and
submitted by each member of the team (in subsequent weeks, one person will submit a
memo for the team.)
Installing the DragonFly12 Development Module
You will be issued a breadboard station and an HCS12-based “DragonFly12” module
(http://www.evbplus.com/c32_modules/c32.html), shown in Figure 1. Each lab station
includes a personal computer, a power supply, and a Witztronics WTBDMS12
background debug mode (BDM) module to connect to the microcontroller. You will
need to obtain your own breadboard(s) from the Scientific Supply Store prior to the start
of lab. The DragonFly12 module contains a Freescale HCS12 microcontroller and a 6-
pin BDM (background debug mode) header. The microcontroller is from the Freescale
HCS12 family of devices discussed in the ELEC 2220 text book. The HCS12 contains
32K bytes (MC9S12C32 chip) or 128K bytes (MC9S12C128 chip) of flash memory, 4K
bytes of RAM, and a variety of input/output and other peripheral functions. The pin
numbering on the DragonFly12 is shown in Figures 2 and 3, and the DragonFly12
schematic diagram is linked to the course web page. Note that a number of HCS12
input/output port signals are not accessible on the 40-pin module.
The breadboard stations have banana jacks for connecting the power supply, a 50-pin
header for connecting a logic analyzer, and a variety of switches, LEDs, 7-segment
display digits and decoders that can be used for debugging. The 7-segment display digits
include binary to 7-segment decoders, to which connections are made via the headers
below the digits.
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Lab 1 - Project Creation and Debugging | ELEC 3040 and more Lab Reports Electrical and Electronics Engineering in PDF only on Docsity!

ELEC 3040 – Electrical Engineering Lab IV

ELEC 3050 – Computer System Design Lab

Lab Session 1 – Project Creation and Debugging

The objective of this laboratory session is to become familiar with the process for creating, executing and debugging application programs, using the CodeWarrior Development Studio for the Freescale MC9S12C32 or MC9S12C128 microcontroller, mounted on a “DragonFly” development module. (These two microcontrollers are identical, except for containing 32K and 128K of flash memory, respectively. They will be referred to as simply the HCS12 in the rest of this document.) Two “projects” will be created and tested, one in assembly language and the other in C. This will demonstrate the basic setup of an application project in each language, as well as the process for transferring the program to the HCS12 and debugging the program.

The second objective of this laboratory session is to begin utilizing the engineering communication skills discussed in the lecture. Specifically, an engineering notebook is to be maintained, documenting all designs, lab procedures utilized, observations of the results of each test or procedure, and notes on any errors detected and their solutions. Also, a two-page memo documenting the activities of the lab session is to be written and submitted by each member of the team (in subsequent weeks, one person will submit a memo for the team.)

Installing the DragonFly12 Development Module

You will be issued a breadboard station and an HCS12-based “DragonFly12” module (http://www.evbplus.com/c32_modules/c32.html), shown in Figure 1. Each lab station includes a personal computer, a power supply, and a Witztronics WTBDMS background debug mode (BDM) module to connect to the microcontroller. You will need to obtain your own breadboard(s) from the Scientific Supply Store prior to the start of lab. The DragonFly12 module contains a Freescale HCS12 microcontroller and a 6- pin BDM (background debug mode) header. The microcontroller is from the Freescale HCS12 family of devices discussed in the ELEC 2220 text book. The HCS12 contains 32K bytes (MC9S12C32 chip) or 128K bytes (MC9S12C128 chip) of flash memory, 4K bytes of RAM, and a variety of input/output and other peripheral functions. The pin numbering on the DragonFly12 is shown in Figures 2 and 3, and the DragonFly schematic diagram is linked to the course web page. Note that a number of HCS input/output port signals are not accessible on the 40-pin module.

The breadboard stations have banana jacks for connecting the power supply, a 50-pin header for connecting a logic analyzer, and a variety of switches, LEDs, 7-segment display digits and decoders that can be used for debugging. The 7-segment display digits include binary to 7-segment decoders, to which connections are made via the headers below the digits.

Figure 1. Wytec “DragonFly12” 40-pin DIP module (http://www.evbplus.com/c32_modules/c32.html)

Figure 2. Wytec DragonFly12 module layout (top) (http://www.evbplus.com/c32_modules/c32.html)

After clicking OK, the “New Project Wizard” guides you through the rest of the project setup process (click “Next” on each screen.) You will first be asked to select the “derivative”, i.e. the specific target microcontroller for the project. Select MC9S12C32 or MC9S12C128, corresponding to the microcontroller chip on your DragonFly module. For your information, the HCS12 data sheet is linked to the course web page.

Figure 2. Select MC9S12C32 or MC9S12C128 microcontroller.

On the next screen (Figure 3), select the language(s) to be used for the project. Note that you may select more than one if you plan to mix assembly language, C and/or C++. For this program, select “Assembly”.

Figure 3. Select the programming language(s).

On the next screen (Figure 4), check “Absolute Assembly”, since you will put your entire program in a single file, with the program and data locations fixed at specified memory addresses. If a project is spread over multiple files that need to be linked together, you would select “Relocatable Assembly”.

Figure 4. Select “Absolute Assembly” for a single-file program.

Next you will be asked to select “connections” (Figure 5) to the target microcontroller, to be used to download and debug your programs. Check “TBDML”, which allows CodeWarrior to transfer your program to the flash memory of the microcontroller through a USB cable connected to the Witztronics WTBDMS12 background debug mode (BDM) module, which should be plugged into the 6-pin BDM header on the DragonFly12 module. If you wish, you may also check “Full Chip Simulation”, to do some program debugging using a full simulation model of the microcontroller, including simulated input/output devices. You can debug the program in the target hardware via the BDM, using the same user interface as for the simulator, and can change between simulator and actual hardware at any time.

Figure 5. Select “TBDML” and “Full Chip Simulation” to download and debug the program via the USB/BDM interface on the DragonFly12 module and the simulator.

At this point, CodeWarrior creates the project files, including a “dummy” main program to show the basic program structure. Delete the data/instructions from this dummy program and replace them with your own, or else delete file main.asm in the project directory and add your own file.

;* ELEC 3050 - Lab 1, Program 1 * ;* Exercise the HCS12 with assembly language * ;* Project board LED1 is connected to PORTA, bit 0 * ;* SW1 is connected to PORTE, bit 0 * ;**************************************************** ; export symbols XDEF Entry ; export 'Entry' symbol ABSENTRY Entry ; for absolute assembly: mark this as application entry point

; include derivative specific macros INCLUDE 'MC9S12C32.inc'

ROMStart EQU $4000 ; absolute address to place my code/constant data

; variable/data section ORG RAMStart ; Insert here your data definition. PAvalue DS.B 1 ;holds pattern currently in PORTA

; code section ORG ROMStart Entry: LDS #RAMEnd+1 ; initialize the stack pointer bset DDRA,%00000001 ; configure PA0 as output (LED1) bclr DDRE,%00000001 ; configure PE0 as input (SW1) clr PAvalue ; initialize variables to 0 E1: movb PAvalue,PORTA ; write pattern to PORTA (LED1) E2: brclr PORTE,%00000001,E2 ; wait for button press bsr Delay ; time delay for debounce com PAvalue ; toggle LED state bra E1 ; infinite loop

;* Delay subroutine - use nested loops to create a delay * Delay: ldaa #50 ; do outer loop 50 times Outer: lx #0 ; do inner loop 64K times Inner: dex ; X counts inner loops bne Iner ; repeat inner until X= deca ; A counts outer loops bne Outer ; repeat outer until A= rts ; return to main

;************************************* ;* Interrupt Vectors * ;************************************* ORG $FFFE DC.W Entry ; Reset Vector

Now, assemble the program by clicking the “Make” button in the project pane (Figure 7), or select Project > Make from the menu bar. Correct any syntax errors reported above the program pane, and reassemble the program until it is free of syntax errors. (The given test program has two syntax errors.)

Figure 7. Click “Make” to assemble the file, and select “Full Chip Simulation”

The following test and debug procedure may be performed on either the target hardware or the simulator. Before starting a debug session on the target hardware, the DragonFly module must be inserted into the breadboard, which should be placed on the provided breadboard station. Connect the breadboard station’s power supply header +5v to pin 2 (VCC) and the ground header to pin 1 (GND) of the DragonFly module. Then, double- check your power and ground connections, since improper connections will likely damage the module. Now connect pin 22 of the module (HCS12 I/O port pin PA0) to LED1 and pin 13 (HCS12 I/O port pin PE0) to switch SW1 on the breadboard station. Finally, while carefully noting the position of “pin 1”, connect the BDM module to the DragonFly module via the 6-pin header. Incorrect orientation of this header can damage the BDM module and/or the DragonFly module.

NOTE: NEVER INSERT OR REMOVE WIRES ON THE DRAGONFLY MODULE WHILE POWER IS ON. This can cause voltage transients capable of damaging the module and/or the breadboard station electronics.

Figure 9. Debug window, showing source and disassembled code, register values, memory, data values, and a command window, plus two simulated IO_Led components.

The program may be executed one instruction at a time, executed up to a breakpoint, or simply executed without halting via the buttons below the menu bar. From left to right, the button functions are as follows.

Start/Continue – execute until a stop condition (breakpoint) is reached Single Step – execute a single instruction (C or assembly) Step Into – execute an entire subroutine/function as a single instruction Step Out – executed until the current subroutine is exited Assembly Step – for C programs, execute one assembly language instruction Stop – stop executing Reset – reset the microcontroller

These commands, plus the ability to set breakpoints in the source window, are also available in a popup menu accessed with a right mouse click.

Program 2 – Example C program

The C program on the next page performs the same function as Program 1. Create a new project for this program, and verify that it produces the same behavior on the DragonFly12 module. The project creation procedure is identical to the above, with the following differences. On setup page 3 (Figure 3 above), select C instead of Assembly. On Setup page 4, check No (do not use the “Processor Expert). On setup page 5, check No (do not use PC-lint). On Setup page 6, select “minimal startup code”. On setup page 7, check “None” (we will not use floating-point arithmetic). On setup page 8, check “Small” (we will use the minimum amount of memory) On setup page 9, select the desired “connections” (TBDML and/or Full Chip Simulation) – See Figure 5 above.

As in the case of an assembly language project, a “dummy” C program is created as file main.c, listed under Sources in the left hand project pane. Again, you may either replace main.c with your own file, or edit the dummy program to enter your own C code.

The compilation and debug procedure is identical to that used for assembly language programs, as described above.

Laboratory Status Report and Lab Notebook

For Lab 1, each student is to submit a separate memo-style laboratory report, as described in the syllabus. The memo should (1) begin with a brief statement of the objectives of the lab, (2) provide a short discussion of what was done and the results that were observed, and (3) conclude with a brief statement of what was learned, and any suggestions for the lab instructors. In future labs, when programs are written and/or circuits designed, these should be attached to the memo, or otherwise included.

In addition, each student should enter all pre-lab and in-lab activity in the lab notebook. Lab notebooks will be collected from all students every two weeks, beginning with week