Lab 1 – Driving LEDs

advertisement
EENG 383
Microcomputer Architecture and Interfacing
Fall 2015
Lab 1 – Driving LEDs
September 3, 2015
In this lab you will use the HCS12 microcontroller on the SSMI board to turn on and off some light
emitting diodes (LEDs). Although seemingly a simple task, to accomplish it you have to do a number of
sophisticated things (all of which will help you later!).
A report from each team is due to the grader prior to the beginning of the next lab project. The report
should describe what you did, and answer the questions asked for in this handout. More detailed
information about the lab report is on the course website.
1
Prelab Questions (answer prior to coming to lab)
Refer to the data sheets for the SSMI board and the NanoCore12DX module. These are on the course
website under “Reference Documents”, in “SSMIboardSchem.pdf” and “NanocoreSchem.pdf”
respectively. The NanoCore module is a little “daughter” circuit board that plugs into the SSMI board
(socket U1 on the data sheet). It contains the actual microcontroller unit chip, described below. The
NanoCore module has 32 pins in a DIP (dual in-line package) form factor. The signals on these pins are
brought out to headers H1 and H2 on the SSMI board, so that you have easy access to them. H2 is just a
duplicate of H1.
1. What is the pin number on H1 that corresponds to ground?
The HCS12 chip has a number of digital I/O (input/output) ports. These ports are brought out to pins on
the NanoCore module, which then go to header H1 on the SSMI board. We will use pins 0 and 1of Port
M (i.e., PTM) to drive the LEDs.
2. What pins on H1 correspond to Port M, pin 0 and pin 1?
According to the electrical specifications of the HCS12 chip (see Appendix A in MC9S12C Family
Reference Manual, document “MC9S12C128V1.pdf” on the course website), the digital I/O pins of the
microcontroller have 5V output, and an absolute maximum current output (or input) of at most 25 mA.
To make sure that we don’t try to output more than 25 mA, we need to limit the current with a resistor in
series with the LED (see section 4.11.1 in the Huang textbook).
3. What is the typical voltage drop across a red LED (approximately)?
4. If we connect the LED to a 5V output, and use a 1.5 kOhm current limiting resistor, what is the
current through the LED?
2 Powering and connecting to the SSMI board
1
EENG 383
Microcomputer Architecture and Interfacing
Fall 2015
We will power the SSMI board with a 9V DC power supply adapter, which is in the lab kit. The +9V
and ground of the adapter need to be connected to jack J5 of the SSMI board.
• Plug the power adapter into the AC outlet and determine with a digital multimeter (DMM) which
leads of the adapter correspond to +9V and ground. Although the nominal voltage is +9V, what
is the actual voltage as read by the DMM?
• Unplug the adapter from the wall outlet. Connect +9V and ground to the correct inputs on jack
J5. Show the instructor your connections before proceeding further.
• Once the instructor verifies that your connections are ok, plug the adapter into the wall outlet.
Verify that the green LED on the SSMI board comes on, indicating that the board has power.
Make sure the little switch on the NanoCore module is set to “Load”, not “Run”.
3 Creating a simple program
Create a new CodeWarrior project.
• Open CodeWarrior and select File->New Project…
• Expand HCS12 and HCS12C and then select MC9S12C32. This is the microcontroller that the
Nanocore uses. Note: Make sure to selected HCS12 Serial Monitor for the default connection.
Press Next to continue.
• Deselect C and select Absolute assembly. Change the project name and location if needed. Press
Finish to complete creating the new project.
Edit the default template program and change it to the simple Fibonacci program as done in the lecture:
• Replace the declarations for “Counter” and “FiboRes” with the declarations for “N1”, “N2”, and
“N3”:
N1
N2
N3
•
DS.B 1
DS.B 1
DS.B 1
Replace the lines between “mainloop” and “RTS” (inclusive) with the instructions for the simple
Fibonacci program:
movb
movb
#0,N1
#1,N2
loop
ldaa
adda
staa
movb
movb
bra
•
N1
N2
N3
N2,N1
N3,N2
loop
Compile the program.
2
EENG 383
•
•
Microcomputer Architecture and Interfacing
Fall 2015
Connect the serial cable from the PC to the SSMI board, and start the debugger. This should
download the program to the SSMI board. Step through the program. Verify that the Fibonacci
numbers are produced in N3.
Where does RAM start? It is not $0800, as was the case with the simulator in lecture. The
instructions at the beginning re-map the location of RAM. One way to find out where RAM
starts is to look at the address of N1, since it is the first storage location in RAM.
4 Driving the LEDs
You can write to Port M just like a memory address. The address of Port M is given by the label
“PTM”, which is defined in the file “mc9s12c32.inc”, that is automatically included in your
CodeWarrior project. To output a logic high (+5V) on Port M, pin 0, you write a “1” to bit 0 of location
PTM. To output a logic low (0V) you would write a zero to that location.
Change your program to output logic high on PM0, then a logic low, and enclose those in an infinite
loop. There is one additional thing you have to do at the beginning of your program, and that is to
designate PM0 as an output pin instead of an input pin (the default is input). To do this, we write a “1”
to the corresponding bit in the “data direction register” for port M. Just insert the following lines at the
beginning of your program (before the loop) to configure PM0 for output:
ldaa
staa
#$01
DDRM
; Write a 1 to bit 0 of DDRM to configure
; .. PM0 for output
Note: Make sure the power is off when you implement the following hardware changes.
Connect an LED from PM0, through a current limiting resistor, to ground. You can use a discrete
resistor, or the resistor DIP part provided in the kit (see the lab webpage for the datasheet).
At this point (and for the rest of the semester) it may be convenient to use the protoboard on the SSMI
board (the large white breadboard) for connections. The protoboard doesn’t have any connections to the
rest of the SSMI board, so you have to make the connections yourself. You will find it convenient to
connect a black wire from the row on the protoboard labeled “-” to the ground pin on H1. Just leave that
wire in place for the remainder of the semester, so that the protoboard always has a ground connection.
Sketch a schematic of the LED design. Include the predicted current through the LED
• Sign-Off 1: Have the instructor check your schematic and implementation before turning on the
power. Instructor sign-off needed.
Compile, download, and step through the program. Verify that the LED turns on and off.
• In your lab report, include a schematic diagram of your circuit, a listing of the program, and an
explanation of the circuit and the program.
3
EENG 383
•
•
Microcomputer Architecture and Interfacing
Fall 2015
Sign-Off 2: While the LED is on, measure the current through the LED with the multimeter.
Instructor sign-off needed.
Try running the program run at full speed (instead of stepping through it one instruction at a
time). Explain what you see on the LED.
Now connect a second LED from pin PM1, through another current limiting resistor, to ground. Note –
for this step and in the future, always disconnect the power when making hardware changes, and double
check all connections before turning power back on. Change the program to implement a 2-bit binary
counter, where the least significant bit of the counter is shown on the LED attached to PM0, and the
most significant bit is shown on the LED attached to PM1. You can use the inca or adda instruction to
increment the accumulator.
• Sign-Off 3: Demonstrate the 2-bit binary counter to the instructor by stepping through the
program.
5 Clock Frequency
You can slow down the rate at which the LEDs blink by inserting some delay in the program. Insert a
bunch of “nop” instructions in your loop. Run the 2-bit binary counter program at full speed.
• Sign-Off 4: Look at PM0 and PM1 on the oscilloscope simultaneously and measure the period
of each waveform. In your report, include a screen capture of the scope trace, with the cursors
showing the period or frequency.
• Determine the number of clock cycles in your loop, by looking up each instruction in the
instruction set table, and adding them all up. It would be helpful to indicate the clock cycle
count for each instruction in the comments of the program.
• From your measured loop period, and the number of clock cycles in the loop, estimate the period
of one CPU clock cycle, and the clock frequency. Include your calculations and the program
listing in your report.
4
EENG 383
Microcomputer Architecture and Interfacing
Fall 2015
Lab 1: Driving LEDs
Name: ________________________________Name: ________________________________
Task
Description
Initials
Sign-Off 1 LED schematic and implementation
Sign-Off 2 LED current measurement
Sign-Off 3 2-bit Counter
Sign-Off 4 Oscilloscope: Waveform period measurement
6 Rubric
Deliverables
20 pts Pre-Lab
Driving the LED
/7
Clock Frequency
/ 8 Demonstrations
Scope trace(s)
/5
Composition
Questions
5 pts
Total
5 pts
/5
20 pts
Sign-Off 1: Implementation
/2
Sign-Off 2: LED Current Measurement
/5
Sign-Off 3: 2-bit Adder
/8
Sign-Off 4: Waveform Period Measurement
/5
/ 50 pts
5
Download