PIC Microcontroller DIY

        Introducing PIC Microcontroller projects

 

Written by Lim Siong Boon, last dated 20-Oct-09.

email:   _l_mail@siongboon.com_l_

website: http://www.siongboon.com

<email address is blue in color,

please ignore "_l_">

 

 

PIC Microcontroller

 

Source code for Library for C30 compiler project digital potential meter, EE memory

 

 

Development Tools History

 

 

PIC microcontroller Development Board

(Completed on 2006-10-28)

The ultimate PIC Microcontroller development board. After years of programming PIC microcontroller, I have finally design my super development board to program PIC microcontroller firmware. The automatic programming mode select and the 40 bits LED light bar display have ease my programming process and increase debugging speed by 10 times. I can easily do troubleshooting because of the 40 bits LED display. The LED allows display for 5 bytes of variables using only 3 bits of any output port. I used to allocate PORTD to display one byte of the memory. Debugging used to be slow and tedious. This board also features automatic select to programming mode when the board is powered down. This means that there is no need to do manual switching. The ICSP interface allows the firmware to be loaded to the microcontroller without inserting/removing IC chip.

Features

-Development for 18, 28, 40 pins DIP PIC microcontroller

-Serial Communication RS232, with Tx/Rx transmission activities indicator.

-Changeable microcontroller Crystal Clock

-ICSP programming pins

-Automatic switch to programming mode when board power is turned off.

-Proper labels and easy to view LED bar display, buffered from all the ports. Output pins from all the ports.

-Serial to parallel data latching to extend more output bits from 3 output pins. Output pins with easy to view LED bar display.

-Adjustable dc-dc power supply using LM2576-ADJ IC to cater for 5V and 3.3V power supply system.

-Features 74HC series logic family and Max232 IC for operating on 3.3V power supply. (see logic family selection guide)

-Fuse protection.

 

     

Click on the image for Circuit Schematic

For more information for extending microcontroller I/O (input/output) ports using "serial to parrallel" or "parallel to serial" circuit, you can refer to More Circuit Schematic.

 

The development board uses the following logic IC:

74HC595, serial to parallel with output latched

74HC244, octal logic buffer

MAX232, RS232 to TTL tranceiver

LM2576-adj, DC-DC voltage regulator

 

For more information on how to select logic family, see "Logic Selection Guide" from Texas Instrument.

Introduction: AUP, CBT-C, CB3T/Q, SSTU, VME, AUC, SSTV, GTLP, Little Logic, AVC, TVC, ALVT, CBTLV, ALVC, CBT, LVC, LV

Mature: AHC/AHCT, LVT-A, ABT, FCT, AC/ACT, HC/HCT, BCT, CD4000

Obsolescence: 74ALS, 74F, 74AS, 74LS, 74S, 74xx (oldest)

 

PIC microcontroller Programmer

(Completed in the year 2005)

My first own build programmer system. Spent quite a lot of time designing and fabricating the plastic box chassis. It works, but I never really work much with it after I brought myself a commercial version.

 

Microcontroller DIP IC Adaptor

(Completed in the year 2002-05-xx)

This is a interface board for fitting various model of PIC microcontroller to the programmer. The programming pins numer is different for every PIC microcontroller model. This interface board eliminate the need to build a new programmer board for different PIC microcontroller model.

 

PIC Programmer & Development board

(Completed in the year 2002-05-xx)

This board is design to be function as a multi purpose PIC microcontroller development board. I have build specially to trial run the microcontroller firmware I wrote. Bi-directional digital buffer are used, to protect the microcontroller from external device during interfacing. After working with microcontroller for some time, I find that this buffer interface is not necessary. Microcontroller I/O ports do not damage easily. When interfacing microcontroller with high powered or unknown devices, opto-coupler can be used instead. Opto-coupler provides maximum isolation as well as protection between the microcontroller and other devices.

Attached to the main PCB is a smaller PCB board. It consist of a MAX232 converting computer RS232 to microcontroller TTL serial signal. This small board also include a charge pump circuit that generate 12V from a 5V source for the purpose of programming the PIC microcontroller. This programmer design "Toolkit TK3 PIC programmer" was taken reference from my favourite hobby magazine "Everyday Practical Electronics".

 

Development Board schematic & PCB layout

Programmer Board schematic & PCB layout

Microcontroller Essential Test Tools

(Completed in the year 2002-05-xx)

Input switches and Output LED test board interface. It is very useful when doing microcontroller project, because it can help to indicate if the firmware is running correctly inside the microcontroller. A must have kit when doing digital project.

 

 

PIC microcontroller selection references.

table updated in 26 May 2007

Number of Pin PIC16F series PIC18F series alternative
14 PIC16F688  
18

(all  models, not pin compatible)

PIC16F88, PIC16F648a, PIC16F628a, PIC16F84a PIC18F1320, PIC18F1220, PIC18F1330, PIC18F1230
28 PIC16F876a PIC18F2620, PIC18F2525, PIC18F2420
40 PIC16F877a PIC18F4620, PIC18F4525, PIC18F4420
40 USB supported Best features PIC18F4550

 

 

 

 

 

 

Microchip MPLAB microcontroller startup troubleshooting guide.

2009-10-08

Getting my "hello world" firmware loaded into my new hardware design pose the most difficult part of the process. Time consuming doing debugging, and it can takes from half a day to two. The most difficult part, to spent those precious engineering time in debugging. Debugging what I thought I should be good in since I have done so many microcontroller project. Till this day, I still have the problem every time I start microcontroller project after a few months break. The reason I have this guide written. To provide myself possible solution, that can help me, if I encounter the same issue again.

 

 
I use PICkit2 most of the time, because it is a small and compact programmer. Today, I tried out PICkit3. Well I am quite impress with the changes from PICkit2. I hope to get that one day. As for this article, the error messages is meant for PICkit2 use on the IDE Mplab version 8.36.

I do not have much problem doing the compilation of my C programs. The frustration comes during the loading of my hex codes into my newly design prototype circuit. Most of the time is due to human error, because my prototype board are mainly hand soldered, pin by pin.

On the left is the typical error message I encounter. I am scare of them to be frank. I see them almost every time.

 

Initialisation of PICkit2 when connected to Mplab

Initializing PICkit 2 version 0.0.3.63
Found PICkit 2 - Operating System Version 2.32.0
Target power not detected - Powering from PICkit 2 ( 3.30V)
PKWarn0003: Unexpected device ID:  Please verify that a PIC24FJ32GA004 is correctly installed in the application.  (Expected ID = 0x44D0000, ID Read = 0x0)
PICkit 2 Ready

Every time when I press the shortcut key Alt+G, G to program the controller, PICkit will attempt to read the device ID of the microcontroller. The microcontroller used in this example is PIC24FJ32GA004.

As you can see in the error on the right. PICkit is expecting the microcontroller with device ID 0x44D0000. The read by PICkit detects a ID of 0x0. In fact this same error is identical as if the PICkit programmer is not inserted to the ICSP programming pins at all.

This is a hard evident that the microcontroller is not wired properly or evenly not wired at all.

 

Error Encounter using PICkit2 version 2.63, MPLAB version 8.36

Programming Target (10/8/2009  4:37:06 PM)
PKWarn0003: Unexpected device ID:  Please verify that a PIC24FJ32GA004 is correctly installed in the application.  (Expected ID = 0x44D0000, ID Read = 0x0)
Erasing Target
Programming Program Memory (0x0 - 0x23FF)
   PE Error: Using ICSP
Verifying Program Memory (0x0 - 0x23FF)
   PE Error: Using ICSP
PK2Error0027:  Failed verify (Address = 0x0 - Expected Value 0x40200 - Value Read 0x0)
PICkit 2 Ready

 

1) The first thing to check if your hardware. It is most of the time the source of the problem. Check if the ICSP programming pins are wired correctly

Pin 1: !MCLR

Pin 2: Vdd (3.3V or 5V, depends on the device)

Pin 3: Vss (ground)

Pin 4: PGD (data line)

Pin 5: PGC (clocking line)

Pin 6: unused

 

Attached on the left is the basic schematic of the microcontroller PIC24FJ32GA004 if your wiring is exactly the same as what is shown, PICkit2 should be able to load the hex file into your controller without any problem.

An advise to you, don't assume that your wiring is correct. Check 2 or more times to ensure. This is often one of my major mistake make. The schematic is typically correct, but because of the confident doing many similar project, the checking is often the lacking part.

For PIC24FJ series controller, there is a pin Vcap & DISVREG. Make sure that there is the capacitor there. !MCLR pin to be pull up to Vdd using a resistor about 10kohm.

The following pins are to be connected to PIC24FJ32GA004, in order for the ICSP programmer to download the *.hex files onto the microcontroller. Improper connection will definitely generate programming error messages.

 

Pins connection

Pin 18 connect to !MCLR
Pin 17, 28, 40 connect to Vdd (3.3V)
Pin 6, 16, 29, 39 connect to Vss (Gnd)
Pin 21 connect to PGD
Pin 22 connect to PGC
Pin 7 connect to as Vcap

 

Socket holder for PIC24FJ32GA004 TQFP-44 prototype board

Front

Back

TQFP-44 Prototype board or adaptor

 

 

2) Check if the header file declare in the source code is correct
#define    __PIC24FJ32GA004__
#include "p24fxxxx.h"

This actually informs the PICkit programmer what type of device it is going to encounter. This is also why the error message indicates the expected ID of 0x44D0000, which is the device ID for PIC24FJ32GA004 microcontroller.

Some example of other device ID for PIC24FJ series microcontroller.

Microcontroller          Device ID

PIC24FJ16GA002     0x00444

PIC24FJ32GA002     0x00445

PIC24FJ48GA002     0x004466

PIC24FJ64GA002     0x00447

PIC24FJ16GA004     0x0044C

PIC24FJ32GA004     0x0044D

PIC24FJ48GA004     0x0044E

PIC24FJ64GA004     0x0044F

You might double check if the microcontroller device is selected correctly under the menu "Configure". It is probably not necessary as the device select is base on what is written with your source code.

 

 
3) Check if you have included the correct linker file for the microcontroller PIC24FJ32GA004. The file name goes something like this, "p24FJ32GA004.gld". The file is available under the C30 folder "C:\Program Files\Microchip\MPLAB C30\support\PIC24F\gld", after you installed the C30 compiler for your Mplab.

 

 
4) Do not solder capacitors on PGD, PGC pins. PGD PGC can be use for programming as well as I/O during operation. Due to the programming use, I will usually design this pin as an input during operational. This feature do free up the controller pins for other uses. Using it as an input, it does not have any load to worry about. There is one time I added capacitor across the input and ground, thinking that it may filter any switching noise from the switch input. The capacitor turns out to cause problem to the PGD PGC pins. It results in a slow slew rate causing data error during program loading.

 

 
5) Ensure that your circuit is powered from it's own power source. This is especially needed if you have a big load of components on our board. The PICkit programmer might not be able to support all those power. Sometimes the PICkit doesn't provide the power. There should be a settings that allows your PICkit to supply the power.

 

 
Another similar error occur. This time round, the device ID is read as 0xFFFF0000. I found the problem and it happens that the ICSP pin 4 (PGD, data) and pin 5 (PGC, clock) has been wire wrongly. They are swapped. Programming Target (10/8/2009  6:13:18 PM)
PKWarn0003: Unexpected device ID:  Please verify that a PIC24FJ32GA004 is correctly installed in the application.  (Expected ID = 0x44D0000, ID Read = 0xFFFF0000)
Erasing Target
Programming Program Memory (0x0 - 0x23FF)
   PE Error: Using ICSP
Verifying Program Memory (0x0 - 0x23FF)
   PE Error: Using ICSP
PK2Error0027:  Failed verify (Address = 0x0 - Expected Value 0x40200 - Value Read 0xFFFFFF)

 

When the PICkit2 has sucessfully loaded the hex file into the microcontroller chip, you should see the message on the right. PICkit2 program loaded into microcontroller sucessfully

Programming Target (10/9/2009  10:30:46 AM)
PIC24FJ32GA004 found (Rev 0x3003)
Erasing Target
Programming Program Memory (0x0 - 0x23FF)
  (Using Programming Executive)
Verifying Program Memory (0x0 - 0x23FF)
  (Using Programming Executive)
Programming Configuration Memory
Verifying Configuration Memory
PICkit 2 Ready

   
   

 

 

 

 

 

email:   _l_mail@siongboon.com_l_

website: http://www.siongboon.com

<email address is blue in color,

please ignore "_l_">

 

 

Keyword: Microchip PIC microcontroller prototype development, PIC programmer, Max232, ICSP programming interface, output buffer, LED indicator, 74LS595 74HC595, 74LS244 74HC244, DC-DC power supply, 40pins 28pins 18pins DIP IC

PIC18F4550, PIC18F452, PIC16F877a

PIC18F252, PIC16F876a

PIC16F88, PIC16F628a, PIC16F84a