Help Nuts and Volts make sense!
April 16, 2007 6:52 AM

How to get started PIC programming?

I'm interested in learning how to program little things using microchips... and it would appear that there are a ton of options out there.

Here's the thing -- I'm a beginner.

I know how to program (although assembly terrifies me), so I'm looking for something where I can write in basic or some similarly abstract language. I guess I need a kit or something -- something with a set of projects built in, so I can find my way without too much trouble.

My only technical requirement is that the programmer has to have a USB interface.

Any suggestions? Also, any suggestions for little projects I can build would be helpful...
posted by ph00dz to Technology (30 answers total) 13 users marked this as a favorite
I know there are multiple books out there on getting started in PIC programming. It's popular enough to be in the electronics section of a big bookstore - I've even seen them in half price books.

I'm actually starting to do some PIC stuff myself, so I've been looking around...

The Basic Stamp (www.parallax.com) is by FAR the easiest. It has a basic-like language, serial or USB programming, tons of peripherals and options. However, they're also pretty expensive, the bare bones older ones are around $40. Not bad for experimenting but I want to make a dozen units of the thing I'm designing and I'm aiming at a internals cost of more like $15 total...

I also have been looking through the neat projects at MicroCapps. They use a programmable pic and apparently they've built sort of an OS for it, and they program it, I think, in C. Maybe check that out.

If you find any nice online tutorials or starter guides, I'd love to hear about it.
posted by RustyBrooks at 7:20 AM on April 16, 2007


BASIC Stamp
posted by Rhomboid at 7:21 AM on April 16, 2007


PIC refers to a specific family of chips from Microchip Inc. Piclist is an excellent resource for all things PIC related.

You might also consider getting a kit from the Basic Stamp family, made by Parallax. They cater a little more to the education/hobbyist market.
posted by kc8nod at 7:22 AM on April 16, 2007


I'd highly suggest checking out Arduino. It's a free-as-in-speech hardware board with an integrated programmer and analog/digital io.

The programming environment is based on Processing and uses a stripped-down Java-like syntax; it's pretty easy to get started.

SparkFun sells the board starting around $35 for the USB version and going up to $140 for a Bluetooth version.
posted by jacobian at 7:22 AM on April 16, 2007


PS: I'd highly suggest staying away from the BASIC Stamp. It's proprietary platform that doesn't really integrate well with anything outside of its walled garden. You'll waste money, and you'll waste time when you realize the skills you learn on a stamp don't translate to real-world IC programming.
posted by jacobian at 7:24 AM on April 16, 2007


Although it's not PIC based*, I recommend checking out the open-source Ardunio project.

Coding for the Ardunio is done in C, and they've built some helpful libraries and an IDE to get you up and running quicking.

You can buy a USB board at Spark Fun.

Check the todbot blog for project ideas.

*The Ardunio is based on the Ateml Mega8 uP.

(On preview, what jacobian sorta said.)
posted by stungeye at 7:27 AM on April 16, 2007


You can program PICs in C using their MPLab IDE (free download from Microchip.com), so don't worry about that. The ICD2 puck will allow USB download of code -- look in to that and anything else you might need to program them... invest in a good development board (with LED outputs, motor outputs, etc, so you can see what your program actually does). Here is just one example. Google can help you find more.

Just go to the store, find a book that seems easiest to read, and follow it. Most good PIC books will recommend a specific model (for example, PIC16F877). At this point you don't need to worry too much about which model you choose; if you were to get in to detailed design of an electrical system, you might worry then.

Just make sure that you controller model matches the development board matches the book/tutorial you choose to follow. Once you have those basics down it'll be easy for you to experiment.

BASIC stamps are an option, and I've played with a Stamp-based BOEbot before that wasn't too bad, but they're pretty limited -- you say you know how to program, so you might find yourself frustrated with some of the PBASIC (is it still PBASIC?) limitations.
posted by olinerd at 7:27 AM on April 16, 2007


Oh, and yeah, because I'm not sure if you know the terminology, I think what you're interested in are microcontrollers. PICs are one example (and are probably the most widely used in both hobby and industry). BASIC Stamps are another. Atmel has some. TI has some (we use the MSP430 here at work).

Having the right terminology as you Google around for things well help you.
posted by olinerd at 7:47 AM on April 16, 2007


If you can, without terror, imagine writing in a fairly crippled flavor of BASIC where the variables can only hold one character/8-bit number at a time, the only variable you can do arithmetic or tests on is A, and the only variable you can use for array subscripts are X and Y, and GOTO targets can be any name you like instead of just line numbers, you're well on your way to learning 6502 assembler.

The 6502 hits a pretty nice sweet spot in the ease-of-learning vs. feature-rich spectrum. Grab yourself an Apple II emulator, run LISA 2.5 or Merlin on it and get stuck in.

Once you're confident with 6502, branching out to other architectures won't be anywhere near as scary.
posted by flabdablet at 8:15 AM on April 16, 2007


I've considered the BASIC Stamp, since that is roughly what I'm looking for, but yeah, Rusty, I'm a little concerned about the same thing. What if I want to make a bunch of whatever I'm making?

I guess I'd prefer an interpreted language over having to do into C and whatnot. Ardunio sounds very promising...

You folks have played with it? Does it live up to the hype?
posted by ph00dz at 8:23 AM on April 16, 2007


I got a Boe-bot from Parallax. It uses the Basic Stamp, and is designed as an entry-level PIC. It's fun to chase the cat with.

Also, if you want to make a bunch of the same thing, you test it on the board, and when you have your program tested (and saved on your ccomputer), you can buy more stamps and easily download them with the same program.

Nuts & Volts magazine has lots of projects articles on different PICs, including the Basic Stamp.
posted by MtDewd at 8:38 AM on April 16, 2007


If you're not sold on wanting to use PICs, but want to learn an 8-bit microcontroller, I highly recommend Atmel's AVR series. They're cheap, widely available, have lots of spiffy peripherals onboard (integrated oscillator, USARTs, I2C, several-channel PWM, some have integrated LCD controllers), and there's a free opensource toolchain for writing C software for them that runs on most major OSes. There's also a free assembly development environment that Atmel releases, AVR Studio. I started with an STK500 development board, but there are plenty of other, cheaper options for serial or parallel programmers.

I know this isn't strictly relavent, but I've found AVR stuff "friendlier" than PIC stuff so I figured I'd give that architecture a shoutout.
posted by Alterscape at 11:06 AM on April 16, 2007


thirding arduino, I've used it sucessfully to teach microcontroller programming in an academic setting. I used to use the basic stamp for the class and I'm very happy with the switch.
posted by puppy kuddles at 12:39 PM on April 16, 2007


FYI I picked up "123 PIC Microcontroller Experiments for the Evil Genius" today at half price books. Thanks for inspiring me to get off my ass! I'll probably use the 18F452 which go for about $10 on mouser.com


Also, if you want to make a bunch of the same thing, you test it on the board, and when you have your program tested (and saved on your ccomputer), you can buy more stamps and easily download them with the same program.


Right, but basic stamps are expensive ($40-50 instead of $10) so if I was going to make a lot of them, that would be a factor. I don't mind entertaining myself with a $50 toy, but if I wanted to "produce" these for sale, lower cost is better.
posted by RustyBrooks at 1:16 PM on April 16, 2007


If you get into programming PICs, you should consider mentoring a FIRST Robotics team.
posted by martinX's bellbottoms at 3:09 PM on April 16, 2007


Also, if you're going to use this project as a way in to assembler, the Atmel machine architecture is quite neat, regular and capable; the PIC architecture, on the other hand, will leave you sobbing and rocking in the corner. It's really quite squirrelly.
posted by flabdablet at 3:52 PM on April 16, 2007


I second/third/whatever something other than BASIC Stamp. I've used the 8051 which is simpler still than Atmel's AVR and I would recommend the book 'Programming and Customizing the 8051 Microcontroller'.
posted by southof40 at 4:30 PM on April 16, 2007


I would just go at the assembly language, there is nothing to be afraid of. PIC is common, which makes it a not terrible choice..

That said, I kind of like the idea that there are open source C compilers for Atmel - it seems like a serious bonus to me. PIC C compilers are mostly third party proprietary things, as far as I can tell, and that is a mess you just don't want to get into when it is completely unnecessary.

For me.. I have a bunch of PIC hardware already, and I don't have money, so the decision is pretty much made - unfortunately.
posted by Chuckles at 7:45 PM on April 16, 2007


Heh, I was reading through my book and I discovered that the basic stamp is actually based on a Microchips PIC.

Regarding assembly, because the type of things that you're likely to do on a PIC are somewhat less general purpose than a regular computer, assembly is probably OK. A lot of what you do in C on a PIC is explicitly set registers, lots of anding and oring or what not, and a lot of it is not that different, line by line, from assembly.

Where they differ is that it's just much easier to manage memory, data types, data structures, functions, etc, etc, in C, particularly if you don't already know assembly. I am conversant with 386 assembly and the old motorola 68k assembly and I'd rather program in C any day of the week. Just my 2 cents.

Now, someone find me a digital potentiometer than can be used with voltages higher than about 15V.
posted by RustyBrooks at 7:50 PM on April 16, 2007


The basic stamp module costs ~$50. The module is a straight plug in with interpreter chip, eeprom, resonator, power regulator, resistor pack, NPNs and PNP. It is so you can program through the module. For volume applications you can buy the interpreter chip $11, eeprom $5, and resonator $2.48 (with price discount in volume). Could definitely pick up the resonator wherever you get all other components for your circuit, plus probably the eeprom as well depending on the price vs from parallax. So really the comprable pricing for volume application would be pic vs interpreter chip and eeprom. All other components for the circuit would be used with either choice (not including programming board/circuit setup you'd need either way).
All that said I bought a BASIC STAMP which I still have not had time to messed with. In researching what to start with I found Parallax to be more user friendly with packaging of info and product. With that ease does come the trade off of limitations compared to a pic, as mentioned above. I made my choice knowing it would be a stepping stone.

Rusty what are you making?
posted by sailormouth at 8:22 PM on April 16, 2007


Every time I see a late80s/early90s stereo in the garbage, I pull the motorized POT out of it. A digital POT at 15V doesn't sound like that much to ask though..
posted by Chuckles at 8:22 PM on April 16, 2007


Not much to ask at all, actually - AD7376 +30 V/±15 V Operation 128-Position Digital Potentiometer (I'm thinking your problem is more complicated somehow, because that was too easy :P).
posted by Chuckles at 8:27 PM on April 16, 2007


I'm building a tube amp. Then yesterday I saw this amp which has the whole set of controls done with rotary encoders feeding into (I assume) digital potentiometers. The values of the "pots" are shown as LCD meter bars. So you can dial in the sound you like, and save it in a "patch" and recall it later. The patches/values are also controllable via midi, which is totally sweet, including all the toggle switches, like for preamp gain selectors, the triad/pentode switch, and even a switch to go between octal and el84 output tubes. Totally sweet. The voltages that the tone pots could see is pretty high though - even 30V might not cut it. I'll have to check some calculations. The preamp controls shouldn't be too much of a problem unless there's a volume pot between the preamp and power amp stages (there is on mine)

I hadn't considered motor driven pots. I guess that's a workable solution.

Mostly my problem is that although I have some experience with all digital designs (although most of that is hand done VLSI design, not exactly chips and wires) and all analog designs (amps, sound effects, etc) I know nothing at all about crossover devices like digital pots.

My other project du jour is like a digitally controlled patchbay. Imagine that you plug in your effects into all the in/out jacks on this thing, and then you say, OK, I want the signal to go to effect #1 first, then effect #7, then effect #5 then effect #4, skip all the others and go to the output. Just like what you'd do with all the patch cords on a regular patchbay. Such things exist and are hellishly expensive. I am working on a version using cmos switching, another sort of crossover between digital and analog.

Oh and I just looked at the AD7376... that looks like a 15V device to me - I guess I should have specified, more than +/- 15V. I don't even need 128 positions, I'd probably be OK with 16. Actually maybe I could use several of them in series. Say I needed a 500K pot, I could use 5 100Ks in series, each one could handle up to +/-15V so a total of 75V. I'd set each one to total volts/5 so that they all drop the same voltage. Hmm. It's worth trying.
posted by RustyBrooks at 9:20 PM on April 16, 2007


That all sounds really cool! I'm afraid I'm still infected by audiophile notions of purity when it comes to digital pots and switching applications like you describe, and etc., but I think I'm beginning to recover :P
For anyones confused about audiophile purity: Extra components in the signal path = unnecessary signal degradation = Evil! Fair enough, but it isn't very practical when you want to get something done..

5 stacked parts sounds kind of extreme.. What you really need is an amplifier stage, a FET connected as a voltage controlled resistor, voltage controlled attenuator, something like that.. I'm not exactly sure what it would look like, but it seems like something that has been done a few times.
posted by Chuckles at 10:26 PM on April 16, 2007


I found this: AN-582 Resolution Enhancements of Digital Potentiometers with Multiple Devices. It specifies the reasoning for putting these in series as a means of increasing the resolution, but obviously the voltage is going to be split between the devices.
posted by RustyBrooks at 10:26 PM on April 16, 2007


OK, I probably wouldn't use 5 of them. 2 or 4 maybe... there are multi-digipot chips that are designed for that, that let you address 2 or 4 of them as one unit, that even output the proper switching info to run into a multiplexor to select the output.

And yeah, I'm trying not to think at the moment about the non-linearity that these devices inevitably have. But I'm not doing it for audiophile purposes, either (I'm making guitar amps). I might try it on a solid state amp first, since they're considerably cheaper and easier to make.

There are lots of other applications... universal power supply for B+ voltage for tube amps, for example... I could have one power supply with multiple patches, one for this amp, one for that amp, etc. That might get kinda problematic since the resistors in power supplies have to dissipate a lot of wattage. Another example might be a self-adjusting bias. You could set the bias on your output stage where you wanted it to be, meter the actual bias current across a 1 ohm resistor, and then use a feedback loop to set the digital pot. If the current is too high or low, adjust and take another reading. You could do it every time you turned on, or every time you changed the tubes, or to a limited extent you could treat the bias current as just another input to save with your patches.

I have to admit that I often get carried away with adding choice to things that might not need it. My favorite amp to play on has One Freaking Knob. No tone controls, no preamp controls, no switches, just a volume knob.
posted by RustyBrooks at 10:32 PM on April 16, 2007


I know a lot of compressors and envelope followers use a LED/light dependant resistor as a voltage-controlled resistor. No idea what kind of fidelity you get with that. The FET is something I've thought of too, but I was reading about it recently and there is some problem with it that I can't think of at the moment.
posted by RustyBrooks at 10:35 PM on April 16, 2007


Oh, I remember now. The FET voltage controlled resistors top out at under 10Kohms.
posted by RustyBrooks at 10:47 PM on April 16, 2007


Well, the voltage will divide across the resistors, but you still have the power supply and digital logic lines to worry about.. You can work around that, but it could be messy (five independent power supplies and pulse transformers, or maybe just a string of resistors and AC coupling caps).

I know a lot of compressors and envelope followers use a LED/light dependant resistor as a voltage-controlled resistor.

Wow.

The FET voltage controlled resistors top out at under 10Kohms

That's interesting, something to do with linearity? A FET's off resistance is pretty high, so..
posted by Chuckles at 11:20 PM on April 16, 2007


The power lines wouldn't be a problem, you can use the same ones. There are actually one-chip solutions for 2 and 4 digital pots.

Yeah, the FETs are biased to Vdd/2 to improve linearity, so they're never off. Well, I guess if Vgs gets negative enough they would be, but you'd be well out of the linear range then I think. The range sucks too... you never get a nice low resistance, depending on the fet you might get 400-800 ohms or 1-2K or 5-10K etc.
posted by RustyBrooks at 7:17 AM on April 17, 2007


« Older Plant extracts and staying out of jail   |   Can I run 600ft of 100BaseT? Newer »
This thread is closed to new comments.