 proud to see as many people as I do here you are obviously the the hardcore who are both awake and have not left after checkout time so thank you for coming uh so basically my talk today is on 8-bit microcontrollers uh I'll be going over a bunch of different aspects of them it's kind of a shotgun presentation I am Phil King and the reason I might have something useful to say about this is because I'm a hardware engineer who's been designing with these things on and off for over a decade now I am also an enthusiast who's building all sorts of weird things at any given time and I actually have taught a course on this stuff so I so I picked up some idea of what to present the forum here is really different than I'm used to so there will be there will be glitches and I ask you to indulge me if there's anything you need to know please raise your hand I will be taking questions throughout but I also have a Q&A period at the end and the reason you should be you should be interesting what I have to say is because we've got some really neat stuff you can do with 8-bit systems 8-bit microcontrollers and of course free stuff since that's always yeah I'll be getting he asks are the notes and slides available online they aren't yet they will be and the url is at the end of the presentation uh so they they will be available you don't need to write all this crap down with regard to getting free stuff since that's what you're all wondering about since I mentioned that last the free stuff specifically is an atmel stk 100 starter kit they are these things this is the hardware that I have developed this presentation around they're a really slick little kit I don't even know off the top of my head what what the price of these things is retail I think they're about 150 but I've got some of them to give way and there's two different ways to get one you can either suggest a project idea during the Q&A period in which case we will be be prepared to to elaborate and I'd like to discuss ideas and I may or may not invoke the audience to to give you the thumbs up or thumbs down on whether your your idea merits a starter kit and then the other way is to get to get a starter kit by submitting a feedback form with a project idea and this is if you're not willing to hold your project up to public humiliation feel free to write down the feedback information at the end this is basically the way I bribe my audience to give me recommendations on how to make these talks better I've been doing variations on this for a while now and hopefully it's evolving and getting better but if it sucks I need to know that so specifically what am I going to hit on I'm going to hit on what are microcontrollers presumably if you're here you have a pretty good idea what that is so I'm not going to dwell on that real long why am I focusing on the tiny ones the talk title is eight pins and eight bits and I'll get into what exactly that means in terms of the starter kit shortly what can they do what exactly functional what exact functionality do you have in these things what are the development tools both what am I using and what if you want to be using something else and then I'll do a bunch of application examples I don't have specific demonstrations of most of the application examples because a lot of them are derived from other people's projects application notes things like that and instead I look at them in terms of putting them on this hardware and what you would want to do to adapt them to your needs and then finally the Q&A period at the end always got to have one of those okay so what exactly is a microcontroller some of you are actually old enough to have started out working like I did on eight bit computers before before Intel ruled the world was that was that a four a four bit impressive but there was a time when eight bits was was what you got uh at least in anything that that had a single piece processor now most eight bit controller eight bit processors which by the way still represent the largest market share in terms of number of cpu core shipping are found almost entirely in microcontrollers which is an eight bit cpu core together with a bunch of resources stuck around it in and the common canonical examples are memory for example some rom or flash or eprom ports which are programmable i o where they've they've generally taken all of the internal bussing to the processor kept it in the chip and then they give you some ports out to pin so you can twiddle individual electrical connections as i o ports rather than dealing with them as memory mapped i o and then a variety of peripherals depending on on what you're what you're using i i mentioned timer interrupt controller these are sort of the basic ones larger microcontrollers will have more i'm dealing with really really small ones and then generally a microcontroller is a self-contained architecture requiring only a few other components or in the case of some of these parts literally no other components to build a system so why am i so obsessed with the tiny ones little eight pin eight bit jobbies first of all because we can uh it's it's really cool to see what you can do with a part that has only eight wires coming out of it also learning to make use of minimal resources there there are some folks in the demo crowd who know that 1k is a lot of program space uh but there are a lot of people who who have gotten away from from the roots and it's it's fun to see what you can do in a very small very small package both in terms of physically and in terms of code space and then minimal wiring and i put that up kind of as a joke but when you've only got eight pins there's just not that much wire you're going to need and if you hate soldering things together or you hate wire wrapping this is this is a good way to keep the the wire count down so what what are some of these interesting minimal systems and one category i sort of synthetically lumped a lot of them into is implants which are things you want it to be small enough that you can put it places people won't notice it that it's unobtrusive or that it fits inside some existing system so bugs or portable stuff uh another essentially are arguably an implant also but but a separate category is mod chips and i will sort of glance over that but i know that's of interest to at least some of this crowd um and then telemetry devices one of the things that came out in the project discussions last year is a lot of people said i want to build a telemetry widget for blah and so that's a really good application for a really small controller where you want to collect a few bits of data and either log it or send it off over over a link somehow and so what what are the eight pin microcontrollers if you if you look at the whole family the ones that i have been able to track down there may be others i have overlooked if so i apologize and feel free to to add them to the heap but the common ones available now are the at mal at tiny series and a couple of the other at series um and then the microchip pick 12c and i believe they've just come out with an eight pin version of either the 14 or the 16c there are also that's that's why i said there's a few other picks i'm going to be focusing on the at mal avr's like so many things in this in this world uh your choice of processor your choice of microcontroller rapidly becomes a religious topic uh i i like the avr because it's got some neat features and because i can get free development hardware for him um yeah the the pick is the pick is also a good part a lot of people have a lot of experience with the pick but i'm just going to be running off on the avr and uh showing you what what you can do with this board so the common features to the avr architecture whether they're the eight pin or not are that it's a risk instruction set uh the closest you may have have run into if you haven't done microcontroller development is uh mips the mips risk instruction set the uh it's a harvard architecture meaning that you have separate code and data space um there's 32 general purpose registers although as with most 32 general purpose register sets they're not all quite general uh and then there's a status register and then there's a set of i o registers that vary from part to part but every one of them has a block of i o space uh some of the features of the risk instruction set that make it really good even for a small application like this is simple fixed length instructions uh in the avr instruction set virtually everything is a 16 bit word uh which means that when you get the pipeline the the execution pipeline full they're able to click uh click around click along at one cycle per instruction if you've done any development with say an 8051 depending on the implementation the 8051 will run up to 12 cycles per instruction uh which which really starts to bog it down it's nice that you can that you can run a an avr at one megahertz and get in the best possible case one mips out of it uh and then it's a load store architecture meaning that anything you want to manipulate you drag into a register you twiddle it you shove it back out there are no direct operations on memory uh some of the general purpose register oddities i mentioned that they're not all quite equal uh if you do a load from data in program space and that may sound a little odd but there is a there's a special instruction called lpm for loading constants that you've stored in your flash code space they get explicitly loaded to r0 that's hard wired into it if you do a load immediate because of the way the instruction is set up if you think about you've got 16 bits for this instruction word if you're doing a load immediate eight of them are taken up with the immediate value and some of them have to be for the op they they wanted four of them for the op which means they've only got four bits left over for the register description which means that you can actually only address 16 registers for immediate instruction so they arbitrarily chose the upper half of the register set so you get r16 to r31 if you want to do a load immediate you cannot load immediate in the r0 to r15 and then there are several uh two two register indices that are set up in the case of the the small parts the only one that they implement is the z index which is the concatenation of r30 and r31 and to give you an idea of how this stuff all maps together there is data space which has the register file also at the top of data space which means you can you can access registers by doing memory access and you can treat the registers as a block of s ram which is useful because some of the parts have no other s ram and in fact you've only got 32 bytes of s ram in the register file uh you can also and then they also map the i o registers which have their own sort of pseudo i o space immediately after the register file so on all of the avr parts the uh data address space is is known to be the first the first 0 to 1 f is going to be your your register file and 20 to 5 f is going to be your i o space if s ram if there is any begins after that external s ram if the chip supports any and none of these do some of the larger ones do happens after that so the specific features of the at tiny tiny 11 the part that we're looking at are it's an eight pin dip or s o i c package uh i don't i have some some pictures later on i don't know if everyone here is familiar with an eight pin dip it's it's a really standard package it's it's relatively small if you want it smaller you can go to the surface mount s o i c uh there are six i o lines available or actually this should say five i o and one input if you disable the reset if you think about it that means you've got six i o and power and ground so it's it's making good use of its pins and then in this particular part you've got one k byte of code flash because it's a 16 bit instruction word that's 512 instruction words and some of you are thinking what can you possibly do with 512 words some of you are probably thinking why why that's that's a ton of space um the truth lies somewhere in the middle and i'll and i'll touch on some of the some of the cool things you can do in a relatively small space when i when i'm talking about the feature uh the applications more features there's a variety of speed grades available for the at tiny 11 and you can you can sort of map into a a space of what power and speed performance you want you can run them up to six megahertz uh the at tiny 11 specifically comes in speed grades up to six megahertz at five volts and then in lower voltage uh versions that run for example down to 2.7 volts at 2 megahertz another nice thing about this is it's a fully static CMOS implementation meaning that you can actually run the clock all the way down to zero it's got a couple of standby power modes that that will that will turn itself off and it can also be set to wake on interrupt which means you can you can if you know the next behavior the system wants to respond to is something outside of itself it can actually just put itself to sleep and it will wake up on an external interrupt and you can drop the power consumption down to a few micro amps and then uh even when it's running running relatively fast it's it's fairly low power it's uh and then i i quote the uh data sheet at less than five milliamps at one megahertz at five volts if you bring the voltage down you can bring the power down uh within within reason there's some other implication implications to running the voltage at different levels and i'll touch on those briefly later it also has a whole bunch of different clocking options and this is this is kind of cool as well because when you're building a minimal system you don't want to have to hang an oscillator off this thing you can you can externally clock it you can stick an external crystal and it actually has a an oscillator amplifier circuit built into it in that case you burn two of your eight pins just sticking a crystal on it if you only need four that's that's fine if you want to hook an external oscillator up to it you can you can do it with only one pin in that case it's just the input the clock input you can also do it with zero pins with the onboard rc oscillator uh the upside is it takes zero pins and it runs at one megahertz at five volts although it runs at 350 kilohertz at three volts it runs at 110 kilohertz at two volts it runs at 1.1 megahertz at zero degrees celsius it runs at one it runs at 900 kilohertz at 70 degrees celsius in other words it's not regulated it's going to drift all over the place if you've got an application where you're only interacting with people this is okay if you've got an application where you're doing asynchronous serial communication you may want a more stable clock the at 12 part for example has a calibrated oscillator on board and they actually tested the factory and and guarantee the the constraint of that one megahertz rc rc oscillator on the at tiny 11 it's going to drift all over the place and the specific microcontroller resources they've stuck on this particular part are a hardware watchdog timer in this case they actually run the watchdog timer off the same oscillator as the self-clocking rc circuit so the watchdog runs at one megahertz and you can divide that down by any of a whole bunch of prescale values and or you can disable it if it's on and your system uh has has turned on the watchdog and fails to kick it before it times out the watchdog will trigger a reset uh this is useful if you're building a system that you're afraid might go brain damage it's also useful if you're building a system where you want to be able to time out on confusion and i'll touch on that later there's actually some good software system reasons you might want to watchdog timer it's got an eight bit counter timer it's a counter when you when you use it to when you trigger it based on an input pin it's a timer when you hook it up to the clock and you can use this for doing all sorts of real time or quasi real time applications there is an analog comparator which allows you to to tell to get a single bit uh comparison of two analog inputs on two of your iopins it can also generate an interrupt so if you want to be monitoring an analog level and cause the system to wake up you can actually trigger on analog comparator fire uh and then the interrupt controller which which hooks some of these together the you have an external interrupt pin you've got a an interrupt on any pin change you can actually cause the system to interrupt when any of the external pins change value so they can effectively all be used as interrupt obviously you've got to be careful because you you could interrupt a lot if you've got that hooked up to a high speed high speed signal you've got timer counter overflow and then you've got the analog comparator what does it not have this is this is where the rubber meets the road on some of the some of the eight pin stuff it has no SRAM beyond the general purpose registers that means if you need more than 32 bytes to do anything this is not the part for you uh it does not support any sort of external SRAM obviously with eight pins you're not going to have a real big address data bus uh it also means that because there's no external SRAM the the stack is three deep meaning it's really easy to blow it and it's implemented in hardware so it's nine bits wide of custom hardware you cannot explicitly push or pop anything into the stack only when you do calls will it stick the pc the program counter into the stack uh otherwise the stack is effectively not there also if you do below the stack it has the interesting behavior of wrapping around so if you if you do a if you do a call call call call you will have lost the first call return address and the fourth will now sit over the first um it also has no hardware you are one of the things I talk about a little bit later is implementing a software you are which is really quite doable it has no ee problem storage that may seem a little uh non sequitur but many of the parts do have a small chunk a third memory space that is ee problem space for storing lookup tables constants this is a non volatile space normally the part can write to in this case it just isn't there and then there's no atd converter uh you can you can add a serial atd converter if you want or if you really need that use a part that has it but this particular part doesn't what development tools am I using uh the assembler of choice I use is atmel avr studio which is an integrated development environment with an editor and assembler it also includes a simulator so you can actually simulate your code uh obviously within the constraints of not having the hardware in the system uh if you're using the avr studio with this particular board you have to use a separate isp package in system programming and that allows you to program through the pair parallel or serial port and then the development hardware as I talked about a little bit earlier is the uh stk 100 I don't know why I'm holding it up no one can see it when in fact I have uh a slide of it in just a second there we go there is what the board looks like uh you see the parallel port and serial port connections on the left side you've got a prototyping area on the right the uh the stack of sockets the stack of sockets about midboard is where you plug in the various parts you can see it supports uh two flavors of eight pin part and then a 20 and a 28 pin there's also a micro controller on it that's that's doing the system programming yeah this particular os only runs uh or this particular development only runs under a rather unpopular os uh there are other options and I'll touch on that in just a minute the uh good question the the white circular thing is actually a piezoelectric speaker that allows you to do uh sound output and I'll touch on that as a neat application of these parts shortly um and then another nice thing about this board is it has its own power regulator built in so you feed it basically seven to 20 volts ac or dc and it's any polarity of dc and it's fine with that uh as I as I mentioned it accommodates the 20 to 28 pins provides oh it also provides four leds and four buttons the fifth led and button were the power and reset respectively um and then there's various jumpers next all of the all of the uh the sockets that allow you to to turn on and off some of the functionality if you don't if you if you want to wire things out directly this the uh the jumpers make great wire wrap posts um and then this is this is a really good system for getting a minimal a minimal uh development going but once once you're going it's also really easy to transition to a standalone device and in fact there's an isp header at the top of the board uh there's a header that allows you to use this board to insystem program your own part if you accommodate that in your design and in an external board uh oh and one other thing there's an ir uh transceiver pair on this thing if you want to develop an ir remote control and I talk about that a little bit shortly okay so what if you hate this os or what if you want what or why can't you see uh specifically cross assemblers and and that's my preferred development tool are available for pretty much any os uh the assemblers are relatively simple to write one of the nice things that falls out of uh a risk architecture is the assemblers are pretty straightforward uh the isp tools are also available I do not recall off the top of my head what the preferred linux isp or bsd isp is uh I'll try to get pointers to those up on the website fairly quickly yes a terminal emulator and a z modem transfer with the stk with this particular development environment okay if you've got if you've got a minimal system I I'm I'm not sure if that will work with this particular board it may uh I honestly don't know if he suggested you can just do a z modem was a z modem transfer okay uh to the part uh but the absolute of it is that even though kanda who makes this board for atmel does not publish this stuff widely enough uh it is readily available online uh and as far as c you can use uh there's there's a variety of c development environments a lot of people say well you know c can be done efficiently and it in fact can iar makes a third party development set unfortunately that costs about 5k uh gcc which actually arguably produces better code is available uh widely and it it does it's it's really easy to to set up a c environment i i don't do it simply because i prefer to see exactly what instructions i'm twiddling and and be able to run the uh the simulator environment uh one of the things you got to be aware of when you're using c especially with a part like this some of some of the uh compilers will choke on this simply because you have no s ram and they really want a stack to maintain stack frames and they get cranky when they've got no s ram at all uh but they they can do it okay so what can you actually do what are some of my sample applications uh an at keyboard interface uh a serial flash connection and audio output and some of the canonical audio examples are morse and dt mf uh some other example modules would be a soft u art i alluded to that earlier data stream manipulator otherwise known as a mod chip and an ir remote control or even a small parallel application in this case a four bit parallel application a stepper motor controller so the at keyboard interface at this point i i'm going to delve into these i'm going to try to give you a sort of glancing overview of a bunch of different things reference uh some of the application notes you may want to look at if you have if you have more questions feel free to raise them either now q and a or or after the talk uh but the at keyboard interface for anyone's looked at it is a serious synchronous serial interface meaning you have a clock and a data line it's very well documented very straightforward uh it also includes five volt power with it this is really nice because it means that the at connector can power your little your little widget and you're well within the uh the current limitations of any device hanging off an at uh an at port in fact virtually every keyboard in in the world has a microcontroller in it which is just running an at interface most of them are 8051s because they were all designed back in about uh 1983 ported over when at became popular for when xt became at and then they they largely haven't changed them it's a it's a rom rom-based microcontroller the qcat makes a great housing and a source of cable if you're looking for a keyboard interface in taking apart the qcat you will also learn some interesting truths one of them is that there is no direct electrical connection between the keyboard in and keyboard out from the qcat which means that it is at least handing along and being aware of every keystroke this makes sense but it's also a little insidious for reasons i'll get to momentarily so the at uh the at mill reference at keyboard interface is application note 313 they wrote it in c i went through it and i've done parts of it in assembly i haven't i haven't got that up and available online yet either but hopefully it will be uh they actually put the clock on the external interrupt line one of the nice things about the at interfaces it it has a maximum clock rate of i believe around 100 kilohertz 110 kilohertz which means you can actually uh it's slow enough you can just trigger and interrupt every time a clock signal comes in and read the bit uh sample sample the data every interrupt and then it's possible to get out of sync with the 11 bit frame that it sends if you somehow miss a bit uh for some reason in that case what you generally want to do is time out the their canonical example uses the uh the the an 8 bit timer for a 1.5 millisecond time out and then this is where if you're clever and want to save a few a few bytes of code space you just set up the watchdog to time out after 15 milliseconds every time you receive a a bit or you've gotten to the end of the 11 bit frame turn off the watchdog you kick the watchdog timer otherwise it'll get to 15 milliseconds it'll assume that it's gotten out of sync and it'll time out and reset so what are some amusing inner widgets you could build with just an 8 bit micro controller hooked up to an abort an at keyboard and a few i came up with were the typo generator where you could have something that sits on the keyboard line and turns say every fourth r into a t or or just does does minor transformations in a non-obvious way on the keyboard stream this will annoy the hell out of anyone who doesn't know what it what that it's there another that i would like to build is the keyboard pipeline where it doesn't actually release a keystroke until the next one so you've got a leg of keyboard of a leg of keystroke in your keyboard and then something that's actually useful something that actually has has some uh some use would it be a keyboard remapper if you wanted to do a crudy dvorak or a pc to sun uh because a lot of people get cranky about transposing caps and uh caps lock and control when they're changing keyboards so there are actually a lot of uh a lot of useful applications even with just just the at keyboard interface yeah he asks if you set it up to look for keystrokes s and u together and then log say anything around that how hard would it be to get it out um it depends on how you want to store it how you want to get it back but hold that thought so you want a lot of memory a serial flash for example atmel makes this great little part it's the at 24c 512 it is 64 k bytes of flash in an eight pin dip package it has again a two bit uh rather a two-wire bi-directional interface you can actually stack them and it has because they're using power and ground uh as two other pins uh clock and data as two of their other pins they have a right protect pin and then two of the pins are address lines so you can actually set these address lines basically as a bootstrapping you hardwire the address lines and then in the command frame to the serial ee prom you can address an address you provide two address bits so you can address up to four of them which means you can stack them and you can basically bust them together and get up to 256 uh 256 k bytes of storage in serial ee prom in a very small form factor uh here's here's an example uh one of the nice things is because it's an eight they're both eight pin dip packages they share power and ground pins so you can do this little this little bug sex thing where you basically just stack them together and in this case i would actually to do what i want to do with it i'd actually have to route some of the pins around uh with with some wires because i this unfortunately puts uh one of the serial data lines on top of the atmel and interrupt line which you want for the keyboard interface but i mean if you look at it it's pretty cool that you've got in the in the left hand picture you have a microcontroller with 64 k of flash hanging off it that's non-volatile memory uh the whole system runs at five volts and basically you could you could make that work with no other hardware hanging off it uh the right hand example is if you want to boost that up to 192 k of flash i have the one pin that's one of the address lines and basically i i just wanted to provide an example of how you if you don't want if you don't want that pin connected normally you would tag the pins together with solder but if you want if you want to pin to go somewhere else it's really easy to just lift it up and run a wire off it hmm okay so you've got an at keyboard interface you've got a large non-volatile memory you've got a tiny size and you've got a bunch of people at defcon what could we build with this now at this point i will go into a brief aside on a moral conundrum i found myself in when preparing this talk it resolved itself in part because i was behind schedule and didn't get the thing completely built but i was actually going to provide a reference design for a keyboard sniffer that anyone could build i read an article though about giving guns to children it may it struck a chord with me that you know there should be a certain minimal sincerity check to this you should you should at least have to build your own gun so so i largely leave it at that but the implication is you could build a really spiffy little keyboard uh keyboard sniffer and as as to the question of how you get it out how you get the data out uh if you've seen the ghost board which is actually a commercial product that does this and is in fact based on i think it's it might be based on an avr don't remember there's there's a web page someone tore one apart and saw what's in there and they actually used a larger microcontroller i think this is a little slick a little little cooler solution because it's just that much smaller i mean you could probably make it look like just the keyboard connector but in their solution they actually capture keystrokes and then output keystrokes uh as as the means of getting to you actually type a an activation sequence and since it's sniffing the at keyboard interface you can just use that to trigger it to have it kick over and and reveal that it's there and start dumping its log uh i i would be inclined to actually make the thing completely transparent you want it to be completely out of band so there is nothing you can type that would make it reveal itself and also i i would prefer to given the number of pins uh and what i'd like to to use them for i would probably actually set the hardware up so that i would have to drop it into a second fixture to extract the memory but that's just because i want to be the only one who can read it anyway so skipping skipping oh yes sure yes the question is is there a security bit in the atmel that will that will prevent reading back the contents of the program memory and the answer is yes there's a couple of flash fuses that set different functionality but one of them is a security bit there's a uh a a read protect uh that will that will make it impossible to extract the contents there is also a write protect i believe that makes it impossible to overwrite it although you can still erase it if you want to so you don't end up turning it into a one-time programmable part um anyway uh it depends on the specific part but check the data sheet there are there are definitely things you can do to make your code i won't say impossible to extract but you can you can require them to shave off the top of the part and use really expensive probing equipment and there are some really neat probing tools uh so audio output the there there is a proud history with 8-bit systems of generating uh audio by twiddling one bit to a speaker anyone who who grew up with an apple 2 knows that you can do some pretty amazing things with one bit to a speaker uh you can also use a lookup table to generate a more pure tone and uh i talk about using a lookup table in either ie prom or using load program memory um you may be wondering how if you've only got one bit going out how do you get anything other than on or off and i'll talk about that just in just a second with uh program space the i talked about this briefly earlier but the way you extract uh your your lookup tables from program spaces with the lpm command you put the address you're looking for in the z register which is which is basically the r30 and r31 and then because of the way they want to represent the program memory as a a 16 bit word they call the upper 15 bits the word address and the lower bit the byte select which is the same as saying a byte address but that's the way they represent it but basically it means that you can you can store constants efficiently in the 16 bit uh flash code space so so you can store lookup tables even though you don't have the ie prom in this particular part uh morse code like i said is a real canonical uh audio audio interface it's it's kind of cool because it represents um a a fairly well known audio output and it's kind of it's kind of nice to have your your part alert itself that it needs to do something by just going an interesting exercise when you're working with a system with no space uh such as this or minimal minimal spaces how do you how do you uh encode morse uh for your lookup table to to do the ascii to morse conversion and i i touch on this just because it's it's a neat example of figuring out how to store things really efficiently uh morse is essentially binary and that you've got short and long but you've got variable length signal symbols anywhere from e and t which are one up to some of the punctuation which i believe are six or seven i don't remember if there's any seven punctuation uh if you use a counter and a bit mask then you quickly run out of bits for anything longer than five and i i talk about l you know there you could use you could use the four and then a bit mask and you could concatenate them together using three bits and five three bits of length and five bits of uh of data or you could use zero null bits at the start a one start bit and then the bit mask after that in which case you've you've managed to reduce the length indicator to one bit uh and this struck me as something that's not immediately obvious but is is a nice efficient way of of storing things that are variable length and little little lookup tables so i felt compelled to to include that okay dt mf say instead of a morse application you want to be able to dial dial a phone at mel has an application note for you uh avr 314 they do it in 260 bytes of code and 128 byte lookup table the lookup table is basically just a representation of the pulse with modulation constants for a sine wave and what you do is you output variable length constant values on the speaker pin and then you take advantage of the fact that there's a a characteristic capacitance to act as a low pass filter and so what you do is by turning the speaker on and off faster than it could possibly represent an audio you get the the low pass equivalent of that which turns into a sine wave or something close enough to it that that you can actually do fairly pure tones you can do tones pure enough to do dt mf um in this case the example in the data sheet uses a pulse with modulation uh feature that is included on a lot of the timer counters on on the uh larger avr's in this case there's a timer counter but there's no pulse with modulation feature to it so you'd have to to jerry rig that in software but it can be done um and that's that's how you can do pure tones obviously if you want to do complex sounds you would need a much larger external memory but again if you've got say a 64 k k byte flash memory hanging off it you could actually do a pulse with pulse with modulation representation of more complex waveforms to generate more complex uh sounds soft you are say you want you want your device to be able to talk to the outside world in in an obvious way uh application note avr 304 is a really complete interrupt driven uh timer based uart it takes uh several hundred words of code space so you eat up a good chunk of your code space but you end up with a uart that is unobtrusive sits in the background interrupt uses the interrupt pin uh to detect start bits and then and then samples based on the timer uh all of these if you're going to hook them up to say an rs 232 port are going to require an external transceiver to do the level shifting from zero to five to zero to twelve uh but those are those are readily available or if you've got a system that's all what that's all things you've built you can you can just keep it all at five volt signaling uh i believe that's rs 422 or something um what okay 422 is balanced thank you yes he asks the clock is someone unstable what do you do do you use a crystal to to clock it uh and again the audience is getting ahead of me if you wait just about two more slides i will in fact address that um but yes there are there are definitely clocking problems on an asynchronous interface that you have your that you have clock drift uh and there's a couple of ways around that if you want a minimal software you are application no avr 305 is 32 words busy wait loops no interrupt no timer quick and dirty and it's really kind of cool basically there's one there's one hard coded busy wait delay loop that's half a bit time long for whatever bit speed you want the thing to accommodate and then it just does shift register work and calling this delay loop uh one one two or three times depending on how many half bit delays it needs and that's that's a good example of uh sort of sexy little uh very small efficient uh coding for microns I mean 32 words for you are this is pretty neat some thoughts on software you are it's at high bit rates uh your clock your clock disc uh your clock alignment with whatever baud rate you're trying to support will get worse and worse and as was brought up the clocking is only as stable as a system clock beware of the internal oscillator if you're using a part like this running at 1 megahertz you can you can theoretically do a ur that supports 38.4 uh kbaud however you probably want to bring that way back because as your clock drifts the uh the error gets more and more severe uh and you've got thermal drift you've got voltage drift you've got manufacturing variations as I said the at 12 also includes a calibrated clock that you can use yes yes oh yeah the the the at keyboard is is a synchronous interface that can go up to 100 kilohertz but fortunately you don't have to extract your own clocking out of it yes okay the question is can you measure the internal clock to an external clock to do thermal measurement of the of the part with the clock drift not that I am aware of I don't believe there is anything well it might be possible if you had an external counter to do to do counter matching the trouble is you can't get single clock resolution for it would be difficult to get single clock resolution for doing comparisons it might be possible uh it's much cheaper to just stick a thermal thermal measuring device in the system um either either a thermal diode or uh or or a an explicit thermistor um another another point you bring up though is clock drift if you do have a stable external reference and you are willing to believe that clock drift is truly random uh is is a good source of randomness uh you can you can actually use clock noise to to feed your entropy buffer if you you know are into that sort of thing um so data stream manipulation oh my uh data stream manipulation mod chips like I said I'm going to only touch on this if you do a search on avr mod chips for the play station you will find that there is someone who actually has source code available online uh the way a mod chip works at least in a play station is you are just replacing the very low bit rate out of out out of band uh serial stream that says what the region code for this particular disk is and what it does is instead spits out the region code it spits out all of the region code so that any mod chip will work anywhere and the play station hardware that reads this at least initially was forgiving enough to accept this sort of behavior um most of the mod chips that you can buy online are implemented on the pick uh device they're like I said there's at least one avr available online and again beware of clock clock deviation uh if you're gonna do a mod chip you might want to do it on an at12 which has a uh calibrated clock because if you have thermal drift you can actually get far enough out that your mod chip will stop working some of the early generation mod chips suffered from thermal failure whereas your play station is on for half an hour it warms up and the thing uh thing no longer works play station two mod chips are showing this behavior I know that there was also some effort and in the design of the play station too to make it a little harder to do this sort of thing uh obviously in any system where you've got the signals running around someone's going to figure out a way to get in there I think their goal is merely to make the mod chip more expensive than the play station so and that that may well happen uh and then I talked briefly about doing an ir uh ir receiver if you want to be able to to build a remote control uh a wireless remote control application philips sony rc5 protocol is explained in avr 410 uh it's similar to a soft uart except it uses biphase or manchester encoding where there's a transition on every bit time that means that a high to low transition is a zero a high to low transition with the transition in the middle of the bit is zero a low to high is a one the reason you do this is because it's easier to spot transitions than long runs of constant value especially in a medium like ir uh it also means that the signal is self-clocking uh you don't have to maintain clocks synchronization over many bit times uh it takes an input from an external ir diode and the ir diode is actually available on this board and then the rc5 framing and they get into this uh in the datasheet but i just wanted to mention it is two start bits which are always ones a control bit which is toggled every time any particular button is pressed five address bits because of course you want two to the fifth devices to control with your remote and uh six command bits because of course you've got that many devices what do you have to say to that many and then the small parallel example is a stepper motor controller and i include this because there's actually a lot of uh there was a lot of interest in doing uh servo designs at last year's talk and stepper motors are really nice because once you understand what they're doing they're fairly easy they are open loop control mechanisms that are still that are still deterministic if you try to run a dc motor and you turn it on for one second you have no many you have no idea how many times it's gone around and and you can gear it way down but you still don't know exactly how far you've moved with stepper motors as long as you don't overload them they have moved as many steps as you've clocked and and so it's it's open control loop you don't need an encoder on the shaft but you still know where the thing is uh for a unipolar stepper motor the control is trivial for a dual polar you actually have the possibility of building a software destroyable system and i'll talk about that in just a second a unipolar drive is is commonly called a six wire stepper motor where you've got a center tap on each of two coils in the magnet and then you've got the end taps and you want to turn on one or the other end tap to change the polarity on on either of the coils there is a uh datasheet that i reference here uh at ericsson which is a great introduction to stepper motor control i just uh swiped some diagrams from them and if you're if you're interested in building a servo i'd i'd recommend you go there and look at it if you're using a bipolar you have a coil it's a four wire stepper motor and you want to be able to to apply uh either you want to be able to reverse the polarity across the coil so what you do is you're building what's called an h bridge driver and if you look at this the alternate corners of the h bridge are controlled by the same bit so it's still only four control bits required for an h bridge but if you look at it you'll also notice a really nasty failure mode if if you turn on uh both sets of switches on any h bridge you suddenly have a a very low impedance path from vcc to ground and the thing will emit light smoke or fire depending on depending on how much power you're putting into it so what if you want more i o uh well then you may want to look at other parts what are you doing with an eight pin part if you want more i o but if you if you are some kind of sadist you can you can use serial serial to parallel shift registers and in fact there are some examples of this in really old uh really old led signboards where they actually control a a large you know multi hundred led array with essentially two pins by just shifting everything out into shift registers and then if you want your transitions on the shift registers to be clean make sure to use one with output latches and then it takes a third pin because you got a clock the output latch but it it you can chain these things together and have an arbitrary number of ios but the parts are so cheap for the larger parts you might as well just use a larger larger controller how do i blah for anything i have failed to mention here and there is an infinite number of things i fail to mention here hit the web uh if you if you search you'll be amazed that there's chances are if you've got a great idea someone else has already built it or at least has thought about building it also the manufacturer application notes as you may have gotten an idea from from my presentation provide a lot of good reference designs often if you look at manufacturers of parts that aren't the one you're looking at you're working on you will find someone who's doing it on some other part and then you can port it over to your architecture of choice or change parts depending on how agnostic you are you know maybe there's a reason they chose a pic or maybe there's a reason they chose an eighty fifty one or some other part uh or finally if you don't find what you're looking for create your own and please share it with the world because that's how the next guy who goes out looking on the web finds your project uh if you're looking for a starter a starter book the kit is the hardware you need the kit doesn't provide a a a good uh first order reference there i finally last year a lot of people were asking for a book and there's a book called get going with avr by peter sharp it's written in british so it's uh it's got a few it's got a few strange words in it but it's a really good explanation it starts at very low level stuff and you know it it will explain to you what binary is but it gets passed that by about page four and and then it really does get into some interesting some interesting applications to show you how to make good use of the hardware it's designed around a slightly different candle development board but you should be able to make the transition fairly painlessly uh do read the documentation for this stuff because there are some quirks to the stk 100 uh the the control device which is the there's actually a microcontroller on there that it uses to send the code to your device through it's basically an in-system program controller actually controls the the voltage that the processor runs at and took me the longest damn time to figure this out uh in spite of looking at the schematics i was really embarrassed that i could not figure out why the thing would run three times faster when it was in run mode than in program mode until i realized three three one megahertz 350 kilohertz this this sounds like the rc oscillator running at three volts duh also the ir the isp software requires intel hex files which is not the default of avr studio this was also the source of far more wasted time than it should have been for me so it's embarrassing but i admit it here to to remind you that make sure the files you're generating because i generated one hex file generated one output file and then had failed to save that change to the avr studio so i could never figure out why my code no matter how i would change it didn't ever get better and it turns out i was downloading the same image into the into the part repeatedly then chance for me to drink some water okay i like to close these with an inspirational message and one of the things i would say like any like any good project the hard part of these is getting started and this year i added the caveat that you should cheat by starting with someone else's work or or a trivial example uh and i i have some trivial examples i'm happy to give you uh i've got a very few minutes left in the talk so i'm probably not going to to do a demo of the dev studio it's it's pretty straightforward it's available online at the atma website for free i would encourage you to go take a look at it even if you don't have the starter kit you can at least play with the simulator uh start small and work up from there be willing to make make mistakes because that's like i said i've tried to share my mistakes here but if you do something stupid at least you will only do it once hopefully and then and then get involved join the community of developers there's a lot of people who are interested in this stuff and no matter how retarded your project is there's probably at least one other person on earth who thinks it's as cool as you do so to recap microcontrollers a different development opportunity gone over some of the characteristics of the avr specifically the at tiny eleven we've looked at a lot of example functions and then i've quit the fund it's just fun to tinker with these it's neat to make blinking lights uh and then now's the chance to win the development environment i'll go into qa mode in just a second but if you would like to submit feedback i would i would strongly encourage you to give me a feedback if you if you have a pen and paper if you don't ask that's the guy next to you please write down your name or handle if you win one it will be at the bellhop desk with your name or handle on it in an hour uh because i gotta read the project ideas uh tell me what i should change about this talk if if there's anything you would have like to see more of less of uh please tell me what what i could do differently next year if i if i come back uh what if anything you liked about it this is less important to me but i ask this merely so i don't take out something good uh and then the important question for getting the development kit is why do you want an stk 100 what's your cool project idea the feedback is important to me but the kits are awarded based on the project idea so even if you tell me i'm stupid ugly and i suck but you have a good project idea you will win a kit uh and like i said winners can pick up theirs at the bellhop desk out front it's the thing out in front of the uh it's it's outside where you can check your bags and i will just stick your name on it and check it there and uh and i'll try to post a list of the winning handles and i will give away any i don't give away here if you want to contact me uh my email address pking at pkscientific.com and the the subtle implicit plug for my not an agent jackets which i'm not selling it at the moment anyway uh the website for this talk is notanagent.com and the slides and some of the examples will be available on there shortly i'm also if you have other things you'd like me to add to the website please feel free to send them along there's an avr web ring i may or may not add the site to uh but there's a lot of project rings that you can find if you just look around it's it's it's a very fertile uh very fertile environment online so q and a uh are there any general microcontroller questions avr specific or uh or who wants to try and win win something with a project idea oh sorry yeah uh hold on yeah that's that's the information i'm looking for in terms of feedback uh was there yes yeah sorry you project idea a very small spam bar ip ip storm bot so his idea was an ip uh an ip packet spewer based on a microcontroller where you where you pre pre compute the frame and have it sitting in memory and have the thing hooked up to an ethernet controller uh hooking up to an ethernet controller is is a few more pins than we have here but but you could probably you could probably do it with uh a couple of eight pin ports what you've described in part is a peak is the pico web i don't know if anyone is raising their hand to mention this there actually is a uh an avr to um to an isa ethernet controller device it's not designed to spew out packets as fast as you want to it's designed to actually be a complete web server but uh let's let's let's get a uh an audience approval rating does does a a packet storm generator based on a microcontroller an ethernet chip married a married a development box yes no yes show of hands everyone who thinks you should get one everyone who doesn't clock rate problems but it might be running fast enough if you got a an ethernet controller with onboard memory to at least tell it send that frame again so for what it's worth i will i will uh at least concede that you could you could build it is is there anyone speaking uh in his in his defense a solution okay okay it's a it's a three wire interface to a hard wire uh hardware based ip stack did you say okay well so that makes it work so reference design for that available at i ready dot org so okay it sounds like it's going to work i i think i'm going to give it to him so hold on so could you hand that back yeah it's a big green box we can see it okay uh yes a single key keyboard a single key keyboard for going from morse code to at so that you can use it while driving or roller skating i i i think that's a winner yeah and and if you're really ambitious and want to stick four buttons on it you could do a nibble based quartet keyboard see the people in the back always get screwed you the guy in the white uh was that free geek is that is that a label or a command okay so okay okay he wants to build something for use at free geek which is a stepper motor control for a robotic arm to swap tapes in a in a tape farm because tape libraries are really expensive yes the lego mindstorm kid is is is a great way to build the mechanical portion of your design okay so so there's the trouble the trouble that leaps to mind is at least with the with the minimal i o you're gonna get one stepper motor so you're gonna have one degree of freedom which is a fairly limited robotic arm i'm i'm gonna be cruel and throw this one entirely to the audience and this time i'm actually gonna listen to what they say uh who thinks the the robotic arm control for a tape farm should get it and and not i'm i'm sorry submit a feedback form what yeah that's what he based for um and and another thing i would point out is if you get out of here and you've submitted a feedback form you still don't get one call up at mel and and sound either really smart or really pathetic and there's a good chance that that there's a good chance that they will send you one especially if you're a student asked to speak to the university liaison because they they do like to get these things into schools or if you can just say you're a student um okay the guy with both hands up in the gesture cap okay so it's uh an answering machine that calls out for you it's it's it's uh he's using dtmf and an external voice recorder chip to dial out and uh wait for the other end to pick up and record am i am i basically getting it right okay and it'll respond to to to uh dtmf tones from them a a a a a a social engineering or telemarketing tool okay uh throwing it to the audience does he get one oh i'm sorry hostile crowd all right uh i'm i'm just about out of time how much longer can i go okay so so we got the next speaker okay so i'm i'm i'm pretty much running out of time i'm gonna take one more uh and again the guy sort of tore the back in the yeah in the in the blue cap yeah uh could you speak up i i caught a link between a gameboy and oh okay using the link port on the gameboy advance and basically building glue between that and a pc okay so so would you would you be running i mean would you be using the gameboy uh would you be running games on the gameboy or using the gameboy as a terminal for the pc okay so so it's a a a development uh project for for basically the gameboy as as a uh as a console i don't know sounds kind of cool what's what's the consensus all in favor all opposed okay the hostile people are less are less adamant i think you get one uh can you come on up here at the end and uh if everyone could just bring bring feedback forms if you've got them up to me i'm going to wrap it up now so the next guy can speak but thank you very much you've been a great audience