takeMeToYourRobot logo

Microcontroller PIC 16F876A

PREAMBLE

This is a short review of the PIC 16F876a made by Microchip. I certainly don't know everything about this microcontroller and all its capabilities but I have used it to build many of my behavioural (i.e. robotic and mechatronic) sculptures so I'll try to pass on some of what I have learned here and give you an idea of how I think the chip stacks up against other options.

My strategy has been to choose a microcontroller technology and stick with it for a while in order to avoid time lost to learning curves and the surprising idiosyncrasies that all microcontrollers harbour. Every so often, I look around more carefully and choose a new package to work with. I may very well do this soon (and am very excited about the QWERK, for instance) but for certain applications and when I want to make things small I will probably continue to use the 16F876A.

SOME OF THE BASIC SPECIFICATIONS OF THE CHIP

Some basic specifications of the chip: A) it comes in a 28-pin DIP package plus a few surface-mount varieties B) it has 22 I/O pins C) it has 256 bytes of EEPROM data memory, 14 kBytes of program memory, and 368 bytes of RAM D) it has 5 channels of 10-bit Analog-to-Digital (A/D) converters E) it has 2 capture/compare/PWM functions F) it has a synchronous serial port can be configured for SPI or I2C and G) it has USART.

A) and B) mean it has a significant number of pins for you to do stuff with (attach to sensors, buttons, motor-control ICs, screens etc.), especially if you are comparing it to the once popular 16F84 or something of that ilk. C) means, amongst other things, that in certain cases you might find that you are writing programs that don’t fit on the chip or that require more memory (especially if you start using a lot of floats or non-small arrays) but for a lot of things you’ll be just fine D) means that you don’t need another chip to do conversion of analog signals (like the signal from the Sharp range-finders for instance). One of the really useful things about E) is that you can set up PWM outputs (perhaps to a motor control IC for instance; (unfortunately, if I remember correctly, these can not be set to a slow enough frequency to control hobby servo motors so you have to do this in your code, ideally in an timer interrupt)) that take care of themselves (i.e. don’t need to be manually coded or done in your own custom interrupts). F) is good because a lot of sensors and other ICs use these interface protocols and hence this uC can talk to those devices with just a little setup.

BOOTLOADER AND CROSS-COMPILER

I use the PIC C compiler from CCSC which is, in general, well-documented and easy to use. There are some places where the documentation is cryptic and misleading (a specific instance: I banged my head against the wall getting the SPI working with a particular sensor and only fixed it by guessing what an undocumented flag that I found in the header did)

I use a bootloader with this chip that I got from

A bootloader allows you to change the code on your chip without removing it from the circuit that it is part of. This is quicker and easier than using a chip programmer (although you do have to use the chip programmer to put the bootloader on in the first place) especially as you might want to have your control circuit somewhere deep within your sculpture. Using the bootloader, you only have to run a few wires out for serial coms and everything else can be in the bowels of your machine.

Many microcontroller-based control boards (like the Basic Stamp and the Arduino) also have bootloaders but I have noticed that the Arduino bootloader is currently quite slow compared to the one I use on the PIC and, since you have to bootload your code in every iteration of your programming cycle, having a short load time is critical for productivity and sanity.

INTERRUPTS

Additionally, although I can’t say this with authority because I have not used many of these other options, it sounds as if it is difficult (maybe not even possible) to write code for the Arduino (and some of these other boards) that takes advantages of interrupts. Interrupts are critical if you want your uC to do more than one thing at a time. An interrupt allows the program to be doing one thing and then when the right triggering event happens (say someone pushed a button, or a sensor has made a reading and is ready to hand it over, or you had set one of the PICs internal timers and it had “gone off”) quickly take care of something else and then get back to what it was doing. If you are making a machine that is controlling several hobby servos, a few motors via PWM, polling a number of sensors, and making some low-level decisions about how to behave given all those sensor readings it would be very difficult to write code that would do all this without using interrupts.

SIZE, COST, WEIGHT, SIMILAR CONSIDERATIONS

An additional advantage to using the 16F876A or (any small IC-style microcontroller) and building your own board around it is that you can control what you include and hence keep the circuit very small and light. If your project is large, there may be no reason (except cost) not to run the thing off a Mac mini or, a much better option if you are making a robot that is intended to move and perhaps be mobile, is the Qwerk since it has a lot of built-in capability for motor control, sensor-reading, and such. But if the kinds of things you are making are small, or gracile, or need to be light, or indeed need to be cheap (because you are a penny-pincher or because you are going to make a lot of something or are very likely to lose the thing you are making because you are sending it out to sea), you are best off building your own circuits around uC ICs.

The trade-off is that for each new project you must prepare a new circuit (either on a breadboard or on a pre-fab or custom PCB) that has all the components (the clock, some capacitors, some resistors…) the PIC needs to function.

The PIC 16F876A is available at Jameco for $7.35 and at Mouser for $7.39, less in quantity of course.

MORE INFO

More info on this chip and Microchips whole line of PIC microcontrollers can be found at

Posted 7 months, 4 weeks ago by ian

Tagged with: microchip pic review

Add a comment

Log in to post a comment. Not a member? Join now!