SlideShare una empresa de Scribd logo
1 de 7
Descargar para leer sin conexión
UAV DevBoard:
Getting Started with PIC
Programming
5/11/2009


    If you bought a UAV DevBoard, you will need to program it in order to do anything useful or
interesting with it. It is not hard to do, after a few times it will be easy. But the first time can be
confusing. This document will help you get started.
    In addition to the UAV DevBoard itself, you will need the following items to program it:
        •   An ICD2. This is a programmer/debugger hardware item for connecting the
            DevBoard up to your computer. I suggest that you buy the one recommended by
            SparkFun, http://www.sparkfun.com/commerce/product_info.php?products_id=5. I
            do not recommend the “PIC-ICD2-Pocket”. I have one of these, and I have been able
            to get it to work with the dsPIC30F4011 CPU on the DevBoard, but there have been
            several reports of problems with it.
        •   An IDE (interactive development environment). This software suite is available as a
            free download from MicroChip. It provides an excellent support environment for
            firmware development for the DevBoard.
        •   A C compiler for the dsPIC30 family of CPUs. This is also available as a free
            download from MicroChip.

Download and install the IDE and C compiler
    You should install the IDE before you connect the ICD2 to your computer, otherwise plug-
and-play will get confused and will try to install the ICD2 without having the drivers that it needs.
    Go to the MicroChip website, www.microchip.com. Both the IDE and the compiler are
available under the Design->Development Tools menu, in the Software section. Close all other
applications first. Download and install the MPLAB IDE first. It will take a while. If it complains
about applications that you have open, close them down and proceed. It may ask you about
installing the HI-Tech C compiler, you should decline, you do not need the HI-Tech
compiler.You should also download the MPLAB IDE user’s guide, it has a very useful section on
getting started.
    After you install MPLAB IDE, download and install MicroChip’s C compiler. It is available
under the same area as the IDE, under MPLAB C compilers. Click on MPLAB C compilers, and
scroll to the bottom of the downloads list. Download and install “MPLAB C Compiler for dsPIC,
Evaluation Version”. This is a free download. To get it, you will need to register with MicroChip.
The only difference between the free evaluation version of the compiler and the purchased
version is that after 60 days, the optimization options turn off. However, you do not need the
optimization options, so it does not matter. You should also download the reference manual for
the compiler. You can find it under the Design->Technical Documentation->User Guides,
“MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs Users Guide.” Depending on how
deeply you intend to get into the programming of the dsPIC, there are also reference manuals on
the dsPIC30F4011 hardware and programming model that you can download.
    After you install both the IDE and the compiler, you should check that the IDE is working.
Click on the red and blue MPLAB IDE icon. The IDE should open. In the unlikely event that the
IDE does not open, check the IDE user’s manual for suggestions on what to do.




PIC Programming                                                                                       2
5/11/2009


Installing the ICD2
    After you install the IDE and the compiler, you need to install the ICD2. I am not real clear
on this, I did it only once, and that was several years ago. There are instructions for installing the
ICD2 in the help window of the IDE. My recollection is that you start up the IDE, and connect
the ICD2 to your computer with a USB cable. Installation is then automatic.
   There are two ways that you can connect your ICD2 to your computer, either with the RS232
connector, or the USB, but not both. I recommend that you use the USB.
    So, bring up MPLAB IDE and plug in your ICD2 and wait for it to install.

Programming the UAV DevBoard
     You are now ready to program your board. It is shipped with self-test firmware already
installed. To do something more interesting, you will probably want to program it with something
else. There are several programs available on the main page of UAV DevBoard, including demos,
MatrixNav, and AileronAssist. Decide which one you want to start with, download it, and unzip
it. Then, do the following. Some of the steps can be done in a different order, as you gain
experience, it will become clear to you which ones can be shuffled around. Much of it is
“common sense”:
    1. Start up MPLAB IDE.
            If you have not already done so, start up the MPLAB IDE.
    2. Connect your ICD2 to your computer through a USB connection. This will power up the
       ICD2.
    3. Power up your UAV DevBoard.
            Apply approximately 5 volts on the power and ground pins of any servo or Rx
        channel of the board. If you are connecting an Rx to the board, you can backfeed power
        and ground through the Rx. Otherwise, the simplest thing to is to apply power and ground
        to one of the unused Rx channels. The pins nearest the edge of the board are ground, the
        center ones are power. Do not try to power the board from the spare Vcc pin. Your board
        may or may not do anything when it is powered up, depending on whether it is also
        connected to the ICD2 at the time. The ICD2 may hold the CPU in reset, if it is
        connected.
    4. Connect your ICD2 to your DevBoard.
              Use the 6 wire ICSP cable that came with the ICD2. The connectors are keyed so that
        it is not possible to connect them backwards. The ICD2 has two places where you could
        make a connection, only one of them is the right one. Make a connection to the ICSP
        connector that is between the USB connector and the RS232 connector.
    5. Open the project in MPLAB IDE.
           Under the project menu, select “open”. MPLAB will bring up a window for you to
        browse for the project that you want to open. Projects have a .mcp extension, and will
        have the MPLAB icon. Select the project that you want.
    6. Make sure that the IDE is working in the RELEASE mode.



PIC Programming                                                                                          3
5/11/2009


          The IDE is capable of both simple programming as well as debugging. You will start
      with programming. After you open the project, select RELEASE in the IDE toolbar.
      There are only two options, RELEASE and DEBUG. Chances are the project will come
      up in the DEBUG mode, change it to RELEASE.
   7. Select your ICD2 as the programmer and check its settings.
          Select MPLAB ICD2 from the programmer menu. Check a couple of settings under
      programmer settings or debugger settings. Under the STATUS tab, select automatic
      downloading of firmware, but do not select connect at startup. Under the POWER tab,
      make sure that the programmer/debugger is not going to try to power the DevBoard from
      the ICD2.
   8. Do a project “make”.
          This is an important step. Do not skip it. Otherwise you will simply erase the PIC
      without reprogramming it. Select “make” from the project menu. The IDE will compile
      and build the firmware. There will be several warnings issued, but there should not be
      any errors. At the end, there will be a message that the build was successful. This step
      usually goes smoothly, but there are a couple of things that could go wrong.
          If something went wrong during the installation of the C compiler, the IDE might not
      be able to find it. In that case, go to “Select Language Toolsuite” under the project menu.
      You want the Microchip C30 Toolsuite. If it is not selected, use the Toolsuite browser to
      find and select it. It should be located where ever you saved the IDE, probably under
      ProgramFilesMicrochipMPLABC30.
   9. Execute a “Connect” operation.
           Select connect from the programmer menu. You should receive the following
      messages if everything goes right. If something goes wrong, skip to the last section for a
      list of common mistakes, misunderstandings, and problems.
           Connecting to MPLAB ICD 2
      ...Connected
      Setting Vdd source to target
      Target Device dsPIC30F4011 found, revision = Rev 0x1003
      ...Reading ICD Product ID
      Running ICD Self Test
      ...Passed
      MPLAB ICD 2 ready for next operation
          Also, the first time that you connect, the IDE will install a new operating system into
      the ICD2. It will ask you if you want to do that, you should accept. It will take a few
      minutes. After the first time, the IDE will skip this step, unless you are using the ICD2 to
      program another type of PIC.
   10. Execute a “Program” operation.
           The IDE will program the board through the ICD2. You should see something similar
      to the following messages:
           Programming Target...
      ...Validating configuration fields
      ...Erasing Part



PIC Programming                                                                                    4
5/11/2009


        ...Programming Programming Executive
        ...Verifying Programming Executive
        ...Programming Program Memory (0x0 - 0x187F)
        Verifying...
        ...Program Memory
        ...Verify Succeeded
        ...Programming Configuration Bits
        .. Config Memory
        Verifying configuration memory...
        ...Programming succeeded
        10-May-2009, 18:04:07

        MPLAB ICD 2 ready for next operation
            If you get error messages instead, skip to the last section.
    11. Run the firmware.
            There are two ways of doing this. You can run the firmware with or without
        disconnecting the ICD2. If you want to leave the ICD2 connected, select “Release from
        Reset” from the programmer menu. If not, you can simply disconnect the ICD2
        connection to the board, it will start running.
            You can also reset the CPU from the programmer by selecting “Hold in Reset”, and
        then “Release from Reset” from the programmer menu. This is a particularly convenient
        way to restart the firmware without disturbing the gyros.
When you are done programming, I recommend that you do the following:
    1. Deselect the programmer or debugger
    2. Close the project.
    3. Disconnect the ICD2.

Writing and debugging your own firmware
    At some point you may want to write your own firmware, in which case you will want to do
some debugging. The process is similar to that of programming, except that you select DEBUG
instead of RELEASE in the IDE toolbar, and you work from the debugger menu instead of the
programmer menu.
    There are two debugging functions available to you that you can select from the debugger
menu, either MPLAB SIM or MPLAB ICD2. MPLAB SIM allows you to debug your firmware
without using any hardware. It is very useful in the early stages of firmware development,
particularly when you just want to validate your math. MPLAB ICD2 debugs your firmware
while it is running in your hardware. You can set breakpoints, start and stop your program, and
read and write to memory locations.




PIC Programming                                                                                   5
5/11/2009


Common mistakes, misunderstandings, and problems
    I am really hoping that everything goes smoothly for you, but you may run into some
problems. This section describes how to recognize and correct the most common ones.
   When things go wrong, the following is the most commonly encountered set of error
messages.
     Connecting to MPLAB ICD 2
...Connected
Setting Vdd source to target
ICDWarn0020: Invalid target device id (expected=0x101, read=0x0)
...Reading ICD Product ID
Running ICD Self Test
... Failed Self Test. See ICD2 Settings (Programmer->Settings) (status tab) for details.
MPLAB ICD 2 ready for next operation
   The most likely cause for this error is that the DevBoard does not have any power, or that the
ICD2 is not connected to the DevBoard. Go to the settings menu for the programmer and look
under the Power tab. There are three voltages listed. Vdd should be 5 volts or a little less, Vpp
should be around 13 volts.
    Another possibility is a defective 6 wire programming cable. Check the continuity on all 6
wires. (One of the ICD2s that I have was shipped with a defective cable.) Make sure the wires are
tight in the connectors. I had a cable in which one of the wires was making an intermittent
connection, it caused me a great deal of grief. Make sure the cable is connected to the right place
on the ICD2, the connector between the USB and the RS232.
    If you want to eliminate the 6 wire cable as a possible source of trouble, you can make the
connection between the ICD2 and the DevBoard with a pair of female-to-female 3 wire servo
cables, such as the ones that SparkFun sells,
http://www.sparkfun.com/commerce/product_info.php?products_id=9187. Be very careful to
connect the pins in the right order, refer to the 6 wire cable for the sequence.
     Another cause for this error is that you have somehow selected a different CPU. Take a look
at the bottom of the IDE window, it should say “dsPIC30F4011”. If not, go to the Configure
menu and select the correct device.
    Another possibility is that there is a compatibility issue involving the version of the IDE that
you are using. Some users have reported that after receiving the above error messages, they were
able to clear the problem by uninstalling the version of the IDE that they downloaded, and
loading version 7.50 instead. You can locate version 7.50 of the IDE by going to
www.microchip.com, and searching on IDE. One of the links will be to the IDE archives, from
which you can install version 7.50.
   At this point, if you are still getting the above error messages, you probably have a defective
ICD2. Contact SparkFun, explain the situation, and ask for an exchange.
    Another common set of error messages, that is easy to resolve, is the following:
    Connecting to MPLAB ICD 2
ICD0019: Communications: Failed to open port (USB): (Windows::GetLastError() = 0x2, 'The
system cannot find the file specified.
')



PIC Programming                                                                                        6
5/11/2009


ICD0021: Unable to connect with MPLAB ICD 2 (USB)
MPLAB ICD 2 ready for next operation
    You are almost guaranteed to get this message if you disconnect and then reconnect the USB
cable to the ICD2 while it is powered up. The best thing to do is to deselect the programmer
(select none), power off your DevBoard, disconnect the USB, close your project, exit the IDE,
and start all over again. This error may not clear the first time you restart, but it will eventually
clear.
    There are a few other common error messages that you may encounter, but they are self-
explanatory and easy to fix. There are some unusual error messages that you could encounter, but
I cannot reproduce them easily, so if you get stuck, contact me, I will give you a hand.




PIC Programming                                                                                         7

Más contenido relacionado

La actualidad más candente

laptop repairing course in delhi
laptop repairing course in delhilaptop repairing course in delhi
laptop repairing course in delhiAmit Gupta
 
An introduction to_programming_the_microchip_pic_in_ccs_c
An introduction to_programming_the_microchip_pic_in_ccs_cAn introduction to_programming_the_microchip_pic_in_ccs_c
An introduction to_programming_the_microchip_pic_in_ccs_cSuresh Murugesan
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityDanHeidinga
 
Developing Multi-OS Native Mobile Applications with Intel INDE
Developing Multi-OS Native Mobile Applications with Intel INDEDeveloping Multi-OS Native Mobile Applications with Intel INDE
Developing Multi-OS Native Mobile Applications with Intel INDEIntel® Software
 
Y1 gd engine_terminology (1)
Y1 gd engine_terminology (1)Y1 gd engine_terminology (1)
Y1 gd engine_terminology (1)RehanaWhiteley
 
Vipul divyanshu documentation on Kinect and Motion Tracking
Vipul divyanshu documentation  on Kinect and Motion TrackingVipul divyanshu documentation  on Kinect and Motion Tracking
Vipul divyanshu documentation on Kinect and Motion TrackingVipul Divyanshu
 
Csharp Hands On Lab Paul Yao
Csharp Hands On Lab Paul YaoCsharp Hands On Lab Paul Yao
Csharp Hands On Lab Paul YaoMamgmo Magnda
 
Multi-Configuration support in MTJ
Multi-Configuration support in MTJMulti-Configuration support in MTJ
Multi-Configuration support in MTJgustavoeliano
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security InternalsOpersys inc.
 
Enhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osEnhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osArnav Gupta
 
OpenTuesday: Die Selenium-Toolfamilie und ihr Einsatz im Web- und Mobile-Auto...
OpenTuesday: Die Selenium-Toolfamilie und ihr Einsatz im Web- und Mobile-Auto...OpenTuesday: Die Selenium-Toolfamilie und ihr Einsatz im Web- und Mobile-Auto...
OpenTuesday: Die Selenium-Toolfamilie und ihr Einsatz im Web- und Mobile-Auto...Digicomp Academy AG
 

La actualidad más candente (14)

tut0000021-hevery
tut0000021-heverytut0000021-hevery
tut0000021-hevery
 
Multi-OS Engine Technology Overview
Multi-OS Engine Technology OverviewMulti-OS Engine Technology Overview
Multi-OS Engine Technology Overview
 
laptop repairing course in delhi
laptop repairing course in delhilaptop repairing course in delhi
laptop repairing course in delhi
 
An introduction to_programming_the_microchip_pic_in_ccs_c
An introduction to_programming_the_microchip_pic_in_ccs_cAn introduction to_programming_the_microchip_pic_in_ccs_c
An introduction to_programming_the_microchip_pic_in_ccs_c
 
JavaOne 2016: Life after Modularity
JavaOne 2016: Life after ModularityJavaOne 2016: Life after Modularity
JavaOne 2016: Life after Modularity
 
Developing Multi-OS Native Mobile Applications with Intel INDE
Developing Multi-OS Native Mobile Applications with Intel INDEDeveloping Multi-OS Native Mobile Applications with Intel INDE
Developing Multi-OS Native Mobile Applications with Intel INDE
 
Y1 gd engine_terminology (1)
Y1 gd engine_terminology (1)Y1 gd engine_terminology (1)
Y1 gd engine_terminology (1)
 
Vipul divyanshu documentation on Kinect and Motion Tracking
Vipul divyanshu documentation  on Kinect and Motion TrackingVipul divyanshu documentation  on Kinect and Motion Tracking
Vipul divyanshu documentation on Kinect and Motion Tracking
 
Csharp Hands On Lab Paul Yao
Csharp Hands On Lab Paul YaoCsharp Hands On Lab Paul Yao
Csharp Hands On Lab Paul Yao
 
Multi-Configuration support in MTJ
Multi-Configuration support in MTJMulti-Configuration support in MTJ
Multi-Configuration support in MTJ
 
Android Security Internals
Android Security InternalsAndroid Security Internals
Android Security Internals
 
Enhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_osEnhancing and modifying_the_core_android_os
Enhancing and modifying_the_core_android_os
 
OpenTuesday: Die Selenium-Toolfamilie und ihr Einsatz im Web- und Mobile-Auto...
OpenTuesday: Die Selenium-Toolfamilie und ihr Einsatz im Web- und Mobile-Auto...OpenTuesday: Die Selenium-Toolfamilie und ihr Einsatz im Web- und Mobile-Auto...
OpenTuesday: Die Selenium-Toolfamilie und ihr Einsatz im Web- und Mobile-Auto...
 
Android
Android Android
Android
 

Similar a Pic programming gettingstarted

ARM-ES MANUAL.pdf
ARM-ES MANUAL.pdfARM-ES MANUAL.pdf
ARM-ES MANUAL.pdfvidhya1806
 
Programming atmega using boot loader
Programming atmega using boot loaderProgramming atmega using boot loader
Programming atmega using boot loaderruyanchung
 
03 Beginning Android Application Development
03 Beginning Android Application Development03 Beginning Android Application Development
03 Beginning Android Application DevelopmentArief Gunawan
 
verilog basics.ppt
verilog basics.pptverilog basics.ppt
verilog basics.ppt8885684828
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocksTech Bikram
 
openGl configuration_in visual studio 2019.pptx
openGl configuration_in visual studio 2019.pptxopenGl configuration_in visual studio 2019.pptx
openGl configuration_in visual studio 2019.pptxMuhammadUmer787617
 
Video optimization for android - Part I
Video optimization for android - Part IVideo optimization for android - Part I
Video optimization for android - Part IYoss Cohen
 
Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming Dr. Pankaj Zope
 
BMW Standard tools 2.12 on win7 64 bit
BMW Standard tools 2.12 on win7 64 bitBMW Standard tools 2.12 on win7 64 bit
BMW Standard tools 2.12 on win7 64 bitOBD365
 
Springboard & OpenCV
Springboard & OpenCVSpringboard & OpenCV
Springboard & OpenCVCruise Chen
 
Klement_0902_v2F (complete article)
Klement_0902_v2F (complete article)Klement_0902_v2F (complete article)
Klement_0902_v2F (complete article)Mike Friehauf
 
Final NEWS.pdf
Final NEWS.pdfFinal NEWS.pdf
Final NEWS.pdfRebaMaheen
 
Final NewsApp.pdf
Final NewsApp.pdfFinal NewsApp.pdf
Final NewsApp.pdfRebaMaheen
 
Larson and toubro
Larson and toubroLarson and toubro
Larson and toubroanoopc1998
 
Proposal project fared
Proposal project faredProposal project fared
Proposal project faredHaniz Razad
 
Z turn Board Tutorial Book
Z turn Board Tutorial BookZ turn Board Tutorial Book
Z turn Board Tutorial BookLinda Zhang
 
Chapter+1 +the+adventure+begins
Chapter+1 +the+adventure+beginsChapter+1 +the+adventure+begins
Chapter+1 +the+adventure+beginsnoor020202
 
Steps to be done in arduino ide for monitoring
Steps to be done in arduino ide for monitoringSteps to be done in arduino ide for monitoring
Steps to be done in arduino ide for monitoringCitharthan Durairaj
 

Similar a Pic programming gettingstarted (20)

Android app upload
Android app uploadAndroid app upload
Android app upload
 
ARM-ES MANUAL.pdf
ARM-ES MANUAL.pdfARM-ES MANUAL.pdf
ARM-ES MANUAL.pdf
 
Programming atmega using boot loader
Programming atmega using boot loaderProgramming atmega using boot loader
Programming atmega using boot loader
 
03 Beginning Android Application Development
03 Beginning Android Application Development03 Beginning Android Application Development
03 Beginning Android Application Development
 
Garagino doc
Garagino docGaragino doc
Garagino doc
 
verilog basics.ppt
verilog basics.pptverilog basics.ppt
verilog basics.ppt
 
How to work with code blocks
How to work with code blocksHow to work with code blocks
How to work with code blocks
 
openGl configuration_in visual studio 2019.pptx
openGl configuration_in visual studio 2019.pptxopenGl configuration_in visual studio 2019.pptx
openGl configuration_in visual studio 2019.pptx
 
Video optimization for android - Part I
Video optimization for android - Part IVideo optimization for android - Part I
Video optimization for android - Part I
 
Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming Unit III ARM Interface and ARM Programming
Unit III ARM Interface and ARM Programming
 
BMW Standard tools 2.12 on win7 64 bit
BMW Standard tools 2.12 on win7 64 bitBMW Standard tools 2.12 on win7 64 bit
BMW Standard tools 2.12 on win7 64 bit
 
Springboard & OpenCV
Springboard & OpenCVSpringboard & OpenCV
Springboard & OpenCV
 
Klement_0902_v2F (complete article)
Klement_0902_v2F (complete article)Klement_0902_v2F (complete article)
Klement_0902_v2F (complete article)
 
Final NEWS.pdf
Final NEWS.pdfFinal NEWS.pdf
Final NEWS.pdf
 
Final NewsApp.pdf
Final NewsApp.pdfFinal NewsApp.pdf
Final NewsApp.pdf
 
Larson and toubro
Larson and toubroLarson and toubro
Larson and toubro
 
Proposal project fared
Proposal project faredProposal project fared
Proposal project fared
 
Z turn Board Tutorial Book
Z turn Board Tutorial BookZ turn Board Tutorial Book
Z turn Board Tutorial Book
 
Chapter+1 +the+adventure+begins
Chapter+1 +the+adventure+beginsChapter+1 +the+adventure+begins
Chapter+1 +the+adventure+begins
 
Steps to be done in arduino ide for monitoring
Steps to be done in arduino ide for monitoringSteps to be done in arduino ide for monitoring
Steps to be done in arduino ide for monitoring
 

Más de Ajit Padmarajan

Más de Ajit Padmarajan (7)

Uav v30 schematic
Uav v30 schematicUav v30 schematic
Uav v30 schematic
 
Mediatek 3329
Mediatek 3329Mediatek 3329
Mediatek 3329
 
Gpsuav2 manual v29
Gpsuav2 manual v29Gpsuav2 manual v29
Gpsuav2 manual v29
 
Unmanned aerial vehicle
Unmanned aerial vehicleUnmanned aerial vehicle
Unmanned aerial vehicle
 
Bluetooth technology
Bluetooth technologyBluetooth technology
Bluetooth technology
 
glove input system
glove input systemglove input system
glove input system
 
Final biochips
Final biochipsFinal biochips
Final biochips
 

Pic programming gettingstarted

  • 1. UAV DevBoard: Getting Started with PIC Programming
  • 2. 5/11/2009 If you bought a UAV DevBoard, you will need to program it in order to do anything useful or interesting with it. It is not hard to do, after a few times it will be easy. But the first time can be confusing. This document will help you get started. In addition to the UAV DevBoard itself, you will need the following items to program it: • An ICD2. This is a programmer/debugger hardware item for connecting the DevBoard up to your computer. I suggest that you buy the one recommended by SparkFun, http://www.sparkfun.com/commerce/product_info.php?products_id=5. I do not recommend the “PIC-ICD2-Pocket”. I have one of these, and I have been able to get it to work with the dsPIC30F4011 CPU on the DevBoard, but there have been several reports of problems with it. • An IDE (interactive development environment). This software suite is available as a free download from MicroChip. It provides an excellent support environment for firmware development for the DevBoard. • A C compiler for the dsPIC30 family of CPUs. This is also available as a free download from MicroChip. Download and install the IDE and C compiler You should install the IDE before you connect the ICD2 to your computer, otherwise plug- and-play will get confused and will try to install the ICD2 without having the drivers that it needs. Go to the MicroChip website, www.microchip.com. Both the IDE and the compiler are available under the Design->Development Tools menu, in the Software section. Close all other applications first. Download and install the MPLAB IDE first. It will take a while. If it complains about applications that you have open, close them down and proceed. It may ask you about installing the HI-Tech C compiler, you should decline, you do not need the HI-Tech compiler.You should also download the MPLAB IDE user’s guide, it has a very useful section on getting started. After you install MPLAB IDE, download and install MicroChip’s C compiler. It is available under the same area as the IDE, under MPLAB C compilers. Click on MPLAB C compilers, and scroll to the bottom of the downloads list. Download and install “MPLAB C Compiler for dsPIC, Evaluation Version”. This is a free download. To get it, you will need to register with MicroChip. The only difference between the free evaluation version of the compiler and the purchased version is that after 60 days, the optimization options turn off. However, you do not need the optimization options, so it does not matter. You should also download the reference manual for the compiler. You can find it under the Design->Technical Documentation->User Guides, “MPLAB C Compiler for PIC24 MCUs and dsPIC DSCs Users Guide.” Depending on how deeply you intend to get into the programming of the dsPIC, there are also reference manuals on the dsPIC30F4011 hardware and programming model that you can download. After you install both the IDE and the compiler, you should check that the IDE is working. Click on the red and blue MPLAB IDE icon. The IDE should open. In the unlikely event that the IDE does not open, check the IDE user’s manual for suggestions on what to do. PIC Programming 2
  • 3. 5/11/2009 Installing the ICD2 After you install the IDE and the compiler, you need to install the ICD2. I am not real clear on this, I did it only once, and that was several years ago. There are instructions for installing the ICD2 in the help window of the IDE. My recollection is that you start up the IDE, and connect the ICD2 to your computer with a USB cable. Installation is then automatic. There are two ways that you can connect your ICD2 to your computer, either with the RS232 connector, or the USB, but not both. I recommend that you use the USB. So, bring up MPLAB IDE and plug in your ICD2 and wait for it to install. Programming the UAV DevBoard You are now ready to program your board. It is shipped with self-test firmware already installed. To do something more interesting, you will probably want to program it with something else. There are several programs available on the main page of UAV DevBoard, including demos, MatrixNav, and AileronAssist. Decide which one you want to start with, download it, and unzip it. Then, do the following. Some of the steps can be done in a different order, as you gain experience, it will become clear to you which ones can be shuffled around. Much of it is “common sense”: 1. Start up MPLAB IDE. If you have not already done so, start up the MPLAB IDE. 2. Connect your ICD2 to your computer through a USB connection. This will power up the ICD2. 3. Power up your UAV DevBoard. Apply approximately 5 volts on the power and ground pins of any servo or Rx channel of the board. If you are connecting an Rx to the board, you can backfeed power and ground through the Rx. Otherwise, the simplest thing to is to apply power and ground to one of the unused Rx channels. The pins nearest the edge of the board are ground, the center ones are power. Do not try to power the board from the spare Vcc pin. Your board may or may not do anything when it is powered up, depending on whether it is also connected to the ICD2 at the time. The ICD2 may hold the CPU in reset, if it is connected. 4. Connect your ICD2 to your DevBoard. Use the 6 wire ICSP cable that came with the ICD2. The connectors are keyed so that it is not possible to connect them backwards. The ICD2 has two places where you could make a connection, only one of them is the right one. Make a connection to the ICSP connector that is between the USB connector and the RS232 connector. 5. Open the project in MPLAB IDE. Under the project menu, select “open”. MPLAB will bring up a window for you to browse for the project that you want to open. Projects have a .mcp extension, and will have the MPLAB icon. Select the project that you want. 6. Make sure that the IDE is working in the RELEASE mode. PIC Programming 3
  • 4. 5/11/2009 The IDE is capable of both simple programming as well as debugging. You will start with programming. After you open the project, select RELEASE in the IDE toolbar. There are only two options, RELEASE and DEBUG. Chances are the project will come up in the DEBUG mode, change it to RELEASE. 7. Select your ICD2 as the programmer and check its settings. Select MPLAB ICD2 from the programmer menu. Check a couple of settings under programmer settings or debugger settings. Under the STATUS tab, select automatic downloading of firmware, but do not select connect at startup. Under the POWER tab, make sure that the programmer/debugger is not going to try to power the DevBoard from the ICD2. 8. Do a project “make”. This is an important step. Do not skip it. Otherwise you will simply erase the PIC without reprogramming it. Select “make” from the project menu. The IDE will compile and build the firmware. There will be several warnings issued, but there should not be any errors. At the end, there will be a message that the build was successful. This step usually goes smoothly, but there are a couple of things that could go wrong. If something went wrong during the installation of the C compiler, the IDE might not be able to find it. In that case, go to “Select Language Toolsuite” under the project menu. You want the Microchip C30 Toolsuite. If it is not selected, use the Toolsuite browser to find and select it. It should be located where ever you saved the IDE, probably under ProgramFilesMicrochipMPLABC30. 9. Execute a “Connect” operation. Select connect from the programmer menu. You should receive the following messages if everything goes right. If something goes wrong, skip to the last section for a list of common mistakes, misunderstandings, and problems. Connecting to MPLAB ICD 2 ...Connected Setting Vdd source to target Target Device dsPIC30F4011 found, revision = Rev 0x1003 ...Reading ICD Product ID Running ICD Self Test ...Passed MPLAB ICD 2 ready for next operation Also, the first time that you connect, the IDE will install a new operating system into the ICD2. It will ask you if you want to do that, you should accept. It will take a few minutes. After the first time, the IDE will skip this step, unless you are using the ICD2 to program another type of PIC. 10. Execute a “Program” operation. The IDE will program the board through the ICD2. You should see something similar to the following messages: Programming Target... ...Validating configuration fields ...Erasing Part PIC Programming 4
  • 5. 5/11/2009 ...Programming Programming Executive ...Verifying Programming Executive ...Programming Program Memory (0x0 - 0x187F) Verifying... ...Program Memory ...Verify Succeeded ...Programming Configuration Bits .. Config Memory Verifying configuration memory... ...Programming succeeded 10-May-2009, 18:04:07 MPLAB ICD 2 ready for next operation If you get error messages instead, skip to the last section. 11. Run the firmware. There are two ways of doing this. You can run the firmware with or without disconnecting the ICD2. If you want to leave the ICD2 connected, select “Release from Reset” from the programmer menu. If not, you can simply disconnect the ICD2 connection to the board, it will start running. You can also reset the CPU from the programmer by selecting “Hold in Reset”, and then “Release from Reset” from the programmer menu. This is a particularly convenient way to restart the firmware without disturbing the gyros. When you are done programming, I recommend that you do the following: 1. Deselect the programmer or debugger 2. Close the project. 3. Disconnect the ICD2. Writing and debugging your own firmware At some point you may want to write your own firmware, in which case you will want to do some debugging. The process is similar to that of programming, except that you select DEBUG instead of RELEASE in the IDE toolbar, and you work from the debugger menu instead of the programmer menu. There are two debugging functions available to you that you can select from the debugger menu, either MPLAB SIM or MPLAB ICD2. MPLAB SIM allows you to debug your firmware without using any hardware. It is very useful in the early stages of firmware development, particularly when you just want to validate your math. MPLAB ICD2 debugs your firmware while it is running in your hardware. You can set breakpoints, start and stop your program, and read and write to memory locations. PIC Programming 5
  • 6. 5/11/2009 Common mistakes, misunderstandings, and problems I am really hoping that everything goes smoothly for you, but you may run into some problems. This section describes how to recognize and correct the most common ones. When things go wrong, the following is the most commonly encountered set of error messages. Connecting to MPLAB ICD 2 ...Connected Setting Vdd source to target ICDWarn0020: Invalid target device id (expected=0x101, read=0x0) ...Reading ICD Product ID Running ICD Self Test ... Failed Self Test. See ICD2 Settings (Programmer->Settings) (status tab) for details. MPLAB ICD 2 ready for next operation The most likely cause for this error is that the DevBoard does not have any power, or that the ICD2 is not connected to the DevBoard. Go to the settings menu for the programmer and look under the Power tab. There are three voltages listed. Vdd should be 5 volts or a little less, Vpp should be around 13 volts. Another possibility is a defective 6 wire programming cable. Check the continuity on all 6 wires. (One of the ICD2s that I have was shipped with a defective cable.) Make sure the wires are tight in the connectors. I had a cable in which one of the wires was making an intermittent connection, it caused me a great deal of grief. Make sure the cable is connected to the right place on the ICD2, the connector between the USB and the RS232. If you want to eliminate the 6 wire cable as a possible source of trouble, you can make the connection between the ICD2 and the DevBoard with a pair of female-to-female 3 wire servo cables, such as the ones that SparkFun sells, http://www.sparkfun.com/commerce/product_info.php?products_id=9187. Be very careful to connect the pins in the right order, refer to the 6 wire cable for the sequence. Another cause for this error is that you have somehow selected a different CPU. Take a look at the bottom of the IDE window, it should say “dsPIC30F4011”. If not, go to the Configure menu and select the correct device. Another possibility is that there is a compatibility issue involving the version of the IDE that you are using. Some users have reported that after receiving the above error messages, they were able to clear the problem by uninstalling the version of the IDE that they downloaded, and loading version 7.50 instead. You can locate version 7.50 of the IDE by going to www.microchip.com, and searching on IDE. One of the links will be to the IDE archives, from which you can install version 7.50. At this point, if you are still getting the above error messages, you probably have a defective ICD2. Contact SparkFun, explain the situation, and ask for an exchange. Another common set of error messages, that is easy to resolve, is the following: Connecting to MPLAB ICD 2 ICD0019: Communications: Failed to open port (USB): (Windows::GetLastError() = 0x2, 'The system cannot find the file specified. ') PIC Programming 6
  • 7. 5/11/2009 ICD0021: Unable to connect with MPLAB ICD 2 (USB) MPLAB ICD 2 ready for next operation You are almost guaranteed to get this message if you disconnect and then reconnect the USB cable to the ICD2 while it is powered up. The best thing to do is to deselect the programmer (select none), power off your DevBoard, disconnect the USB, close your project, exit the IDE, and start all over again. This error may not clear the first time you restart, but it will eventually clear. There are a few other common error messages that you may encounter, but they are self- explanatory and easy to fix. There are some unusual error messages that you could encounter, but I cannot reproduce them easily, so if you get stuck, contact me, I will give you a hand. PIC Programming 7