Selecting a microcontroller

I’m planning a project and need to select a microcontroller. This being my first experience with microcontrollers outside of FIRST, I’m relatively in the dark as to what exactly I need.

My project needs to control 6 devices drawing 20mA each. Due to my plans, each’ll have to be on a different I/O pin.

Can someone explain or help me find an appropriate microcontroller?

Features I’d like:
Cheap. I’m hoping to make a few of these projects up for teammates.

Low cost-of-entry. I don’t want to have to spend tons of money on software or cables and such.

Preferably programmed in C, C++, or BASIC. I could learn something else if I had to, but this would be easiest for me.

Preferably USB interface, not serial.

I use a Mac, so if whatever software I need for this is available for Mac, that’d be ideal. That said, I could pull out the old Windows box if I needed. OS X would be nice, but low priority.

Well, I’m a bit biased here because most of my chip-level work with uC’s has been with the PIC 16F series of chips, and for a couple bucks each (they’ll even ship you a couple demos for free if you ask nicely) the PIC16F627A would be a good place to start (yes, you can get more advanced PICs for about the same price… but I’ve worked with the 627A a lot, and it just springs to mind first.)

There is a free C compiler available, PICC Lite, although I don’t know if it will work on a Mac. PIC Basic Pro is also a very luxurious language for compiling to the PIC… it has all sorts of easy to use routines, but does cost a couple hundred dollars. The programmers can be whipped up on a breadboard if you want to use a PC parallel connection, but you can also buy them either assembled or as kits for less than $100. And I think you can even get a USB programmer for less than $100.

We’ve been using them for years with my engineering 11 students and while I found the 16F84A tended to be even more resistant to damage (one even kept working after a student put it in backwards, shorting it out so I burned my finger on it when I touched it!), the 16f627a has been pretty good, too, and is dirt cheap to boot. I don’t mind throwing one or two out when students toast them. (But don’t tell the student’s that, or they’ll stop believing my “be more careful” theatrics.) Besides, with the internal oscillator you don’t need a crystal, or anything other than a +5V and GND to get your chip up and running. It makes for very simple circuit boards! You will be stressing it a bit if you put all 20mA draws on the same port and turn them all on and leave them on for a long time, but it should be able to handle it… and if you are worried just put three on PortA and three on PortB.

An added benefit is that you should find lots of MPLab and PIC machine level expertise on this forum as PIC chips have powered the FRC control system since… well… since longer than I know of… and continue to run the VEX robotics platform.

Jason

Arduinos are fun. Not sure if it’s fit for your project, but it’s incredibly cheap for what it can do. I have a Boarduino myself

Well, if your into having usb connectivity and a nice selection of languges the microchip pic 18f2550/4550 series is pretty nice. They can run a USB bootloader, use minimal external components(a resonator and a couple of caps), and there are BASIC(picbasic/picbasic pro) and C(c18 student edition) compilers.

A good cheap programmer is the Pickit 2 from microchip, at around $35 its a steal for a high voltage programmer.

Now, if you have newer mac boxes, bootcamp might be your option because pretty much everything for pic development is windows only.

Well if you want something easy that you wont have to build alot of stuff just to get start doing things. I would suggest aPropeller chip. great chip cheep(20$for a proto board), powerful(8 cores), and the object exchange makes using this chip really easy because most things you would want to hook this thing up with has a class written for it.

I’m also a big fan of the PIC family, they are easy to use, there are 1000’s of example circuits, programming books, development systems, etc. Myke Predko has a number of good PIC books. If you are just starting out I’d suggest 123 PIC Microcontroller Experiments for the Evil Genius as a way to learn both the programming and electronic side. One of his books comes with a circuit board to give you a head start.

Parallax’s propeller is a good choice, as is their Basic Stamp chip family. Once again, like the PIC there are a number of good development systems to use.

Another program in Basic chip is the BasicX-24 microIt has a very good development tool. It’s PC based, so that may be an annoyance for you. Robodyssey sells a very nice support board (and the chip) along with a great programming and robotics book

My suggestion, if you are just going to do this one project, Basic Stamp. If you think you’ll do some minor robotics stuff with sensors and servos, then choose BasicX. Serious micro development, go with the PIC. Advanced programming, then the Propeller chip.

Good luck!
Foster

Thanks for the links everyone.

An arduino or basic stamp all seem like probably a bit overkill for what I’d like to do.

I want to drive 6 four-lead multi-color LEDs that each draw 20mA. They all have to be controlled independently of each other. So, I should have a total current draw of 120mA, yes?

Unfortunately, I’m not sure of how to tell whether a specific chip supports it. Those PICs are looking pretty nice and cost-effective, but I can’t determine which model I need.

Edit:
Apparently I missed checking out the spec-sheet on the Parallax Propeller last night.
According to the data sheet here it looks like (unless I’m reading it wrong) that the chip can put out 40mA per I/O and a total of 300mA?
Am I reading that right?

Did you look at any of the AVRs? AVR 32-bit MCU as a chip probably could do what you want, and I think that most of Atmel’s boards are available for integration with it.

Don’t base your chip choice on current-handling capacity. To switch an LED on or off, you can control a simple transistor (like a 2N3906, about a dime each, handles 100 mA easily) sinking just a few milliamps from the microcontroller.

If you want to control them linearly, that is, more than on or off but also ‘in-between’, then you can pulse them at varying duty cycles, or bias the 3906 for linear operation.

An analogy is controlling motors: we use Victors instead of the MC itself.

If it is a three-color LED (R, G, and 2xB is common), EACH of those needs 20 mA, or 80 mA per (internal) device. 6 x 80 = 480 mA.

Don

I originally suggested you try the 16f627A they can source/sink 200mA total with any one pin doing up to 25mA. The catch is it sounds like you are going to be hooking up 18 LEDs (six packages with three LEDs in each to achieve the multi-colour effect.) Although you can, with sufficient programming trickery using the PIC’s tri-state (high, low and high-impedance) I/O capacity, run many more than 18 LED’s off the PIC’s 18 outputs, and can use PWM to ensure that you don’t exceed the current capacity of the chip, that is hardly a fun way to start.

Now this means that you are going to be looking for a very specific set of characteristics. First of all, if you want to use the freeware PICC Lite compiler, you will be limited to the processors supported by that compiler. Secondly you will want at least 18 I/O pins. Thirdly, you would probably like to have the PIC able to handle a fair bit of current. 200mA is the maximum I have seen any PIC listed as handling, so that means that if you want to have all six “lights” go white (all 18 LED’s on at the same time) you will either run each LED at about 10mA, or will need to do as Don suggests and use some transistors or else an IC capable of boosing the power output a bit. Note that uC’s are not known for being a robust source of power, so being able to source/sink up to 200mA is pretty impressive for a little PIC chip.

I’m also assuming that you want to use a DIP package for “through hole” mounting, typical of a common home made circuit board or breadboard, rather than a surface-mount package.

The constraints of PICC lite are probably the most severe. Most of the chips supported by it are 18 pin chips with just 15 I/O lines… not quite enough unless you cut back to 5 tri-colour LED’s. However there are some larger PICs that it supports. One possibility is the 16f917. Note that this chip only handles 90mA source/sink across all ports, so some form of amplification will be needed. Another possibility is the 16f887 or 16f877a. Note that the 877a can handle 200mA, so the idea of running all 18 LEDs at 10mA without external amplification is possible on this chip… but it costs a bit more.

What I would suggest is picking a few PICs that might work out okay, then going to www.microchip.com and finding the “sample” button in the middle of the screen and asking them to send you a couple samples that you can try out.

And while you are at it, perhaps someone reading this thread who is familiar with a broader range of IC’s might be able to suggest a buffer or opto-isolator or similar chip that would be capable of driving 18 LED lines at 20mA each so that you wouldn’t need an individual transistor for each line.

Jason

You might want to look at Cypress Semi for their color LED controller solution. They have a demo board with a PSOC micro controller, LED driver, and 3 primary color high brightness LEDs. It’s 149$. May seam like allot but its a complete kit to experiment with generating a wide spectrum of color with LEDs. The Cypress PSOC micro controllers are different than PICs. Cypress has allot of app notes to get one up to speed on their form of micro controller. They have a neat programming environment called PSOC express. It’s graphic drag and drop programming. It includes a state machine builder that allows the coding of some very powerful algorithms. I recently bought one of their evaluation boards and really liked the Cypress system.
Here is a link
http://www.cypress.com/ez-color/index.jsp

Something I just realized that does change the number of I/Os needed as well as the current:

I only plan to drive two of the LEDs. I can achieve the effect I want entirely without using one of the colors.

Yet another PIC fan here (can you understand now why Microchip OWNS the microcontroller business even after all these years? :slight_smile: ), and I have been using PIC processors for three years now at my co-op with an awesome robot controller board we whipped up and had made at a PCB prototyping house. The board has a number of different shift registers allowing for hundreds of digital outputs along with a couple bytes of directly-linked pins for high speed digital IO, along with an ability to directly connect to some of the more interesting pins that come out of the micro (i.e. input captures, counters, etc.), some 8255’s for general purpose digital input, and a pair of RS-485 transciever pairs for communication to up and downstream devices on the production line.

The board is set up to use the 18F8722 as it’s microcontroller, same as is in the FRC controller. It’s a fantastic processor, lots of internal peripherals to keep you busy, just wish it had DMA sometimes. But, who can argue with a cheap processor that can handle communications AND run two step-driven axes at 12,500 steps/second with interpolation. :ahh:

This processor is availble on the HPC Explorer board from microchip as well, and can be used with the on-board bootloader it comes loaded with if you want to go that way, or you can get and ICD. I believe the PICkit2 programmer will program the 18F’s too. (just search microchip’s website with any of these names if you want more).

A new processor I’ve recently started working with is the 33F series of digital signal controllers. Awesome pieces of hardware, running at 80MIPS… very nice library of single-instruction math functions too (namely, fractional divide, square and accumulate), DMA capable, CAN compatible, some even have dual analog converters if I remember right. Just a few months ago I finished writing the low-level hardware driver for a 33F to run a 128x64 graphics LCD. My first project ever to have a TV to talk to the world with! :smiley:

Well, besides that huge LED segmented display on our robot this year… :rolleyes:

Hope that helps… post if you have questions.

-q

You know if one were to ignore the fact that it uses a Serial port the STK500 from Atmel is a far better choice than anything from Microchip. Also, the Arduino and an AVRISP would be a nice cheap development environment.

An arduino or basic stamp all seem like probably a bit overkill for what I’d like to do.

Why would an Arduino be overkill? It’s an Atmega168 which for all intents and purposes is equivalent to the PICs. It just has extra peripherals that you probably would end up adding in the end.

Something I just realized that does change the number of I/Os needed as well as the current:

I only plan to drive two of the LEDs. I can achieve the effect I want entirely without using one of the colors

You typically don’t want to drive LEDs directly off the IO port of a microcontroller. LED drivers are usually utilized which the microcontroller controls.

I can only hazard that it looks complicated.

I’d suggest the boarduino since it drops into a breadboard. That would make circuit testing / design easier.

Seconded. PSoCs rock, especially their capsense (capacitive sensor) models.

Don’t be put off by “graphical environment”. Basically the PSoC is a two part chip - 1 part microprocessor, 1 part reprogrammable hardware. The micro gets coded up in C. The rest gets coded up graphically.

What is this stuff he speaks of? Well, it is somewhere between pure FPGA and set hardware. Each chip gets some number of blocks that can be set up to do specific tasks. As an example, a digital block might be a serial port, SPI driver, I2C port, Timer/PWM/Counter, Random Number Generator, or a CRC checker. An analog block can be as simple as an A/D, or it can do some really cool switched capacitor analog filtering (way too much rock for just one hand!). Also, the capacitive sensing truely rocks - attach a bit of copper the size of your finger to a pin, and it is a button.

While not as flexible as a true gate array, you do get the benefit of doing some stuff in hardware.

Give them a shot!

That is true, but the PIC 16F627a (as well as a few other PICs) has the LED drivers built in to the uC. Each pin can drive up to 25mA with a total of 200mA off the entire chip.

Since this application would only require 12 lines, the 16f627a would be an ideal choice. Not only will Microchip send you a couple of freebies to experiment with, but they can be purchased for just $2.95 from digikey (dropping to $1.48 if you order 25 or more). They require NO external circuitry in order to run… just feed them something between about 2.5 and 5.5 volts and hook them up to ground and you’re good to go. Plug in your LEDs and resistors direct to the I/O pins and there is no simpler or cheaper way to build the circuit described here. (Well, at least that I know of…)

I’d even be willing to hazard a guess that the PIC could handle the 240mA required to drive each LED at 20mA… at least for a short period of time… if it were kept reasonably cool. I haven’t tried it… but if you fry a PIC, it’s not like it is a big problem. They are cheap enough to sacrifice a few.

The software can be created in machine code using MPLAB (free) or using PICC Lite (also free, and also using the MPLAB IDE). I can’t promise that it will run on a MAC, but I can bet you can find an old PC for free that will run it. If you have an old PC kicking around then you can also build the NOPPP, the “No Parts PIC Programmer”](http://www.covingtoninnovations.com/noppp/) or the Classic PIC Programmer or any number of other DIY designs that can be done on a breadboard and plugged in to a parallel port. My favourite is the TPIC, as it also serves as a prototype board as well as a programming board, but I’m not sure if they are still for sale. In any case, there is no shortage of commercial PIC programmers and kits for sale.

There are many other microcontrollers that could do the job, but there aren’t many that can do it as simply and inexpensively as the PIC… particularly if you plan on making more than one of this device. You will be spending more on the LED’s than the uC, I’ll bet!

Jason

That sounds perfect. Although I may have to do something about the overheating; I’m hoping to be able to integrate this into a piece of clothing or something.

And if I did manage to get it into clothing, I was hoping to produce several more.

Also, the reason I’d think an Arduino is overkill is that they cost $35 or so each, and have more than enough power to do what I want to do. $35 for the microcontroller alone, aside from adding another $12 for the LEDs and whatever the clothing article would possibly cost.

Either way, pic or ATmega (arduino), you will probably need a programmer or micocontroller with a bootloader on it. An Arduino is pretty much just a $4 ATmega168 with a bootloader on it paired up on a board with a powersupply and USB to serial chip. The nice thing about arduino is that the software runs great on a mac, and you can just buy that board or a cheap clone and it will work. No need for a programer, vmware, or mplab.

Have you seen the shirts on Thinkgeek? Possible inspiration there… there are a few other models besides the wi-fi detecting shirt.

You may also want to consider a surface mount package for a clothing application… all PICs are available in surface mount packaging. I will pass you on to others for tips on doing it as I’ve stuck to good old through-hole DIP stuff for everything I need to do, but I understand simple surface mount isn’t that hard if you have a good soldering iron and a steady hand.

I’d say the best way to see what a PIC can handle in regards to current draw (they might actually mean it when they say there is a 200mA limit… I haven’t driven more than about 10 LEDs at a time off a 627a so couldn’t tell you for sure) is to try it. If you can’t light up all the LEDs at once, you could always increase the value of your resistors to bring the current draw down a bit. The LEDs won’t be at peak brightness then, but should still be pretty darn close to it.

As a point of general interest, while I am sure this fits in to the “not exactly great practice” category and several people will happily explain why this won’t work, you can run several LEDs directly off a PIC running at 5v without any resistor between the LED and ground. It would be a conservative estimate to say that my students have done this on over 200 PIC 16f84, 16f84a, 16f627 and 16f627a chips without any problem. If you were to run your PIC on 3V (2xAAA batteries perhaps?), it may be possible for you to hook up all your LED leads directly to the PIC and back to ground without the need for any other components.

And if I’m wrong and you fry the PIC… you’re out two bucks. Give it a try!

That’s one thing I love about the PICs… not only are they tough little chips, but they are cheap, cheap, cheap!

Jason