can you do with a microcontroller?
Answer: Virtually Any Project
Microcontrollers give you a fantastic way
of creating projects. 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.
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:
And all of these work from within an 8 pin DIL package!
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.
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.
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.
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||Re-programmable program storage.|
|RAM||Memory storage for variables.|
|EEPROM||Long term stable memory : Electrically Erasable Programmable Read Only Memory.|
|I/O ports||High current Input/Output ports (with pin direction change).|
|USART||Built in RS232 protocol (only needs level translator chip).|
|SSP||I2C and SPI Interfaces.|
|Comparator||An analogue comparator and internal voltage reference.|
|ADC||Analogue to digital converter.|
||Parallel Slave Port (for 8 bit
|ICSP||Simple programming using In Circuit Serial Programming.|
Most PIC microcontroller pins can be set as an input or and output and this
can be done on the fly e.g. for a dallas 1 wire system a pin can be written to
generate data and read at a later stage. The TRIS register controls the I/O
direction and setting a bit in this register to zero sets the pin as output while setting it as one sets the pin as input.
This allows you to use a pin for multiple operations e.g. the Real Time clock project uses RA0, the first pin of PORTA, to output data to a seven segment display and at a later point in the program read the analogue value as an input.
The PIC I/O ports are high current ports capable of directly driving LEDs
(up to 25ma output current) - the total current allowed usually ~200mA this is
often for the whole chip (or specified for several ports combined
Each PIC microcontroller has up to three timers that you can either use as a timer or a counter (Timer 1 & 2) or a baud clock (Timer 2).
The original timer: Timer 0 was the first timer developed and you can find
it in all the earliest devices e.g. 16F84 up to the most current e,g, 16F877A.
It is an 8 bit timer with an 8 bit prescaler that can be driven from an internal (Fosc/4) or external clock. It generates an interrupt on overflow when the count goes from 255 to zero.
Timer 0 always synchronizes the input clock (when using external clock).
Note: You can read and write timer 0 but you can not read the prescaler.
Note: The prescaler changes its effect depending on whether it is a timer prescaler or a watch dog prescaler - so the same prescaler setting may prescale by 2 or by 1 depending on its use!
This is a 16 bit timer that generates an overflow interrupt when it goes
from 65535 to zero. It has an 8 bit programmable prescaler and you can
drive it from the internal clock (Fosc/4) or an external pin.
To eliminate false triggering it also has an optional input synchronizer for external pin input.
This timer can be used in sleep mode and will generate a wakeup interrupt on overflow.
Timer 1 is also read by the CCP module to capture an event time.
Note: Using this timer in sleep mode will use more current.
This is an 8 bit timer with an 8 bit prescaler and an 8 bit postscaler. It
takes its input only from the internal oscillator (Fosc/4).
This timer is used for the timebase of a PWM when PWM is active and it can be software selected by the SSP module as a baud clock.
The USART is a useful module and saves having to code up a software version
so it saves valuable program memory. You can find more information on RS232
here and how to make it work. Look here for pin outs.
All you need to interface it to a PC serial port is a MAX232 chip (or equivalent).
Note: An equivalent MAX232 chip is the SP202ECP that has the same pinout as the MAX232 but lets you use 100nF capacitors - so you don't need the large 1uF caps.
You have to be careful using the baud rates as they depend on the main clock
in use and normal oscillator values in general do not fit very well with 'real'
The Capture/Compare/PWM module has three modes of operation:
Capture mode is used to capture the value of Timer 1 when a signal at the
CCP pin goes high (or low depending on how the CCP is set up). The CCP can
accurately capture the arrival time of a signal at the CCP pin so it can be
used for pulse time measurement.
Compare mode is used to generate an output when Timer 1 reaches a value you
put into CCPR1. One special event trigger mode lets you start the ADC when
the compare mode triggers.
PWM gives you one Pulse Width Modulation output with 10 bit resolution and
with no software overhead - once started it operates all by itself unless you
want to change the duty cycle.
It uses Timer 2 to define its operation using Timer 2 period register to define the frequency of the PWM.
Note: The duty cycle is not a percentage it is the number of periods of the PWM clock that the output is high!
SPI and I2C are shared so you can only use one at a time (or you could use the I2C bit banged routines in the Real Time Clock project to have both at the same time).
You can find a project that uses I2C here and you can find more information on I2C here.
The comparator is module that has two analogue comparators which can be set
up in one of 8 different ways. Either digital or analogue inputs can be
compared to reference voltages.
In one mode an internally generated voltage reference is used as an input to both comparators and in the same mode multiplexing lets you monitor up to four different input pins.
You can even send the output of the comparator to a pin so that it is used independently from the microcontroller e.g. in a circuit where you need a comparator you don't need an extra chip!
The analogue level must be between Vdd and Vss as protection diodes won't allow anything else.
The module will generate an interrupt if the comparator output changes.
You can use it in sleep mode and the interrupt will wake it up.
The source impedance of the analogue signal must be smaller than 10k.
The single 10 bit Analogue to Digital Converter can have up to 8 inputs for
a device multiplexed from input pins.
The ADC can be used during sleep but you have to use the RC clock mode. One benefit of this is that there will be no digital switching noise so you will get better conversion accuracy.
The 16F675 can measure 4 analogue input pins!
The Parallel Slave Port lets you to connect the PIC microcontroller directly
into a microprocessor system. It provides an 8 bit read/write data bus and RD
(read) WR (write) and CS (chip select) inputs - all active low.
This provides an easy route to adding a PIC microcontroller to an 8 bit system that already exists.
|ICSP||In Circuit Serial Programming||click here (jumps to ICSP section).|
|WDT||Watch dog timer||This is a software error protector.|
|BOR||Brown Out reset||This detects if the power supply dips slightly and resets the device if so.|
|POR||Power on reset||This starts microcontroller initialization.|
|PWRT||PoWeR up Time||A time delay to let Vdd rise.|
|OST||Oscillator start up timer||Wait for 1024 cycles after PWRT.|
|SLEEP||PIC microcontroller sleep mode||Enter low power mode.|
If your software goes haywire then this timer resets the processor. To
stop the reset the well behaved software must periodically issue the CLRWDT
instruction to stop a resert. The WDT runs using its own oscillator. It
runs during sleep and shares Timer 0 prescaler.
Power On Reset starts PIC microcontroller initialization when it detects a
rising edge on MCLR.
If you enable this then 72ms after a POR the PIC microcontroller is
Oscillator Startup Timer delays for 1024 oscillator cycles after PWRT (if
PWRT is enabled) ensuring that the oscillator has started and is stable. It
is automatic and only used for crystal oscillator modes and is active after POR
or wake from sleep.
Sleep mode (or low power consumption mode) is entered by executing the
'SLEEP' command. The device can wake from sleep caused by an external reset,
Watch Dog Timer timeout, INT pin RB port change or peripheral interrupt.
All three devices are extremely powerful and the main difference is that they have different numbers of pins and memory size.
Note: There are differences in using the devices i.e. there are some registers that are different but in the generally you can interchange them - this is made easier using a high level language.
The devices used in this site are:
|PIC microcontroller Device||PIC microcontroller No. Pins||PIC microcontroller Flash memory WORDS|
(Note: that all of them have the letter F in - this means it is a Flash re-programmable part - don't go and buy a part with O in as its OTP - programmable only once! - only do that if you are really really sure it's the final design).
You may think that 1k or even 8k is so tiny that it won't be useful but each
PIC microcontroller uses RISC (Reduced Instruction Set Computing) which simply
means that it has a cleverly arranged instruction set that only has a few
instructions. The mid range parts have 35 instructions.
If you use the high level language as recommended in this site then you won't need to be too aware of the instruction set it just means you can do a lot with a small amount of memory. Most of the projects on this site although they are fully working projects fit within 2k words!
Note: If you need more memory you can always move to the 18F series of PIC microcontrollers. Another option is to add an I2C serial eprom.
New! CommentsHave your say about what you just read! Leave me a comment in the box below.
Jump from PIC microcontroller introduction to
Best Microcontroller Projects Home Page.
How to use the MCP23017 to increase your I/O by 16 pins (or more) and use its interrupt system.
Arduino Battery Charger: A very useful project that lets you charge 'un-rechargeable' alkaline batteries!
Digispark ATtiny85: Essential information on setting up and using this tiny, but powerful, chip