Kuro5hin.org: technology and culture, from the trenches
create account | help/FAQ | contact | links | search | IRC | site news
[ Everything | Diaries | Technology | Science | Culture | Politics | Media | News | Internet | Op-Ed | Fiction | Meta | MLP ]
We need your support: buy an ad | premium membership

[P]
Build a Simple Microcontroller Programmer

By jmzero in Technology
Tue Apr 15, 2003 at 04:11:21 PM EST
Tags: Technology (all tags)
Technology

I'm fairly new to hobby electronics, and I'm also pretty dumb. I was also able to build a simple programmer for AVR series microcontrollers over the weekend. Whether you've got a fancy robotics project in mind or whether you just want to have some blinking lights on your desktop, this is a project you can do (even if it's your first project) and have fun doing - and all for around $10 US.


All of the information I'll present here could be found by a quick search on Google, and at every step you've got lots of choices. The following is just the quickest route I found to get to the equivalent of "Hello World".

Our first step, naturally, is to build the programming device. Here's what we'll need:

  1. The microcontroller to program. We'll use an Atmel AT90S2313 ($3)
  2. 10x 100 ohm resistors (stripes will be brown, black, brown, then gold) ($1)
  3. 10x 27 picofarad capacitors ($1)
  4. 2x 47 microfarad capacitor ($1)
  5. 2x 4MHz crystal ($1)
  6. Any old 25 pin (parallel port) printer cable that we can wreck ($?!)
  7. A computer with a parallel port running DOS, Windows or Linux. I can't see how we could wreck this, but I naturally can't accept responsibility if you do.
It will also make things much easier if we have:
  1. A hobbyist breadboard kit with little prebent jumper wires ($15)
  2. Some electrical tape ($3)
  3. A cheap Radio Shack multimeter ($20)
  4. A wire stripper ($5)
To test the little thing, we'll also need:
  1. Some little LEDs to blink ($1)
  2. A regular nine volt battery, and if possible a pad that snaps on to a nine volt battery and has some wires hanging off so we can connect easily to our breadboard

If you have an electronics store nearby (like Arrow for instance), they probably have all this stuff in stock. If not, you can order from Digi-Key or Arrow or lots of other places.

The device we'll be building is called an SP12. Steve Bolt, the nice man who came up with this (and wrote the software we'll use on the PC side) has a page for it - "programming a spider's brain". The thing we'll be building is the first picture on the page. Ignore the talk about dongles and enhancements and software - worry about that later. If you can follow his diagram, then do so (experienced people can also find a pinout/summary for the chip at Atmel's website - summary doc). If these things don't help you, that's OK. Do the following:
  1. Have a look at this picture. This is what mine looks like. Makes you feel more confident that yours will work, doesn't it?
  2. Cut off the printer end of your printer cable, and cut the rubbery outer stuff back a couple inches.
  3. Identify wires connected to pins 2-9, 11, and 25. There's a good chance your wires are colored and follow this scheme. If not, you'll have to find the right wires with your multimeter/brain.
  4. Connect wire 25 to a 100 ohm resistor. Connect the resistor to the bottom row of your breadboard (this is ground).
  5. Twist/tie wires 4-8 together and tie them to one end of a little jumper wire. Stab this in the top row of your breadboard (this is Vcc, your main input voltage)
  6. Press your little microcontroller into the breadboard so it straddles the little channel in the middle of your breadboard. Make sure all the pins are lined up in holes so that they don't bend back. The little divot on the top of the chip should be on the left side, and the chip should be more or less centered left to right.
  7. Connect the pin 9 wire (of your printer cable) to the 4th pin from the left on the top side of your chip. I did this by tying a green jumper wire (from the breadboard kit) to the wire, then stabbing the jumper wire into the breadboard.
  8. Connect wire 11 to the 3rd pin from left on top side of chip
  9. Connect wire 2 to the 2nd pin from left on top side of chip
  10. Connect wire 3 to the first pin on the bottom side of chip (see picture in step 1 for ideas on how to make this reach).
  11. Connect pin 1 on top side of chip to the top row of your breadboard (Vcc)
  12. Connect the long leg of your 47 microfarad capacitor to the top row. Connect the short leg (which should also have a white stripe beside it) to the bottom row. Again, see picture for ideas on how to make this reach.
  13. Connect the rightmost pin on the bottom side of the chip to ground (the bottom row)
  14. Using a 100 ohm resistor, connect the second pin from left on the top of the chip to some open space on your breadboard. Connect this open space to ground (the bottom row) with one of your 27 picofarad capacitors. For resistors and the little non-cylinder looking (non-electrolytic) capacitors, it doesn't matter which end is which.
  15. Connect the 4th and 5th pins on the bottom of the chip to ground with two more 27 picofarad capacitors. Connect these same two pins together with your 4MHz crystal (the two legs of the crystal are the same).
  16. Your thing should look something like the picture in step 1, unless you're more competent than I am.
Wow. You're done. If you've followed my directions, it should look awful. If you skipped my directions, you probably have a nice looking etched circuit board with a ZIF socket for the processor.

Anywho, before we connect this bad boy to our computer, let's get the software for the PC. It's available at the same SP12 homepage - "programming a spider's brain". If you are using Windows NT/2000/XP, I recommend downloading the DOS version anyways. His NT version uses GiveIO as a driver to access the parallel port, which is kind of hokey (but will work too, and it doesn't much matter). I prefer using UserPort, which simply opens up access to the parallel port for anybody. Once UserPort is installed, the DOS version runs fine - otherwise NT/2000/XP blocks access to the port.

Install the software as normal. In the directory you installed it in, put a copy of this test rom file - it will be our test program. Don't plug your device into the computer yet!

Go to your command line, and get back to this directory. Run:

sp12 -i

This should come back with an error saying you have no device connected, and at this point you shouldn't have a device connected. It will also clear the parallel port data pins so that we can safely plug in our device. PLUG IN THE DEVICE! Now run:

sp12 -i

If everything is right, the program will tell you that it has located an AT90S2313. Hoorah for us! If this worked, you should do a timing run to get things calibrated:

sp12 -t

This should take 10 or so seconds. If it doesn't come back with any errors, then we're ready to program:

sp12 -wpf cfirst.rom

This might take a couple seconds. If it works OK, then the program has been stored in our chip. These little chips store programs on flash, so you can flash your chip pretty much as many times as you'd like. You can now unplug the device from your computer. To see what the program does, we'll have to make a little test circuit:

  1. You're building this.
  2. The chip takes 4-6 volts to run. I used a nine volt battery - the red wire (or smaller knob on top) is at 9 volts. In order to halve the voltage, I connected 2 resistors (100 ohm, again) in series from positive to ground (from battery positive to bottom row). I ran a wire from the place where these two resistors connect to the top row on my breadboard to act as my main voltage. This isn't a great way of doing this, but it should work for a quick test (see picture).
  3. Connect pins 4 and 5 with your 4 MHz crystal (just as you did in the programmer circuit) - this works with the chip's clock. You also need to connect pins 4 and 5 to ground with 27 picofarad capacitors for the little clock circuit to work.
  4. Pins 2-9 from the left on the top of your chip are "data port B". The program you've put on the chip simply counts up in binary (starting at 159) and outputs this number to these pins (pin 2 is the most significant bit, and it goes down from there). Connect as many of them as you'd like to LED's, and connect the LED's to ground. The short legs of the LED's are the ones that you connect to ground.
  5. Connect the halved voltage (which should be your top row) to the first pin on the top left of your chip. Connect the black wire from the battery (the bigger knob on top) to ground. When you're ready to run, connect the bottom right pin on the chip to ground.
  6. I have a little push button switch on my test circuit shown. It's handy, but you can also simply pull out a power/ground wire to start/stop the chip. It will reset every time it loses power.
Hopefully that all worked. Next step? Programming your own software. The spiders brain web site will point you in some good directions. The Atmel website has no-charge software called AVR Studio that will let you program in Assembly and do simulated debugging runs (but you'll still have to use the SP12 software to actually program the device with the roms generated). AVRFreaks has tons of good information on using these wonderful little devices.

My own favorite programming setup (and what I used to make CFirst.rom) is GCC. The easiest way to get started with AVR GCC is to install WinAVR. It comes with tons of junk you don't strictly need, but it's handy to have all the tools together in compatible versions (and it's dead easy to install). You can get the source for CFirst, along with a handy compile batch file (especially useful if you're scared of "make") here - source.zip.

There are quite a few microcontrollers in the AVR/megaAVR series - most of which will work with this programmer. Even this little AT90S2313 has a lot of features - a built in UART (to talk to a serial port, an LCD, or lots of other devices), lots of I/O pins to hook up to switches and such, and static memory. It could be the center of a simple robot. It could work in a control pad for something. An alarm system. A voice recorder. A remote control. A toy. A game. A way to hook fancy controls up to your computer. Endless possibilities. Right now, I'm building a space flight simulator - these little controllers will help me make displays and guages, and will allow me to hook up lots of switches, throttles, and levers up to the central PC.

Good luck, and happy programming!

Sponsors

Voxel dot net
o Managed Hosting
o VoxCAST Content Delivery
o Raw Infrastructure

Login

Poll
What are you going to do with your microcontroller?
o Blinking lights! 25%
o Build a robot 15%
o Hardware control, or part of more complicated setup 24%
o Miscellaneous/other tinkering 12%
o Nothing, but project will be fun 7%
o I'm not interested 14%

Votes: 85
Results | Other Polls

Related Links
o Google
o Digi-Key
o Arrow
o "programmi ng a spider's brain"
o summary doc
o this picture
o this scheme
o "programmi ng a spider's brain" [2]
o UserPort
o test rom file
o this
o Atmel
o AVRFreaks
o WinAVR
o source.zip
o Also by jmzero


Display: Sort:
Build a Simple Microcontroller Programmer | 74 comments (52 topical, 22 editorial, 0 hidden)
Blinkenlights,not Blinking lights in poll (5.00 / 2) (#17)
by Hana Yori Dango on Tue Apr 15, 2003 at 02:30:29 PM EST

wait, it's out of the queue?! Somebody call an editor quick, we can't let this slide!

+1 Section



Blinkenlights, (none / 0) (#23)
by jt on Tue Apr 15, 2003 at 03:29:43 PM EST

Spitzensparken!

[ Parent ]
Sweet! (none / 0) (#25)
by porkchop_d_clown on Tue Apr 15, 2003 at 03:54:13 PM EST

I like it; I've been looking for a "cool" project I could do on the cheap with my son.


--
Tablet is the wrong medicinal analogy: suppository more adequately describes the Smart Display experience. - Rupert Goodwins


AVR cards (5.00 / 1) (#26)
by the77x42 on Tue Apr 15, 2003 at 03:59:31 PM EST

Are good for satellite hacking as well.

http://www.dishtoys.com/


"We're not here to educate. We're here to point and laugh." - creature
"You have some pretty stupid ideas." - indubitable ‮

Note about satellite AVR cards. (none / 0) (#29)
by metalfan on Tue Apr 15, 2003 at 08:06:45 PM EST

The interference these little buggers create cause MAJOR problems.

They interfere with everything from VHF radios to Emergency Position Indicating Radio Beacon's (the ones on boats) to Emergency Locator Transmitters (the ones on airplanes) to the search and rescue satellites. AVR cards can even drown out ELT's in some areas.

Please think about whose lives you are putting at risk next time you watch your fifty channels in three languages of free porn.

[ Parent ]
No (none / 0) (#38)
by the77x42 on Tue Apr 15, 2003 at 11:39:33 PM EST

They don't interfere, they do emit a signal on 120hz which is the same as the ELT, but it's for a VERY small (less than one block) radius. And this is also only if you are using the old style AVR cards.


"We're not here to educate. We're here to point and laugh." - creature
"You have some pretty stupid ideas." - indubitable ‮

[ Parent ]
You are wrong (none / 0) (#39)
by metalfan on Wed Apr 16, 2003 at 12:09:27 AM EST

I work for the Canadian government agency that deals with interference complaints. I personally assisted with one interference investigation regarding these cards. They were causing relatively major interference to the one of the police VHF radio channels. There are MANY other cases, and I can assure you these cards are very obvious when you drive by with a receiver tuned to the appropriate frequency.

Furthermore, ELT's transmit on 121.5MHz and 243MHz, not 120Hz. AVR cards have been causing problems with the search and rescue satellites, especially in major centres where the large numbers of them can drown out an ELT.

[ Parent ]
whatever (none / 0) (#40)
by the77x42 on Wed Apr 16, 2003 at 04:36:12 AM EST

as much as i'd love to continue an argument over the internet, you just be concerned with satellite hacking killing people, and i'll just watch my free porn. deal? good.


"We're not here to educate. We're here to point and laugh." - creature
"You have some pretty stupid ideas." - indubitable ‮

[ Parent ]
Sure (none / 0) (#45)
by metalfan on Wed Apr 16, 2003 at 10:43:14 AM EST

But don't expect me to come looking for you or any of your relatives when the plane crashes. Also don't expect any sympathy when you are fined for causing harmful interference (which is illegal in most places).

[ Parent ]
atmel part (none / 0) (#52)
by bgr on Wed Apr 16, 2003 at 03:43:34 PM EST

Are you referring to the RF oscillator in the atmel part?

[ Parent ]
Huh? (none / 0) (#58)
by metalfan on Wed Apr 16, 2003 at 08:34:29 PM EST

I'm not sure which RF oscillator you're referring to. I don't know a lot about these cards and controllers, but I do know that they radiate enough to cause interference and that the interference they create does cause problems.

See here (Google cached version) and here (Google cached version).

[ Parent ]
they may be misleading you (none / 0) (#60)
by bgr on Thu Apr 17, 2003 at 10:25:52 AM EST

I should have said RC oscillator which emits RF. We use a very similar atmega part in some of our products, and they have all passed FCC for home electronics. The fact that they passed without having to add extra shielding for the part (which we usually have to do for network interfaces or video outputs) tells you a little about how much noise they are emitting. There is no reason that such a device would interfere at all with satellite transmissions. Even using one of atmel's parts specifically designed for RF you wouldn't ever interfere with even a long wave frequency like VHF. I've had a chance to play with some of atmel's TEMIC parts which operate at a lower frequency (~ 120KHz). Very neat little parts. But I can't get communication over 30cm. And you're saying a part designed _not to bleed_ is causing more problems? They're most likely just blowing smoke up your ass.

[ Parent ]
Oh really? (none / 0) (#66)
by metalfan on Thu Apr 17, 2003 at 09:17:51 PM EST

I didn't say they were interfering with satellite communications (well, not directly). I said they emit a signal on the VHF radio frequencies that the police use, and/or on the ELT frequency. The SAR satellite(satellites? not sure how many there are) can see 121.5MHz and think that there's an ELT on.

When these cards are on, there is interference. It's over more than 30cm too. Like I said, it's easily detectable when driving by the house. When these cards are removed/turned off, the interference goes away.

Where would you suggest it's coming from?

[ Parent ]
what magic is this? (none / 0) (#70)
by bgr on Mon Apr 21, 2003 at 10:03:30 AM EST

From what I have seen of these "AVR cards" They are merely a atmega mcu, a handfull of resistors, maybe a serial line buffer to drop the voltage, and a thin hunk of plastic with a smartcard wafer attached. Exactly which part or combination of parts in this is creating this interference? Oh, I forgot the DB25 connector. Maybe that's it ;) If you notice the United States has not passed any legislation regulating these devices, and from what you are saying, they would tend to cause a significant burden here as planes fall from the sky, and hikers are lost forever in the wilderness of places like manhattan. Perhaps Canada is just trying to make citizens who are stealing satellite paranoid about john law driving around their neighboorhoods. I really don't want to build an AVR and take it for FCC testing to prove a point here. But if you want to cover the $10,000 cost I'll be happy to do so, and we'll be able to settle this ridiculous issue once and for all.

[ Parent ]
As far as I know... (none / 0) (#74)
by metalfan on Tue Oct 28, 2003 at 04:43:26 PM EST

The issue is not with the cards themselves.  The issue is that all of these homebrew cards leave the little trapdoor on the satellite receiver open, so an IF or some other such thing radiates from the receiver when it wouldn't normally.

And FYI, "John Law" does drive around neighbourhoods looking for these things.  I know, I was sitting in the passenger seat.

Like I've said before, the use of these cards causes interference with police VHF radios, and also causes false alarms on SARSAT.

[ Parent ]

Say what? (none / 0) (#50)
by tjw on Wed Apr 16, 2003 at 02:25:00 PM EST

Are you sure you're talking about the same thing linked to in that post?

It looks to me like they are simply a smart card emulator . I see no RF-transmitting function.



[ Parent ]
Yes. (none / 0) (#56)
by metalfan on Wed Apr 16, 2003 at 08:12:18 PM EST

I'm talking about the cards based on Atmel micros that you can plug into your satellite TV receiver and get all the channels for free.

You're right, they aren't supposed to transmit RF, but they do.

[ Parent ]
AVRs are great (none / 0) (#27)
by Idioteque on Tue Apr 15, 2003 at 05:32:05 PM EST

I've done a lot of programming on AVRs for work and they definetly make a good hobby micro too, as can be seen by all from all the participants on the AVRFreaks website. It's great for playing around in both C and assembly. Learning assembly on a little RISC processor like this is a great way to start.


I have seen too much; I haven't seen enough - Radiohead
thank you (5.00 / 2) (#28)
by Abominable Abitur on Tue Apr 15, 2003 at 06:08:37 PM EST

i've been looking for something to get my feet wet in electronics and robotics. planning on doing a couple of kit robots first then one from scratch. this should help immensely.

"Terrorism is only a viable "political activist" method for marginalized nutjobs, bottom line. The backlash that it causes makes it intractable for any reasonable ideology. Which is why you don't generally see wild athiest suicide bombers in america's streets." - lonelyhobo
Me too. (none / 0) (#31)
by Akshay on Tue Apr 15, 2003 at 09:20:39 PM EST

Wanted to get my hands dirty in something physical one day. This should help me get started.

The irony, of course, I'm greatly inspired by both the article and the parent's sig. Yessir, lazy can be fixed!

[ Parent ]

getting started (5.00 / 1) (#35)
by polyglot on Tue Apr 15, 2003 at 10:19:25 PM EST

Get yourself the AVR studio from Atmel: this includes all the documentation for the chips, the assembler and (most importantly) a SIMULATOR (the microchip MPLAB has a simulator too).

This allows you to write some code and assure yourself that it will, in fact, work when you put it onto silicon - much easier than debugging blind, which can be very disenchanting for the beginner.

To run your program on real silicon, you need the following at a minimum:

  • AVR Studio
  • Datasheet
  • A programmer and the matching software (see article or google)
  • A chip; I recommend the 90S2313 as a starting point. The 90S1200 lacks the SRAM (so you can't use C or Basic on it), but is good enough for very simple programs.
  • Some experimenter's hardware:
    • Breaboard
    • Jumpers for breadboard (I used CAT5-solid conductors)
    • crystal (3.2768MHz for time-based apps; 8 or 10MHz for general-purpose stuff) and matching (27pF or 33pF) ceramic capacitors
    • Power supply: best option here is a 5V regulated plugpack of the switchmode variety. 500mA will suffice unless you have power-hungry peripherals (you won't for a while yet). You also need decoupling capacitors (between the power rails, as close as possible to the micro), I suggest a pair of 100nF monolythics.
    • I/O. A micro that does nothing is boring and pointless. I suggest a handful of LEDs of various colours (with a 330 ohm current-limit resistor for each) and some switches (pull-down resistor to ground, switch to positive rail).
    • More funky I/O. LCDs are cool and extremely easy to communicate with; just make sure you get one based on an Hitachi HD44780 or equivalent. Keypads are also pretty cool - get the 4x4 matrix type and learn to scan it.
    • Even more funky I/O. Stepper motors. Serial communications. IR receivers for remote controls. Serial EEPROM. Accelerometers. Temperature Sensors. Chunky MOSFETs and PM DC brushless motors. Opto-coupled TRIACs.
    • Time in a psych ward to clean up your micro addiction :)

--
"There is no God and Dirac is his prophet"
     -- Wolfgang Pauli
‮־
[ Parent ]
Kit robots (none / 0) (#32)
by Danse on Tue Apr 15, 2003 at 09:22:10 PM EST

Does anyone know where a complete n00b could get ahold of a fairly simple robot kit? What options are out there. Last time I looked around I didn't find anything that looked like it was simple enough or came with good enough instructions. Even beginner electronics projects would be neat, preferably some that would explain what the various parts actually do.






An honest debate between Bush and Kerry
[ Parent ]
Robot Bulding for Beginners by David Cook (5.00 / 1) (#47)
by camel bawlz on Wed Apr 16, 2003 at 12:14:06 PM EST

This book has been very good so far, I'm having no trouble putting things together, and I completely clueless with electronics. I still have to collect all the parts but I'm on my way to having a line-following robot.

[GO TO HJELL!] They may be little bitches to kill, but I could spend hours lusting after their dead bodies - Parent ]

site (5.00 / 1) (#57)
by Abominable Abitur on Wed Apr 16, 2003 at 08:26:51 PM EST

www.robotbooks.com -->>kits, books, etc. LINK

"Terrorism is only a viable "political activist" method for marginalized nutjobs, bottom line. The backlash that it causes makes it intractable for any reasonable ideology. Which is why you don't generally see wild athiest suicide bombers in america's streets." - lonelyhobo
[ Parent ]
First Rule (5.00 / 1) (#49)
by a humble lich on Wed Apr 16, 2003 at 12:55:37 PM EST

It is would be a bad idea to do electronics with your feet wet. That sounds like a good way to eletrocute yourself.

[ Parent ]
Comparisons (5.00 / 1) (#30)
by metalfan on Tue Apr 15, 2003 at 08:08:34 PM EST

Does anybody have enough experience to provide a reasonably detailed comparison to other popular micros, for instance the PICmicro from Microchip?

PIC vs AVR (5.00 / 1) (#33)
by polyglot on Tue Apr 15, 2003 at 09:49:00 PM EST

I think I can answer this, having written a few k of each of PIC and AVR assembler.

The smaller (eg 16F84) PICs are really easy to buy (at least in .au - even Dick Smith sells them), but they're not cheap (eg AUD10 for an F84), are slow (4 clocks/instruction, typically 4MHz clock for the available ones). However, they are a dream to program: the instruction set and architecture is beautiful and extremely easy to learn. Very few instructions, nice orthogonality and very few gotchas.

The AVR (I've used 90S2313 and 4433) is quite the opposite of this: they have a massive and difficult-to-learn instruction set with lots of overlapping functionality, exceptions-to-rules, etc, BUT (and this I why I now use AVRs instead of PICs) the silicon you get for your dollar is way more powerful. A 90S2313 (AUD6) runs at 10MHz (at 1 clock/instruction), has loads of SRAM and registers, two timer-counters including a 16-bit one with capture/compare and a UART.

So: you get a slightly steeper learning curve on the AVRs if programming them in assembler, but you get a much beefier micro. Both architectures have high level language (C, Basic) compilers; the PIC one (PICC) is not free, while the AVR one is gcc :)

Bascom produces an AVR basic for those wishing to suffer brain-damage (but it does emit native AVR code AFAIK), and Parallax builds a thing called the Basic Stamp which is a PIC on a small PCB. I personally don't like stamps: they keep their basic programs in external EEPROM (lots of room) and interpret it. This is extremely slow and very different from directly programming the micro.

Both companies produce most of their variants in a flash form (simply reprogrammable without UV), so go for these if you are experimenting.

If you're just starting out, I recommend you look at both architectures in detail (ie download the big, free datasheets) and see which is for you. You'll probably get simple stuff happening more easily on the PIC, but should find more advanced stuff (funky timing, distance comms, etc) easier on the AVR; assuming you're using the low-end cheap devices (16F84, 90S2313).

You can build programmers for either architecture for next to nothing (and kits are available for about AUD30), so don't sweat that part of it. A quick google will find you loads of these things.

Some quick links for ya:
PIC Flash Micros
AVR Micros
AVR Tools for Linux, including avr-gcc
Dontronics

Dontronics stocks loads of micro-related stuff, including a thing called the SIMMstick, which is a system for programming AVRs and building AVR systems; I've not used it because its a bit expensive, but it does look very cool.

And lastly, a plug for some of my PIC code: The Time Machine is a project I built which is like cron in a micro (but not as powerful): 8 channels, 10 minute res., weekly period, 5 programs per channel. Its released under the GPL and includes PIC source, schematic, double-sided PCB layout, instructions, photos, etc. The file is 8MB, so please download it only if you're interested in PIC code or want the garden-timer-from-hell (more functionality than those $200 units at the hardware store).

Happy hacking!
--
"There is no God and Dirac is his prophet"
     -- Wolfgang Pauli
‮־
[ Parent ]

Apples to Apples (none / 0) (#42)
by BenJackson on Wed Apr 16, 2003 at 06:15:15 AM EST

The 16F84 has been used in many projects because it's an older chip.  For a pin-compatible (and nearly code compatible, except for initialization) modern version, the 16F628 runs at up to 20MHz, has 3 timers and a watchdog timer, dual comparators, PWM, and a builtin USART.  And it's cheaper!  In unit quantities from Digikey, only $3-4 vs $5-6 for a 16F84A.

Their top of the line products can run faster (40Mhz), have additional useful instructions (eg multiply), have 5-6 timers, up to 16 A/D channels and many combinations of builtin interfaces including USART, MIIC, SPI, CAN and even USB.

A good starter chip these days would be the 18F452.  From Digikey in 1-unit quantities it's $9.38.  It really doesn't matter that it costs that much because you develop on the big one (eg the 16F877 in the 16F line) but you build your blinky light toy with the smallest thing that has enough IO lines (eg 16F628, 12F629).

[ Parent ]

16f877 is what I'm using (none / 0) (#43)
by Gully Foyle on Wed Apr 16, 2003 at 06:57:33 AM EST

20mhz, 16k Ram, 8 10 bit a/d converters, and it's available with an in-circuit emulator (with asm level debugger) for very little cash.


If you weren't picked on in school you were doing something wrong - kableh
[ Parent ]

PIC vs AVR (5.00 / 1) (#46)
by MadShark on Wed Apr 16, 2003 at 12:12:19 PM EST

I've worked with both PICs and AVR's, in school, work and for some hobby projects. Both types of micro are easy to set up and get running. I've used both assembly and C on both micros. If you are writing in assembly, the PIC is a little easier. If you are writing in C, the AVR using the avr-gcc compilier is hands-down the winner.

Because of the architecture of the PIC micro, they are not well suited to higher level languages such as C. We had one project at work that we cross compile for 6 different embedded micros. The resulting code size for the PIC was 40% larger than the largest of the other micros. We've noticed that this is a consistant trend with PICs. We've attempted to use a couple of different compilers for the PIC architecture. They were all relatively expensive and in my opinion, poor quality. One of the compilers we recently tried had 7 code generation bugs we found in the first month of use(and yes they were real compiler bugs, confirmed by the compiler vendor).

My personal choice is to use the AVR micros for my hobby projects. The avr-gcc compiler is free and works great. The AVR line has a range of micros suitable to a variety of projects.

Jason

[ Parent ]

What size breadboard? (5.00 / 1) (#34)
by StormShadow on Tue Apr 15, 2003 at 09:53:09 PM EST

I am looking to get involved in electronics as a hobby and I am wondering what size of a breadboard I should get? I've looked at a few sites and there seems to be all sorts with varying complexity. Anyone have recommendations for someone who'd be new to the hobby? I don't want to spend too much in the beginning.


-----------------
oderint dum metuant - Cicero
We aren't killing enough of our [America's] enemies. Re-elect Bush in 2004 - Me
12/2003: This account is now closed. Password scrambled. Its been a pleasure.


breadboard sizes (5.00 / 1) (#36)
by polyglot on Tue Apr 15, 2003 at 10:38:03 PM EST

This Size is enough for most micro stuff. They generally have keyways down the sides so you can buy multiple modules and click them together when you need more room.


--
"There is no God and Dirac is his prophet"
     -- Wolfgang Pauli
‮־
[ Parent ]

What items should I get as a beginner? (none / 0) (#53)
by StormShadow on Wed Apr 16, 2003 at 06:31:55 PM EST

Ok, I found this site that seems to be an excellent place for me to order stuff from. But I do not know what I should order as a beginner. Obvious a breadboard and a breadboard wiring kit but what else?


-----------------
oderint dum metuant - Cicero
We aren't killing enough of our [America's] enemies. Re-elect Bush in 2004 - Me
12/2003: This account is now closed. Password scrambled. Its been a pleasure.


[ Parent ]
Hmmm (5.00 / 1) (#54)
by jmzero on Wed Apr 16, 2003 at 06:45:48 PM EST

Radio Shack used to sell nice "variety packs" of resistors and capacitors.  Those are likely hard to find now.  

As such, you're probably best to just buy parts as you need them for a specific project.  Once you've tinkered around a bit, you'll probably have a good idea what you'll need.  

I'd also recommend getting a cheap multimeter - a $20 Radio Shack model should be fine. This one actually works pretty good.
.
"Let's not stir that bag of worms." - my lovely wife
[ Parent ]

I lied... (5.00 / 1) (#55)
by jmzero on Wed Apr 16, 2003 at 06:52:12 PM EST

Apparently Radio Shack still sells variety packs - Handy! - similar deals on capacitors, and probably on switches and LED's.  

.
"Let's not stir that bag of worms." - my lovely wife
[ Parent ]
I really like the Atmel chips... (4.50 / 2) (#37)
by John Miles on Tue Apr 15, 2003 at 11:39:16 PM EST

The more powerful ones, like the 16 MHz AtMEGA128, are more than capable of running C++ code at a decent clip. (Well, the brand of lightweight C++ code I tend to write, anyway).

I recently spent some time messing with AVR-GCC, and came away impressed at how well the 8-bit AtMEGA128 handled 32-bit C++ code. For my first project, I ported a software modem for the 3,600-bps Motorola trunked-radio control data format that was originally written for MSVC under Win32, and it took only a day or so to get running.

It's relatively easy to write code under AVR-GCC that will compile on either Win32 or the AVR. When developing an RF synthesizer control program, I used the PC parallel port to get the prototype up and running, then recompiled the same code for the AtMEGA128 and called it a day.

I'm an old-school 6502 hacker, but that was then and this is now. When I started to get into microcontrollers last year, I had absolutely no interest in learning yet another assembly language. Their high degree of compatibility with 32-bit C++ code won me over to the Atmel camp big-time. There appears to be no reason at all to even think about the underlying instruction set, which in my book is a Good Thing.

For so long as men do as they are told, there will be war.

A follow-up (none / 0) (#67)
by John Miles on Fri Apr 18, 2003 at 02:56:34 PM EST

Someone wrote me asking about the pros and cons of the AtMEGA128 versus the AT90S2313 that jmzero was talking about. I haven't used the 90S2313, but it can be thought of as a very low-end part that's almost, but not quite, downwardly-compatible with the '128 (which is currently Atmel's highest-end AVR part).

The MEGA parts have a different pinout compared to the lower-end parts, because they have (many) more features. There are also a few subtle programming differences, but nothing that's not reasonably well-documented in the data book. It is generally not going to be too hard to adapt a circuit for a lower-end AVR to an AtMEGA128 once you're familiar with the parts.

The drawbacks to the '128 are cost (a few bucks more than the slower/less capable parts) and the fact that you can't get it in a DIP package, so prototyping with it can be a challenge. I use these to help with that problem, but they're even more expensive than the chip! If you're comfortable making your own PC boards this obviously isn't a problem, but I've never gotten into that.

You could also go with a more full-featured development board like this one. I used their schematic as a handy guide for hooking everything up on my own projects.

The AtMEGA163 and -323 parts are decent alternatives if you don't need the full 16 MHz speed and all the I/O features of the -128, and they do come in 40-pin DIPs. I settled on the -128 because I wasn't cost-sensitive -- it had every feature I was likely to need in the future, and would save me from learning the ins and outs of the different parts.

The -AC suffix means commercial temperature range. For $1 more you can get the -AI part with a wider (industrial) range. (Although it's probably the same part with a different guarantee!) I'd just go with the ATMEGA128-16AC-ND if I were you. (The -MI and -MC packages are MicroLead Frame parts that will be much smaller than the others -- and much more difficult to work with at home.)

For so long as men do as they are told, there will be war.
[ Parent ]

Nice introduction (none / 0) (#41)
by pmgolz on Wed Apr 16, 2003 at 06:13:09 AM EST

I work for an educational software company and wrote a program to try and introduce microcontrollers to school-age children (12-18). Much as I hate to make my company money, you can download a trial version from http://www.crocodile-clips.com/m6_1.jsp
It allows you program microcontrollers using flowcharts and then download the finished result into a real PIC. When I was working on the project we tried to find PIC manufacturers who might want to write plug-ins for our software but no US company did. Which are the main products used for programming PICs in the US? Also in Europe?
------
Enthios
Did some pro pic work recently... (none / 0) (#44)
by c4miles on Wed Apr 16, 2003 at 07:03:14 AM EST

Ended up using a PICStart Plus programmer (an old one, you can update them by downloading and programming a new ROM - this one was about 15 years old), the Microchip MPLAB IDE (free) and the CCS C Compiler. The IDE is free, the compiler is about UKP100, and the PICStart plus is around UKP200 but just found this fully compatible setup for $99. The compiler integrates with the IDE integrates with the programmer. Nice quick turnover, especially with flash parts.

In case you hadn't guessed, this was in the uk. For a company making personal safety equipment for the elderly.
--
For the Snark was a Boojum, you see.
[ Parent ]

Proprietary methods suck. (none / 0) (#48)
by tzanger on Wed Apr 16, 2003 at 12:27:19 PM EST

disclaimer: I designed, programmed and support the Benshaw RediStart Digital series of soft starters. I was also heavily involved in the design of a "smart" (read card readers, run cameras, sense cars/people, voice interaction, etc.) garage door controller for industrial complexes, apartments, stadiums, etc. (no link, sorry.) I've done some other designs with the PICs, and have used other processors (68k, Intel C196, etc.) but those are the biggest/most impressive of the the lot.

No offense, but the reason that proprietary third party tools don't catch on in the professional realm is that they are inferior compared to the old standbys of C and assembly. (there are some pockets of embedded FORTH and COBOL but they're practically gone.) The STAMPs and compiled PICBASICs and B.LO.Cs (who remembers them?!) of the world are great for hobbiests because they ease the learning curve. When you're down to the wire and have a tight cost/feature point to hit you don't screw around. You hire a competent programmer and forge ahead.

The soft starter I designed runs a PIC16C77 (was 74A but ran out of memory) at 8MHz (2MIPS), uses every peripheral on the chip except for the parallel slave port and doesn't go more than about 125 instructions before hitting an interrupt (usually for A/D or line sync) -- you simply cannot do that without being able to nuzzle up to the hardware. The garage door controller used a 16F877 but again memory constraints pushed us into the 18F series. I've worked on systems using the 12C508 right through to their high-end dsPIC series -- all in assembly mind you.

I would hazard a second guess as to why the proprietary languages and programming paradigms of the world don't make it far -- they abstract you away from the hardware and the assembly code produced so when you've got your $2000 ICE hooked up to it, you're not much farther ahead because you spent most of your time trying to make the flowcharts work instead of understanding what the flowcharts were making the processor do. Some abstraction is good, but too much is a hindrance.

Hell, even in the industrial programming world (PLCs) they don't use proprietary systems anymore -- everyone's using IEC-1131-compliant systems these days and the high-level control and monitioring is down to a few vendors, WonderWare being the top name.



[ Parent ]
Nice simple programmer! (none / 0) (#51)
by the on Wed Apr 16, 2003 at 03:22:10 PM EST

In theory it should be possible to the same with an FPGA or CPLD - you just need a bunch of resistors. The catch is that I haven't figured out how to plug a 144 pin surface mount package into a breadboard for a reasonable price and they don't make alligator clips that small! I'm not up to soldering 144 pins on a homebrew breadboard - especially not when I need to get tracks to wind between pins on the socket.

--
The Definite Article
PLCC / Breadboard sockets (none / 0) (#69)
by HercMk2 on Mon Apr 21, 2003 at 12:40:08 AM EST

Here's one company that has something you might be able to use: PLCC Adapters for Solderless Breadboards

Their products use a vertical orientation (i.e., the chip's on its side), so they fit like very long DIPs on a breadboard. I've never used them, but I found the link and am considering it. (Caveat emptor, in other words).

The downside is that they only support PLCC packages (not PGAs, QFPs, BGAs, etc.) The max number of pins is 84, but you couldn't fit many more than that on a standard breadboard anyhow. However, some PLDs, like the Altera EPM3032A and EPM3064A, are available in a PLCC-44 package, and I'm sure there are others.



[ Parent ]
I've been searching for something like that (none / 0) (#71)
by the on Wed Apr 23, 2003 at 07:16:14 PM EST

Those are pretty damn useful parts - though the PLCC adapters are pricey.

Still, I managed to solder 44 wires to all 44 pins of a PLCC socket at the weekend. Circuit worked fine almost first time. (Not bad I thought considering I've only just learned how to solder.)

--
The Definite Article
[ Parent ]

Misread it (none / 0) (#72)
by the on Wed Apr 23, 2003 at 07:25:27 PM EST

They aren't so pricey. It's gonna be tricky to connect pins on one side to pins on the other side though!

--
The Definite Article
[ Parent ]
Atmel chips in the UK (none / 0) (#59)
by Builder on Thu Apr 17, 2003 at 10:18:40 AM EST

Anyone know where to buy Atmel chips in the UK? Maplin haven't heard of them.
--
Be nice to your daemons
Atmel Chips in the UK (none / 0) (#68)
by kyboshed on Sat Apr 19, 2003 at 10:42:58 AM EST

I ordered mine from Farnell (£6.60).

Farnell

There's a £10 minimum order though.

[ Parent ]

...it should work for a quick test... (none / 0) (#61)
by the on Thu Apr 17, 2003 at 01:38:48 PM EST

9V battery across 200 Ohms. P=V^2/R=(81/200)W=.405W

So make sure you aren't using (1/4)W resistors or you're liable to have a meltdown!

--
The Definite Article

Good point (none / 0) (#62)
by jmzero on Thu Apr 17, 2003 at 02:40:32 PM EST

I should have made more clear in the article that this isn't a real solution, and it's one intended to be used to test and then turn off.

A better solution might be to run your little blinking lights board with the same power from the parallel port, but I thought that might be confusing to wire (and I didn't want anyone to try powering their toy motor this way).

Thanks.
.
"Let's not stir that bag of worms." - my lovely wife
[ Parent ]

Just an extra link (MLP style) (5.00 / 1) (#63)
by truth versus death on Thu Apr 17, 2003 at 03:07:14 PM EST

How to make a USB-based serial programming device (a little more expensive than the above project ;-).

"any erection implies consent"-fae
[ Trim your Bush ]
That's really cool. (5.00 / 1) (#64)
by jmzero on Thu Apr 17, 2003 at 04:17:50 PM EST

Perhaps not a good plan for a first project - but even if you don't want to build the programmer it has some good ideas.  

I might have to try one of them EZ-USB chips.
.
"Let's not stir that bag of worms." - my lovely wife
[ Parent ]

Yeah (none / 0) (#65)
by truth versus death on Thu Apr 17, 2003 at 05:00:55 PM EST

I myself am pretty inexperienced at this stuff but stumbled on the above link after reading your article so decided to post it. Definitely not a good first project if you haven't delved into this stuff before.

My motivation in learning this is to someday use the USB on a modern Macintosh computer to talk to a Series 1 TiVo over its simple serial jack. Now that'd be cool! ;-)

"any erection implies consent"-fae
[ Trim your Bush ]
[ Parent ]
LEGO and microcontrollers (5.00 / 2) (#73)
by frijolito on Wed Jun 18, 2003 at 07:42:27 PM EST

An open-source project that is simply amazing is legOS. These guys built entirely from scratch a very complete, open programming-environment-slash-operating-system for the RCX, which is included in the LEGO company's "Mindstorms" kit.

If anyone is interested in microcontroller programming for robotic devices, and is looking to shell out a couple hundred bucks for a very complete kit which includes sensors and a buttload of LEGO Technics pieces, then I wholeheartedly recommend the software churned out by these guys.

Disclaimer: I work in a crappy software sweatshop in South America, and have no connection to the LEGO guys (I wish!)... I'm just a long-time happy user =).

Build a Simple Microcontroller Programmer | 74 comments (52 topical, 22 editorial, 0 hidden)
Display: Sort:

kuro5hin.org

[XML]
All trademarks and copyrights on this page are owned by their respective companies. The Rest 2000 - Present Kuro5hin.org Inc.
See our legalese page for copyright policies. Please also read our Privacy Policy.
Kuro5hin.org is powered by Free Software, including Apache, Perl, and Linux, The Scoop Engine that runs this site is freely available, under the terms of the GPL.
Need some help? Email help@kuro5hin.org.
My heart's the long stairs.

Powered by Scoop create account | help/FAQ | mission | links | search | IRC | YOU choose the stories!