Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (9.59 MB, 687 trang )
Appendix E: Suggested Laboratory Exercises
595
PRELAB
1. Implement the audio playback/record schematic of Figure 14.2 on your
PIC18F242 system.
2. Read Sections 14.2 and 14.3 and ensure that you understand the audio.c
code (Figure 14.3 through 14.6), as you will be modifying this code during
lab.
Lab Activity
1. Verify that you can record and playback audio at a 6 kHz sample rate using
the audio.c file.
2. Flatten the code of the playback loop within audio.c until you can achieve
an 8 kHz playback rate. This also requires running the I2C bus faster than
the maximum datasheet specification of 400 kHz.
3. If you are feeling ambitious, implement the suggested modification contained in problem #1 at the end of Chapter 14!
E.15 HARDWARE DEBUGGING CHECKLIST
Debugging hardware problems requires a methodical approach and the use of
available instrumentation such as a multimeter and oscilloscope. The following are
debugging checklists that are useful for identifying hardware problems.
“My board used to work and now it doesn’t.”
1.
2.
3.
4.
5.
6.
Used multimeter to measure Vdd on PIC.
Both VSS pins on PIC are connected to ground?
Used scope to see if oscillator working.
Used scope to ensure reset line works.
Checked PIC with older test program (ledflash.c).
Checked PIC in TA reference board to see if board problem.
yes K
yes K
yes K
yes K
yes K
yes K
no J
no J
no J
no J
no J
no J
596
Microprocessors
“My fuse keeps blowing, help!”
To track shorts, perform the following steps in order:
1. Connect the multimeter in series with power to monitor current.
2. Disconnect one half of the protoboard from the other half and determine
which half the problem is in. Only connect power for a brief period of time
to see if short still exists.
3. Remove all ICs from problem half of board and see if short is fixed.
4. If short still exists, remove any capacitors.
5. If short still exists, remove any switches.
6. If short still exists, remove any LEDs.
7. If short still exists, it must be a direct wiring connection between Vdd/Gnd.
“My RS232 interface does not work”
MAX202 is producing ±10 V.
MAX202 Vdd/Gnd connected.
Used scope to see if PC/HyperTerminal is transmitting.
Does HyperTerminal have the right COM port selected?
Is Flow control set to “NONE” in HyperTerminal?
Is the cable connected to the correct COM port on the PC?
Used scope to check MAX202-to-PIC (RX) link (type a
character in HyperTerminal and verify character
arrives RX pin of MAX202 and RX pin of PIC).
8. Used scope to check PIC(TX)-to-MAX202 link (program
PIC with echo program and check if the PIC TX pin is
echoing character).
9. Used scope to check MAX202-to-PC link.
10. If receiving garbage, does measured bit time match baud
rate?
1.
2.
3.
4.
5.
6.
7.
yes K
yes K
yes K
yes K
yes K
yes K
no J
no J
no J
no J
no J
no J
yes K no J
yes K no J
yes K no J
yes K no J
One quick tip: If power is off to your board, and your power-on LED is still
dimly lit and you have an RS232 cable connected, this may indicate that you have
reversed the TX/RX pins on your DB9 to MAX202 chip connection.
Appendix E: Suggested Laboratory Exercises
597
“Jolt does not work”
1. On Jolt startup, you get a “main class not found” error. Verify that your
CLASSPATH environment variable is set correctly and that the comm.jar
file (see Appendix F, Section F.2, “Jolt Installation”) is copied to the location indicated by the CLASSPATH variable. Review all of the Jolt installation steps and verify that you have performed each correctly.
2. The Jolt Program option is not working (the progress bar does not advance). This usually indicates a problem with the serial port connection.
When trying to program, Jolt periodically sends a handshake character via
the serial port to the PIC. To debug, monitor the RX line on the PIC with
a scope and verify that that the handshake character is arriving. If no character is arriving, debug your RS232 interface following the preceding steps.
If a character is arriving, look at the TX output of the PIC—the Jolt
firmware on the PIC should be trying to respond. If the TX output has no
activity, reprogram your PIC with the bootloader firmware.
“My I2C interface does not work”
Verified both SCL and SDA have Vdd via pullups when idle. yes K
Do you have SCL/SDA swapped? (SCL is the CLOCK!)
yes K
Verified transmission by PIC on SCL/SDA.
yes K
Verified I2C device address in your program.
yes K
Verified I2C device address on A1/A0 pins of EEPROM/
DAC.
yes K
6. Is the I2C Device (EEPROM/DAC) sending an ACK?
yes K
1.
2.
3.
4.
5.
no J
no J
no J
no J
no J
no J
“My A/D does not work”
1. Used multimeter to check PIC A/D input voltage
variation.
yes K
2. Is the analog input connected to the correct A/D input?
yes K
3. Is PORTA configured for analog input?
yes K
4. Used printf() statement to print individual A/D result bytes. yes K
no J
no J
no J
no J
598
Microprocessors
E.16 INSTRUMENTATION AND PROTOTYPING HINTS
This section contains a few instrumentation and prototyping hints to aid you in
performing the suggested experiments.
Voltage, Resistance, Current Measurement
A digital multimeter (DMM) is a common instrument for measuring voltage, resistance, and current. Figure E.14a shows how to use a DMM to measure voltage
across a resistor. A resistance measurement is made in the same manner, except the
DMM front panel buttons should be set to resistance instead of DC voltage.
FIGURE E.14 Voltage, current measurement.
Observe that to measure voltage, no physical changes to the circuit wiring has
to be done. This is not true with current measurement, as shown in Figure E.14b.
The DMM must be placed in series with a device whose current is being measured
in order for the current to flow through the DMM and then into the device. This requires physically breaking the circuit connection, and routing the wiring to the mA
and COM terminals of the DMM.
Passive Components: LEDs, Capacitors, Resistors, Switches
Figure E.15 shows some of the passive components in the parts kit of Figure E.2. A
light emitting diode (LED) conducts current when the anode has a voltage approximately 0.7 V higher than the cathode; LED brightness increases as current increases. The short lead is the cathode, the long lead is the anode.
The 15 pF capacitors used with the crystal in Figure 8.4 to form the PIC18F242
clock source are not polarized, which means that it does not matter which direction
the capacitors are connected in the circuit. The 0.1 μF capacitors used between
Appendix E: Suggested Laboratory Exercises
599
Vdd and VSS on the PIC18 and with the MAX202 are polarized and have a clearly
marked positive (+) terminal; the negative ( ) terminal should be connected to
ground. The resistors of the parts kit in Figure E.2 are in a single inline package
(SIP) as shown in Figure E.15c, each resistor is connected between two pins on the
package. A potentiometer will have at least three terminals as shown in Figure E.15d
(the potentiometer of the parts kit in Figure E.2 has four terminals as the wiper terminal is replicated on two pins). To determine the terminals marked as A and B in
Figure E.15d, use a DMM to measure the resistance between pairs of terminals
until you find the terminal pair whose resistance does not change when the potentiometer is adjusted. Pushbutton switches as shown in Figure E.15e have no pin
markings; you must use the DMM to measure the resistance between terminal pairs
to determine which terminal pair is shorted (zero resistance) when the pushbutton
is pressed.
FIGURE E.15
Passive components.
Wire Wrapping
Wire wrap is useful to create secure connections to components that do not plug
directly into the protoboard. In Figure E.1, wire wrap is used to connect to the DB9,
potentiometer, and modular connector. Figure E.16 shows the steps for creating a
wire wrap (WW) connection using a WW tool and WW wire from Radio Shack.
WW wire is 30 gauge wire, and the ends of a wire wrap connection must be stripped
before wrapping. The Radio Shack WW tool has a wire stripper contained in the
600
Microprocessors
handle. The end of the WW tool has a large center hole for fitting the tool over a
post, and a small hole on the side that is used to hold the wire. To create a WW connection, cut a piece of wire of appropriate length and strip approximately 1/2 to 3/4
inch from either end. Place a stripped end into the small hole of the WW tool and
push the wire into the tool until the insulation prevents the wire from going any
further. Then, place the WW tool over a post, and twist clockwise, holding the wire
to keep it taut while wrapping. This should wrap the stripped portion of the wire
around the post. Repeat this with the other stripped end of the wire at the destination post. To unwrap, place the WW tool over the post, push down firmly, and turn
counter-clockwise.
FIGURE E.16 Wire wrapping.
Appendix
F
ON THE CD
The Jolt/Colt Serial
Bootloaders
his appendix discusses use of the Jolt and Colt serial bootloaders for downloading PIC18F242 programs using the serial port interface. Martin Dubuc
wrote both programs, and the Jolt/Colt home pages are found at
http://mdubuc.freeshell.org/{Jolt/Colt}. The bootloader programs are self-extracting
executables named bootldr/ColtSetup.exe and bootldr/JoltSetup.exe on this book’s
companion CD-ROM. Jolt has more features than Colt in terms of viewing the
code to be programmed and altering configuration bit settings, but requires installation of the Java Runtime Environment. Both Jolt and Colt are compatible with
Windows XP. At Mississippi State University, Colt is generally preferred by students because of its simpler installation.
T
F.1 PROGRAMMING THE JOLT/COLT FIRMWARE
Each bootloader consists of two parts: firmware that resides on the PIC18 and a
client that runs on the PC. The PC client reads a hex file and sends the program
memory contents over the PC serial port to the PIC18 bootloader firmware that
programs the PIC18 program memory with the incoming bytes. EEPROM data
memory and configuration bits can be programmed by the bootloader as well. The
PIC18 bootloader firmware is the same for both Colt and Jolt. The bootloader
firmware is in a file named bootload.hex that is found within the respective default
installation directories (C:/Program Files/Colt PIC18F Bootloader, C:/Program
Files/Jolt PIC18F Bootloader). A version of the bootloader hex file with the configuration bits set to options used for the book PIC18F242 reference system is found
in code/labs/bootload_hspll.hex.
Programming the bootloader firmware requires use of an external PIC programmer. Figure F.1 shows a picture of two external programmers available from
Microchip: the PICSTART Plus and the ICD2.
601
602
Microprocessors
FIGURE F.1 PICSTART Plus and ICD2 programmers.
The PICSTART Plus has a 40-pin ZIF (zero insertion force) socket for holding
PIC devices and communicates with the PC via the serial port. It can program a
wide variety of PIC microcontrollers and is the programmer the author uses in the
laboratory environment at Mississippi State University. The disadvantage of the
PICSTART Plus is that the PIC18 has to be removed from the protoboard for programming; the Jolt/Colt bootloaders allow in-circuit programming via the serial
port.
An alternative to the Jolt/Colt bootloaders for in-circuit programming is the
ICD2 programmer, which supports both in-circuit programming and limited incircuit debugging of PIC microcontrollers. The ICD2 communicates with the PC
either through a serial port or a USB port. Figure F.2 shows the necessary modification to the PIC18 startup schematic of Figure 8.4 to support the ICD2. During incircuit serial programming (ICSP), voltage pulses of approximately 12 V are
applied to the Vpp/MCLR pin. The LED isolates the rest of the Vdd bus from the
high-voltage pulses applied on Vpp during programming. The RB6/PGC pin is the
clock used for serial programming data sent over the RB7/PGD pin.
Appendix F: The Jolt/Colt Serial Bootloaders
603
FIGURE F.2 ICD2 programmer connection.
If the ICD2 programmer interface is used, a serial bootloader such as Jolt is unnecessary. One disadvantage to using the ICD2 is that if pins RB7, RB6 are driven
by other active circuitry on your board, these must be isolated during programming, perhaps by DIP switches.
MPLAB is used as a front-end for both the PICSTART Plus and ICD2 programmers. Figure F.3 shows the steps for programming a PIC18 using the PICSTART Plus programmer.
The “File
Import” option (Figure F.3 b) is used for loading a pre-existing
hex file into MPLAB for programming or simulation. The “Configure Configuration Bits” option (Figure F.3c) is used for examining and/or modifying configuration bit settings. When programming the Jolt/Colt firmware into your PIC18, it
may be necessary to use this option to change the configuration bit setting for the
oscillator to match your system. After changing the configuration bits, the “File
Export” option is useful for saving a new copy of the hex file with the modified configuration bits. Steps (d), (e), (f), and (g) in Figure F.3 show how to use the PICSTART Plus to program a PIC18. The final programming step also includes
verification of the downloaded code by reading the PIC18 program memory and
comparing it with the target code.
604
Microprocessors
FIGURE F.3 Using the PICSTART Plus. Screenshots ©2005 Microchip Technology, Inc. Reprinted with
permission. All rights reserved.
Appendix F: The Jolt/Colt Serial Bootloaders
605
F.2 JOLT INSTALLATION
The most up-to-date installation instructions and Jolt version can be found at
http://mdubuc.freeshell.org/Jolt. The following off-line installation instructions are
compatible with Jolt V1.0. Execute the self-installing executable
bootldr/JoltSetup.exe to install Jolt; the default installation location is C:\Program
Files\Jolt PIC18F Bootloader. Before running Jolt, the following steps must be completed for correct operation.
Java Runtime Environment Installation
ON THE CD
Jolt is written in Java, and thus either the Java 2 Platform, Standard Edition (J2SE)
Java Runtime Environment (JRE) or J2SE Software Development Kit (J2SE SDK)
must be installed. A starting point for these downloads is found at
http://java.sun.com/j2se. A version-specific URL for downloading version 5.0 of the
J2SE is http://java.sun.com/j2se/1.5.0/index.jsp. The Jolt version on the companion
CD-ROM has been tested with version 5.0 of the JRE. If you are installing Java only
for use with Jolt, it is recommended that you install the runtime environment (J2SE
JRE), as it is much smaller than the software development kit. The remaining instructions assume that the J2SE JRE has been installed.
Java Communications API
1. The Java Communications API must be installed after the J2SE JRE installation for Jolt to communicate over the serial port. The Java Communications API is found at http://java.sun.com/products/javacomm/ and is
distributed in the form of a ZIP archive. Download this ZIP archive and
unpack it into some temporary directory on your PC. Three files must be
copied from the JavaComm API folder into the JRE folder as shown in Figure F.4.
2. Copy the win32com.dll file from the JavaComm API folder to the JRE bin
folder. If this file is not visible, use “Tools
Folder Options” to change
folder options to display file extensions for known file types and to show
hidden files and folders as shown in Figure F.4 (b, c).
3. Copy the javax.comm.properties file from the JavaComm API folder to the
JRE lib folder.
4. Copy the comm.jar file from the JavaComm API folder to the JRE lib/ext
folder.
5. Two changes must also be made to system variables as shown in Figure F.5.
The CLASSPATH variable must be created and the path to the comm.jar