Saturday 7 June 2008

PIC Microcontroller Introduction

A PIC microcontroller is a processor with built in memory and RAM and you can use it to control your projects (or build projects around it). So it saves you building a circuit that has separate external RAM, ROM and peripheral chips.


What this really means for you is that you have a very powerful device that has many useful built in modules e.g.

* EEPROM.
* Timers.
* Analogue comparators.
* UART.


Even with just these four modules (note these are just example modules - there are more) you can make up many projects e.g.:

* Frequency counter - using the internal timers and reporting through UART (RS232) or output to LCD.

* Capacitance meter - analogue comparator oscillator.

* Event timer - using internal timers.

* Event data logger -capturing analogue data using an internal ADC and using the internal EEPROM for storing data (using an external I2C for high data storage capacity.

* Servo controller (Control through UART) - using the internal PWM module or using a software created PWM.

The PIC Micro is one of the most popular microcontrollers and in case you were wondering the difference between a microprocessor and a microcontroller is that a microcontroller has an internal bus with in built memory and peripherals.

In fact the 8 pin (DIL) version of the 12F675 has an amazing number of internal peripherals. These are:

* Two timers.
* One 10bit ADC with 4 selectable inputs.
* An internal oscillator (or you can use an external crystal).
* An analogue comparator.
* 1024 words of program memory.
* 64 Bytes of RAM.
* 128 Bytes of EEPROM memory.
* External interrupt (as well as interrupts from internal peripherals).
* External crystal can go up to 20MHz.
* ICSP : PIC standard programming interface.

And all of these work from within an 8 pin DIL package!

In the mid-range devices the memory space ranges from 1k to 8k (18F parts have more) - this does not sound like a lot but the processor has an efficient instruction set and you can make useful projects even with 1k e.g. LM35 temperature sensing project that reports data to the serial port easily fits within 1k.

Features
In fact a PIC microcontroller is an amazingly powerful fully featured processor with internal RAM, EEROM FLASH memory and peripherals. One of the smallest ones occupies the space of a 555 timer but has a 10bit ADC, 1k of memory, 2 timers, high current I/O ports a comparator a watch dog timer... I could go on as there is more!
Programming
One of the most useful features of a PIC microcontroller is that you can re-program them as they use flash memory (if you choose a part with an F in the part number e.g. 12F675 not 12C509). You can also use the ICSP serial interface built into each PIC Microcontroller for programming and even do programming while it's still plugged into the circuit!

You can either program a PIC microcontroller using assembler or a high level language and I recommend using a high level language such as C as it is much easier to use (after an initial learning curve). Once you have learned the high level language you are not forced to use the same processor e.g. you could go to an AVR or Dallas microcontroller and still use the same high level language.
Input / Output - I/O
A PIC Microcontroller can control outputs and react to inputs e.g. you could drive a relay or read input buttons.

With the larger devices it's possible to drive LCDs or seven segment displays with very few control lines as all the work is done inside the PIC Micro.

Comparing a frequency counter to discrete web designs you'll find two or three chips for the microcontroller design and ten or more for a discrete design. So using them saves prototype design effort as you can use built in peripherals to take care of lots of the circuit operation.

Many now have a built in ADC so you can read analogue signal levels so you don't need to add an external devices e.g. you can read an LM35 temperature sensor directly with no interface logic.
Peripherals
The PIC microcontroller has many built in peripherals and this can make using them quite daunting at first which is why I have made this introductory page with a summary of each major peripheral block.

At the end is a short summary of the main devices used in projects shown on this site.

The best way to start is to learn about the main features of a chip and then begin to use each peripheral in a project. I think learning by doing is the best way.
Flash memory
This is the program storage area and gives you the most important benefit for using a PIC microcontroller - You program the device many times. Since when does anyone get a program right first time ?

Devices used in projects on this site can be re-programmed up to 100,000 times (probably more) as they use Flash memory - these have the letter F in the part name. You can get cheaper (OTP) devices but these are One-Time-Programmable; once programmed you can't program it again!
ICSP
In Circuit Serial Programming (ICSP) is the next most important benefit. Instead of transferring your chip from the programmer to the development board you just leave it in the board. By arranging the programming connections to your circuit correctly you won't need to remove the chip!

You can re-program the device while it's still in the circuit so once your programmer is setup you can leave it on the bench and test your programs without moving the chip around and it makes the whole process much easier.

Read More......