Sunday, January 24, 2016

pic microcontroller programming tutorial microchip

Some of my favorite tutorials for to program the PIC microcontroller. The TL;DR is figure out what microcontroller I have (it's a dsPIC30F6012A), download the IDE from Microchip, select the previous project, make changes and save it as a new project, hit compile until it doesn't fail compilation, plug in the IDE3 in circuit debugger, select it, find the refresh button to get the IDE to recognize the debugger cable, hit build for download which will do the download.

Some links:

An immense collection of tutorials for PIC16 microcontroller: http://pic-microcontroller.com/pic16-microcontrollers-video-tutorial-series/

An overview page from Microchip that doesn't really tell much that wasn't already obvious: https://www.microchip.com/pagehandler/en_us/designsupport/programming

A video for an earlier version of the Microchip IDE. This video helps penetrate the mysterious complexity of the IDE: https://www.youtube.com/watch?v=mUofSucHx_E

Another helpful video, again not for my version of the IDE but they make so many updates to the IDE that it's not a mystery. Fortunately, some things get carried through various versions: https://www.youtube.com/watch?v=dGc0BMCoeVg&spfreload=1

Somebody who had the same problem as me of needing to get started quickly without having to plow through long manuals. The second reply turned out to be a great list of tutorials: http://www.microchip.com/forums/m139145.aspx

A list of amazingly complete tutorials, alas for a different PIC than I have: http://www.amqrp.org/elmer160/lessons/index.html

A search that I did on Microchip's site when my compilation was having trouble finding a particular header. I think that the eventual solution was to correctly import the entire build directory for the previous project, which had everything properly set up. http://www.microchip.com/search/searchapp/searchhome.aspx?q=spi.h: No such file or directory&resperpage=10&id=2

Another search for how to solve an error message that I was getting. None of the answers in this tread were helpful to me, but they seemed to contain a lot of smart background information I might want to review later. My problem was solved by just reusing the setup from the previous project: http://www.microchip.com/forums/m594491.aspx

One of the problems that I had was that my project wasn't able to find the UART.h and other header files. I don't remember how I solved this; it involved adding a new path or something because the place that these headers were kept changed between the earlier version of the IDE that the program was originally compiled in and the new version that I used.http://www.microchip.com/forums/m766175.aspx
http://www.microchip.com/forums/m773469.aspx
http://www.microchip.com/forums/m528591.aspx

I'm not sure how I ended up looking into what seems to be something to do with graphics libraries, but here's the head of the search that I did: http://microchip.wikidot.com/hif2131:mla-installation

A step-by-step of how I used the MPLAB X IDE to build a project.

1. Start the IDE. For some reason two applications were installed, IDE and IPE. I have no idea what IPE is.

2. If another project is open, select File->Close Project

3. Copy the entire folder containing the old project to be modified to a new folder with the new version name

4. Under File->Open Project, select the new folder. The project will have the old name when it comes up in the "Projects" tab of the navigator pane of the IDE, but you can right click on it and from the context menu select "Rename..." which gives you the option to change the name. An option to "Also Rename Project Folder" is present, but it is not needed because the folder that has been copied already was given the new name in step 3.

5. If not already done, expand the project in the navigator pane to show all the files in the project. Double click on any of the files to edit them.

6. Compile using the hammer or hammer & dustbroom until a clean compile is achieved.

7. Plug the ICD3 adapter into both the programmer connector on the board and a USB port on the PC. *Power on the board with the dsPIC*. In the tiny "Dashboard" pane in the lower right of the MPLAB window, click the "recycle" icon to activate the ICD3 and make it check for a good connection to the dsPIC

8. Click the "Make and Program Device" icon to build the project gain and download it. After the usual build is done, a new tab with the label "ICD 3" will open in the status area and show the status of programming.