MPLAB Starter Kit For PIC18F User's Guide: © 2009 Microchip Technology Inc. DS51852A
MPLAB Starter Kit For PIC18F User's Guide: © 2009 Microchip Technology Inc. DS51852A
MPLAB Starter Kit For PIC18F User's Guide: © 2009 Microchip Technology Inc. DS51852A
• Microchip believes that its family of products is one of the most secure families of its kind on the market today, when used in the
intended manner and under normal conditions.
• There are dishonest and possibly illegal methods used to breach the code protection feature. All of these methods, to our
knowledge, require using the Microchip products in a manner outside the operating specifications contained in Microchip’s Data
Sheets. Most likely, the person doing so is engaged in theft of intellectual property.
• Microchip is willing to work with the customer who is concerned about the integrity of their code.
• Neither Microchip nor any other semiconductor manufacturer can guarantee the security of their code. Code protection does not
mean that we are guaranteeing the product as “unbreakable.”
Code protection is constantly evolving. We at Microchip are committed to continuously improving the code protection features of our
products. Attempts to break Microchip’s code protection feature may be a violation of the Digital Millennium Copyright Act. If such acts
allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that Act.
Table of Contents
Preface ........................................................................................................................... 1
Chapter 1. Introduction to the Starter Kit
1.1 Overview ........................................................................................................ 7
1.2 Operational Requirements ............................................................................. 7
1.3 Initial Board Setup .......................................................................................... 7
Chapter 2. The Demonstration Application
2.1 Bootloader From the MicroSD™ Memory Card ............................................. 9
2.2 USB HID Mouse Demo ................................................................................ 11
2.3 USB HID Joystick Demo .............................................................................. 12
2.4 USB HID Custom Device Demo ................................................................... 13
2.5 USB CDC Demo ........................................................................................... 14
2.6 USB MSD Card Reader Demo ..................................................................... 14
Chapter 3. Developing an Application
3.1 Setting Up an Example Application for Debug ............................................. 16
3.2 Running the Example Application ................................................................ 18
3.3 Debugging the Example Application ............................................................ 18
3.4 Programming the Debugged Application ...................................................... 21
3.5 Creating Other Applications ......................................................................... 21
3.6 Determining Device Support ........................................................................ 21
3.7 Reserved Resources .................................................................................... 21
3.8 Debug Version Information ........................................................................... 21
3.9 Troubleshooting ............................................................................................ 22
Chapter 4. Hardware
4.1 Application Functional Overview .................................................................. 23
4.2 Programmer/Debugger Functional Overview ............................................... 24
4.3 Board Components ...................................................................................... 25
Appendix A. Starter Kit Schematics........................................................................... 29
Appendix B. USB Current Draw Requirements ......................................................... 33
B.1 USB Current Specifications ......................................................................... 33
B.2 PIC18F Soft Start Circuitry ........................................................................... 34
B.3 Soft Start Functions and Usage ................................................................... 35
B.4 USB Suspend Current Limitations for the Starter Kit ................................... 37
Index ............................................................................................................................. 39
Worldwide Sales and Service .................................................................................... 42
NOTES:
Preface
NOTICE TO CUSTOMERS
All documentation becomes dated, and this manual is no exception. Microchip tools and
documentation are constantly evolving to meet customer needs, so some actual dialogs
and/or tool descriptions may differ from those in this document. Please refer to our web site
(www.microchip.com) to obtain the latest documentation available.
Documents are identified with a “DS” number. This number is located on the bottom of each
page, in front of the page number. The numbering convention for the DS number is
“DSXXXXXA”, where “XXXXX” is the document number and “A” is the revision level of the
document.
For the most up-to-date information on development tools, see the MPLAB® IDE online help.
Select the Help menu, and then Topics to open a list of available online help files.
INTRODUCTION
This chapter contains general information that will be useful to know before you use the
MPLAB Starter Kit for PIC18F. Items discussed in this chapter include:
• Document Layout
• Conventions Used in this Guide
• Warranty Registration
• Recommended Reading
• The Microchip Web Site
• Development Systems Customer Change Notification Service
• Customer Support
• Document Revision History
DOCUMENT LAYOUT
This document describes how to use the starter kit as a development and demonstrative
tool for PIC18F J-series device capabilities and features. The manual layout is as follows:
• Chapter 1. Introduction to the Starter Kit – This chapter introduces the starter
kit and provides an overview of its features.
• Chapter 2. The Demonstration Application – This chapter describes the
preprogrammed PIC18F demo application.
• Chapter 3. Developing an Application – This chapter describes how to debug
application software on the starter kit using MPLAB® IDE.
• Chapter 4. Hardware – This chapter provides a functional overview of the starter
kit and identifies the major hardware components.
• Appendix A. Starter Kit Schematics – This appendix provides detailed
schematic diagrams of the starter kit.
• Appendix B. USB Current Draw Requirements – This appendix briefly
discusses USB current consumption specifications and the methods used by the
starter kit to meet those specifications.
DOCUMENTATION CONVENTIONS
Description Represents Examples
Arial font:
Italic characters Referenced books MPLAB® IDE User’s Guide
Emphasized text ...is the only compiler...
Initial caps A window the Output window
A dialog the Settings dialog
A menu selection select Enable Programmer
Quotes A field name in a window or “Save project before build”
dialog
Underlined, italic text with A menu path File>Save
right angle bracket
Bold characters A dialog button Click OK
A tab Click the Power tab
Text in angle brackets < > A key on the keyboard Press <Enter>, <F1>
Courier New font:
Plain Courier New Sample source code #define START
Filenames autoexec.bat
File paths c:\mcc18\h
Keywords _asm, _endasm, static
Command-line options -Opa+, -Opa-
Bit values 0, 1
Constants 0xFF, ‘A’
Italic Courier New A variable argument file.o, where file can be
any valid filename
Square brackets [ ] Optional arguments mcc18 [options] file
[options]
Curly brackets and pipe Choice of mutually exclusive errorlevel {0|1}
character: { | } arguments; an OR selection
Ellipses... Replaces repeated text var_name [, var_name...]
Represents code supplied by void main (void)
user { ...
}
WARRANTY REGISTRATION
Please complete the enclosed Warranty Registration Card and mail it promptly.
Sending in the Warranty Registration Card entitles you to receive new product updates.
Interim software releases are available at the Microchip web site.
RECOMMENDED READING
This user’s guide describes how to use the MPLAB Starter Kit for PIC18F. Other useful
documents are listed below. The following Microchip documents are available and
recommended as supplemental reference resources.
Readme Files
For the latest information on using other tools, read the tool-specific Readme files in
the Readmes subdirectory of the MPLAB IDE installation directory. The Readme files
contain update information and known issues that may not be included in this user’s
guide.
PIC18FJ Device Data Sheets and Flash Programming Specifications
Refer to the appropriate device Data Sheet for device-specific information and
specifications. Also, refer to the appropriate device Flash Programming Specification
for information on instruction sets and firmware development. These files may be found
on the Microchip web site or from your local sales office.
MPASM™ Assembler, MPLINK™ Object Linker, MPLIB™ Object Librarian User’s
Guide (DS33014)
This document discusses the MPLAB ASM Assembler, MPLAB LINK Linker, MPLIB
Archiver/Librarian and other 8-bit device utilities, and helps you use these tools in
developing applications.
MPLAB® C18 C Compiler User’s Guide (DS51288)
This document helps you use Microchip’s MPLAB C18 C compiler to develop your
application.
MPLAB® IDE User’s Guide (DS51519)
This document describes how to use the MPLAB IDE (Integrated Development
Environment), as well as the MPLAB IDE Project Manager, MPLAB IDE Editor and
MPLAB SIM Simulator. Use these development tools to help you develop and debug
application code.
CUSTOMER SUPPORT
Users of Microchip products can receive assistance through several channels:
• Distributor or Representative
• Local Sales Office
• Field Application Engineer (FAE)
• Technical Support
Customers should contact their distributor, representative or Field Application Engineer
(FAE) for support. Local sales offices are also available to help customers. A listing of
sales offices and locations is included in the back of this document.
Technical support is available through the web site at: http://support.microchip.com
NOTES:
1.1 OVERVIEW
The MPLAB Starter Kit for PIC18F provides an all-in-one solution for debugging and
programming applications using Microchip’s own MPLAB Integrated Development
Environment (IDE). A USB connection to a host computer supplies communications
and power to the board; no additional external power supply is needed.
The starter kit includes integrated debug and programmer circuitry that allows
applications to be programmed onto the application side of the PIC18F MCU and then
debugged, all using MPLAB IDE. The need for an additional programmer or hardware
interface has been completely eliminated.
The application side of the starter kit contains a range of hardware components to
demonstrate the utility and processing power of Microchip’s PIC18F46J50 family USB
microcontrollers.
Note: Only initial testing has been performed on 32-bit Windows Vista for this
release of the demo applications. The 64-bit version is not supported at this
time.
Starter Kit
MicroSD card
MDD MicroSD™
File System Flash Card
HEX File
Parser
Flash
Program Memory
0000h
Bootloader
Firmware
A000h
Reset Vector
Application
Program Memory
FFFFh
Note: The demo PC application is intended to be run under Windows and was
written in Microsoft® Visual C++®. If the executable fails to launch correctly,
verify that the .NET Framework Version 2.0 (or later) redistributable pack-
age has been installed. To verify this, check the list of installed programs in
the Control Panel (from the Start button in Windows XP, Settings>Control
Panel>Add or Remove Programs).
If it is not installed, the .NET redistributable package is included on the CD
that comes with the starter kit. It is also available for download from the
Microsoft web site.
Starter Kit
M
If you debug a USB device application, a second USB cable must be connected to
another USB port on the PC or power hub, then to the starter kit at the mini-B
receptacle, J3, on the application side of the board (Figure 3-2).
Starter Kit
M
For more information on using the editor to create and edit code, see MPLAB IDE
Editor Help.
Note: This feature must be set up. From the menu bar, select Edit>Properties;
from the Properties dialog, select the Tooltips tab and then click the
checkbox for “Enable Variable Mouseover Values”.
3.9 TROUBLESHOOTING
3.9.1 Debug Connection Problems
While using the starter kit as a debugger, you may get the error, “Unable to Enter Debug
Mode”, when programming the device. This can result from communication being lost
between the starter kit and MPLAB IDE. To resolve this:
1. Unplug the USB cable from the starter kit.
2. Plug the USB cable back into the starter kit.
MPLAB IDE should automatically reconnect to the starter kit. If this does not work, do
the following:
1. Check the USB connection between the PC and starter kit at both ends.
2. If using a USB hub, make sure it is powered.
3. Make sure the USB port is not in use by another device.
Chapter 4. Hardware
This chapter provides a functional overview of the MPLAB Starter Kit for PIC18F, and
identifies the major hardware components. Topics covered include:
• Application Functional Overview
• Programmer/Debugger Functional Overview
• Board Components
PIC18F46J50
RB3 MicroSD™
Push Button RD6
RB0 RC2 Card Socket
Switch
BMA150
Touch Keys Accelerometer
RA0:RA3
and Scroll Bar RC6
D+/D-
USB mini-B
Receptacle
32 kHz SOSCI:SOSCO
Crystal VBUS
VDD to Debugger
The application side of the starter kit is centered on the PIC18F46J50 microcontroller,
which requires very little additional hardware to perform its tasks. The MPLAB Starter
Kit for PIC18F comes preprogrammed with a MicroSD bootloader that has the ability to
load, program and run precompiled applications from a MicroSD memory card to the
device’s Flash program memory. The MicroSD bootloader uses substantial parts of the
Microchip Memory Disk Drive file system. The precompiled demos use substantial
parts of the Microchip USB Stack Library.
The applications accept user inputs from three sources: the capacitive touch pad, S1
(A5), the acceleration sensor, U6 (A4), and the potentiometer, R24 (A7).
The microcontroller uses one of its A/D Converter channels to sample and convert the
potentiometer’s value to a digital value. Four additional A/D channels are used to
monitor the directional touch pads of S1. The values from these channels are analyzed
with the CTMU to determine when a touch-and-release event occurs on any of the
pads. The application firmware determines which action to take based on the
application’s current context. For example, the capacitive buttons are used as Left and
Right buttons for the USB HID Mouse Demo, while the capacitive slider is used to
emulate the scroll wheel. The capacitive slider is also used by the USB HID Joystick
Demo to generate the Z axes coordinates.
The microcontroller uses the SPI interface to configure the BMA150 acceleration
sensor, then to read 3-axis acceleration and temperature data in digital format. The
acceleration data is used to compute the board’s tilt; this is converted to cursor
movements for the USB HID Mouse Demo and X-Y coordinates for the USB HID
Joystick Demo.
The microcontroller uses the same SPI interface to communicate with the MicroSD
memory card. This allows the USB MSD Card Reader Demo to read and write files to
any MicroSD memory card.
The microcontroller directly drives the OLED display (LED1) using the microcontroller’s
Parallel Master Port (PMP). Data is driven on I/O ports, RD<7:0>. Port control signals,
A0, RD, WR and CS, are provided on ports RB5 and RE<2:0>, respectively. A DC
boost circuit, comprised of power MOSFET Q4 along with D5 and L3, provides the
operating voltage for the OLED.
The microcontroller uses its on-chip USB engine and transceiver to communicate with
the mini-B receptacles on the application side.
Debug 12 MHz
LED Crystal
SPI
Serial EEPROM
25LC010A
In its default configuration, the starter kit functions as a USB bus-powered device.
Power is provided via the USB cable; the nominal 5 volt unregulated supply is regulated
by a Microchip MC1727 3.3 volt, Low Dropout (LDO) linear regulator. Proper main
system power is indicated by the green LED (D2).
A7
A5
A3 M
A8
A4
A11
A2
A1
D4
D1 D3
A9
A10
D2 A6
D5 D6
NOTES:
Programmer/Debugger:
• Figure A-1: Programmer/Debugger System
Application:
• Figure A-2: Application Microcontroller, Touch Switches and Associated
Components
• Figure A-3: OLED Display, LED and Application Side USB Connectors
ICSP™/TEST/DEBUG HEADER
Not Populated
Not Populated
Not Populated
Not Populated
Not Populated
PICkit™ 2
Not Populated
Not Populated
MicroSD™ Card
C16 R21
0.1 μF 100k
RC0
R20
Q1 1.5k
IRLML6402PBF
APP_VDD
Transistor, Q1, a power MOSFET, blocks the current from the 3.3V power rail to the
non-microcontroller portions of the application circuit (e.g., SD card, OLED, etc). R21
ensures that on initial power-up, Q1 is blocking the current flow. R20 and C16 form an
RC filter on the digital output from the microcontroller (RC0 port). This RC filter creates
an analog voltage on the gate of Q1 from the PWM signal supplied by the micro-
controller. The values of C16 and R20 are chosen to produce a large RC time constant
compared to the PWM frequency, and such that, the current drawn from the pin is within
the port pin’s specification.
The PWM frequency is based on the RC network and is chosen to produce a fairly
constant voltage on the gate of Q1. The PWM duty cycle is determined by the gate
threshold of Q1. Once the frequency is selected, changing the PWM duty cycle will
result in a change of the gate voltage. The duty cycle is set so that the starting voltage
on the gate of Q1 is above the threshold voltage across all device variations, so that
the device is in an OFF state. The duty cycle is varied at a rate in which the gate voltage
on Q1 changes slowly enough to ensure that the transistor stays in its linear region dur-
ing the full charging of Q1’s output (Figure B-2). The result is that voltage is supplied to
the application at a slower rate, thus lowering the inrush current.
The duty cycle should stop sweeping at a point that is lower than any possible value for
Q1’s threshold voltage; this ensures that the entire linear region is used for as long as
possible. Once this point is reached, the software can disable the PWM and set the
output of RC0 low; this puts Q1 in Full Saturation mode.
Figure B-2 and Figure B-3 show how the change in gate voltage (yellow trace) relates
to the change in the circuit’s output (blue trace). Figure B-2 captures a close look at the
linear region, while Figure B-3 captures the entire PWM cycle from no output to full out-
put. Note that the gate voltage decreases slowly and constantly over the entire potential
threshold voltage range of Q1.
B.3.1 AppPowerEnable()
The AppPowerEnable() function starts the soft start sequence. The function initial-
izes the port pins, timers and PWM modules to get ready for the soft start. It is optional
if APP_POWER_AUTO_ENABLE is defined.
In light of the Total Application Current Draw specification of 100 mA, this function
should not be called until after the device is enumerated. See the following section for
more details.
B.3.2 AppPowerReady()
The AppPowerReady() function returns a BOOL data type that will return TRUE if the
soft start is complete or FALSE if it is not. This function should be called periodically
during the soft start to insure that the soft start continues ramping properly.
If APP_POWER_AUTO_ENABLE is defined, AppPowerReady() will automatically call
AppPowerEnable() if it is not already started. In light of the Total Application Current
Draw specification of 100 mA, this function should not be called until after the device is
enumerated. The application code that relies on components that are gated by the soft
start should wait until AppPowerReady() returns TRUE before running.
B.3.3 AppPowerDisable()
The AppPowerDisable() function turns the power off to the application. This func-
tion should be used when the device is going to go into Suspend mode in order to meet
the USB suspend current specification.
Index
A Debugger Toolbar
Acceleration Sensor ......................................11, 12, 24 Animate............................................................. 18
Application Components Halt.................................................................... 18
Soft Start Circuit................................................ 27 Reset................................................................. 18
Application Components Run ................................................................... 18
Acceleration Sensor.......................................... 27 Step Into............................................................ 18
Bootloader Reset Push Button ......................... 27 Step Over.......................................................... 18
Capacitive Touch Pad....................................... 27 Demonstration Applications
MicroSD Card Socket ....................................... 26 Bootloader from MicroSD Card........................... 9
mini-B USB Receptacle .................................... 27 HID Custom Device .......................................... 13
OLED Display ................................................... 26 HID Joystick ...................................................... 12
OLED Voltage Boost Circuitry .......................... 27 HID Mouse ........................................................ 11
PIC18F46J50 Microcontroller ........................... 26 USB CDC COM Port......................................... 14
Potentiometer ................................................... 27 USB MSD Card Reader .................................... 14
Voltage Regulator ............................................. 27 Documentation
Conventions ........................................................ 2
B Layout ................................................................. 1
Block Diagrams
H
Application Side ................................................ 23
Programmer/Debugger Side ............................. 24 Host Computer Requirements.................................... 7
Soft Start Circuit................................................ 34 I
Board Components
Initial Board Setup...................................................... 7
Debug LED ....................................................... 26
Connecting Hardware ......................................... 8
Debugger/Programmer Clock Crystal ............... 26
Installing Software............................................... 8
mini-B USB Connector...................................... 26
Internet Address......................................................... 4
PIC18F67J50 Microcontroller ........................... 26
Serial EEPROM ................................................ 26 M
Target Power LED ............................................ 26 Microchip Internet Web Site ....................................... 4
Bootloader MPLAB IDE .......................................................... 7, 15
Display Messages............................................. 10 mTouch Calibration (manual)................................... 14
Memory Map ..................................................... 11
Writing Applications .......................................... 11 P
Programmer ............................................................. 21
C
Charge Time Measurement Unit (CTMU) ................ 24 R
Code Examples Reading, Recommended ........................................... 3
Using AppPowerDisable()................................. 36 Reserved Resources................................................ 21
Using AppPowerReady() to Revision History ......................................................... 5
Control Application Start-up ............... 36
S
Customer Change Notification Service ...................... 4
Customer Support ...................................................... 5 Schematic Diagrams ................................................ 29
Soft Start
D Circuitry............................................................. 34
Debug ........................................................................ 7 Functions, Usage .............................................. 35
Executive .......................................................... 17 Starter Kit
Reserved Resources ........................................ 21 Board Components ........................................... 25
Setup ................................................................ 16
01/02/08