The project
I play Dungeons and Dragons, and like any geek who plays DND i felt like making electronic dice (how clever and original?) with a catch, it has to be ultra portable and has to last at least the length of a standard gaming session on a single charge, it also has to be relatively cheap. I started this build last year around April time, and finished around May last year, i haven't really had much time to write lately so i've been putting off this post. Finally got some free time today, so here it is, my D20 Roller.
One resource i took well advantage of was Dorkbot's PCB service. After three separate revisions i settled on my final design, essentially its a micro (pic18f13k50) 22 SMD LEDs, two push buttons, and a super cap with all the appropriate passives on a 2x1" PCB.
The design:
So for this design i wanted to try and make everything as small as possible, which meant surface mount... everything. Personally, i prefer soldering surface mount, once you get used to is its pretty easy, just sucks when you lose stuff under the bench.
Laying things out when using surface mount is pretty trivial, put the stuff that's important for operation on one side, the junk that runs the show on the other side. Making it portable on the other hand, well that's another story. If you want portability, whats the most obvious choice for power? Battery of course, well aa's and aaa's are bulky and don't provide enough voltage for our LEDs, we could add a boost converter or some sort of power system, but that adds cost and space. We could also use coin cell batteries, these too however can be bulky and the holders can take quite a bit of space. My solution was to use a 1F 5.5v super capacitor.
The biggest advantage is they require no charge circuitry (a current limit resistor is plenty sufficient) They hold whatever voltage they're charged to (in this case 5 volts) and they pack plenty of juice to run a micro and some LEDs for a few hours (if you manage your power well). I provide a mini-usb b type receptacle for plugging into a USB port and siphoning off 5V, a current limit resistor limits the current so smart sources (like a PC) don't freak out when there's this huge current draw on the USB port. A smarter design would of been to add a LDO regulator, since then you can accept a wider range of voltages, this adds costs and takes up space.
The Front:
The Back
Now, as for the actual operation of the die roller itself; there are two thing i'd like the roller to accomplish:
Firstly, you need to be able to tell it when to roll a die, so we need a button for rolling dice. Secondly, we would like to be able to select the die type we would like to roll, this is our second button. Operation is simple, hit select until the the die type you want is highlighted, hit roll and you'll get a value within the range of what you want. Simple, and effective.
A note about random numbers:
Well first off, there is absolutely nothing random about this die roller, it is completely synchronous, if you could time yourself perfectly, you'll get the same value every time. But, if you do the statistics (i have) with this roller and an actual d20, you'll find they both have the same statistical distribution. So how do I do it?
1) Humans are slow and all push-buttons suck.
That is the key to this algorithm, in the background of the program I have timer0 cycling as fast as possible. When a random number is requested, I multiply timer0 with the range, i take the higher byte of the result and that is the "random" value which gets displayed.
The trick is timer0 is a 8 bit counter, with a range of 0-255, at 1MHz it overflows approximately 3900 times a second. The fastest human reaction time is around ~100 milliseconds, average is about 200. So before you can even react to your brain saying "hey i wanna push that button, timer0 has already cycled a few hundred times.
In essence you cant time yourself to get the same value twice, its humanly impossible, the error to your reaction time is much greater than the refresh rate of the timer.
Secondly buttons suck. Anyone who has used a pushbutton knows about a problem called switch de-bouncing. When a switches mechanical contacts come together, they dont make a perfect connection, they bounce against each other untill actually settling into a set state. If you have a scope, set it to single trigger and hook it across a switch, you'll notice have many times the switch "bounces" until it settles into a value. This article explains switch debouncing better than I could:
http://www.ganssle.com/debouncing.htm
The result of this, even if you could perfectly time yourself down to the microsecond, the time it takes the switch to settle, is random. This is actually the source for many random number generators, but I mostly use the first phenomenon, my switch denouncing algorithm is rather simple, I just kill some time before looking at the switch again, its simple and it works!
So yea, my algorithm is't truly random, but it's incredibly efficient (takes 4 instructions) and it generates results indistinguishable from a real die.
Dice in action
The software:
The software is pretty simple, and it's mostly incomplete. For the final iteration i wanted to run a finite state machine and work hard on implementing sleep features, but i never got around to it. The current code is pretty basic, but it works pretty well. Here is the state diagram for how i wanted to implement the code :P
Below i've attached a few things, the source code, the schematic, and a sample excel file where I've done some stats.
If anyone is interested in buying one to play with, I have plenty that need a good home and i'd love to have some funding for a better revision!
You can contact me by email at: jfkfhhfj@gmail.com
Source:d20v2.asm
Excel:d20.xlsx
Schematic:d20SCH.pdf
*************************UPDATES***********************
I've written a brief manual that those who bought either a kit or the dice themselves will find useful!
Manual: www.mcuplace.com/backup/d20/Electric%20D20%20Manual%20V1.docx
Also, I've written another firmware revision, which i will be updating and i'm in the process of writing one more!
Finally, i have another revision of the board, which i am getting printed, i will have these available as kits and assembled versions.
*************************UPDATES***********************
I have two new firmware revisions:
First up is version 4 of the firmware, if i remember correctly, this version puts the display as interrupts making the display a little cleaner and smoother.
d20v4.asm
This revision focuses on power saving and improving how inputs are handled. Inputs are now handled by interrupts and the main routine is completely freed up. Sleep is enabled and clock speed is reduced to 500khz.
d20v5.asm
Any questions! Email me!
I've been out of the game of writing blog posts for a while now, but i promise its only because I've been working on some cool stuff. I'm going to be making a few posts on simple concepts before i roll out some larger projects I've been working on.
Finite State Machines:
A very important part of digital/software design is being able to control how a piece of software "flows", how the user interacts the software and how it behaves to certain stimuli. Finite State Machines associate actions (things your software/hardware does) with a current state and an input combination (Mealy State Machine) or just the current state alone (Moore Machine).
Finite state machines involve breaking your problem down into states, in which each state; the possible inputs to your code produce different results. Its a very simple paradigm, but its often hard to abstract, so we'll start with an example.
An Example:
Lets say we have a digital clock, and we have 3 buttons, there are several features we'd like to implement. Lets say for now, we can only set the time, the alarm time and turn on and off the alarm. If we list all the possible actions we find we can:
-Turn on and off the alarm
-Change the hours of the alarm
-Change the minutes of the alarm
-Change the hours of the actual time
-Change the minutes of the actual time
-So and and so forth.
So now we can do several things; one thing we can do is to have a button for every action. This really tends to eat up hardware and makes the end result sloppy and very user unfriendly (imagine having a button for every aspect of the operation of a more complicated device) Plus we stated above, we only have 3 buttons!
A much better example is to use a finite state machine, in which each button will have a different function dependent on the state that it is in.
For simplicity sake, we will be implementing the design as a Mealy machine (where the action is determined by the inputs and current state.
State Diagrams:
A state diagram is a way of representing the states that a system can take, for our clock we have Three:
State 1: The idle state, in this state we simply keep time, the user can enter programming mode from here or turn on and off the alarm
Button 1 - Will turn on or off the alarm
Button 2 - Enters programming mode (goes to state 2)
Button 3 - Does nothing
State 2: Programming mode for clock/alarm HOURS setting
Button 1 - Does nothing
Button 2 - Sets the current HOURS setting (goes to state 3)
Button 2 - Increments the set value
State 3: Programming mode for clock/alarm MINUTES Setting
Button 1 - Does nothing
Button 2 - Sets the current MINUTES setting (goes back into run mode after)
Button 3 - Increments the set values
So here, we implemented all the functions we wanted to do, with the buttons we had, and we even had ability to add extra functionality to each state!
Here is the state diagram for such a system:
Why FSM:
Besides for making hardware much more simple, FSM also has some major code benefits. The most major is now we can abstract our design into actions. We assign actions to a state/input combination and call this action when the criteria is met, with this we can break down out code and avoid "spaghetti code." This allows us to segment our code into different parts, making things easier to work on in the long run. FSM also allows us to avoid duplicate code, for example, with our clock, we have to increment the minutes and the hours, with this FSM we can write one routine to increment a register and have the current state determine what register to increment. Here we use the current state as a parameter to avoid having two routines for one thing(a simple example). There are many benefits to using FSM in your code, below i included a FSM routine for PIC microcontrollers using lookup tables. The same routine can be written with ROM tables as well.
Some Code:
Below I've written very simple code for a PIC18F micro which allows you to implement a Mealy FSM into your design. It's very simple code and is completely stand-alone, so you can implement it into any project you wish!
cblock 0x00
INPUT
CURRENTSTATE
NEXTSTATE
TEMP
endc
org 0x00
PORTS:
;;;;;;;;;;;;;;;;;;;;;;;
;SETUP STUFF GOES HERE;
;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;MAIN ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
INIT:
movlw 0x00
movwf CURRENTSTATE
movwf NEXTSTATE ;Initialize States to idle
MAIN_LOOP:
call FSM
goto MAIN_LOOP
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This is the main FSM Code ;
;INPUT must be from 0-256 ;
;Each state calls the INPUT numbered ;
;Action from the lookup table ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
FSM:
rlncf CURRENTSTATE,w
call GETSTATE
movff NEXTSTATE,CURRENTSTATE
return
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Lookup Tables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GETSTATE:
movff PCL,TEMP
addwf PCL
goto STATE0
goto STATE1
goto STATE2
return
STATE0:
rlncf INPUT,w
movff PCL,TEMP ;Pics are stupid
addwf PCL
goto ACTION0
goto ACTION1
goto ACTION2
goto ACTION3
return
STATE1:
rlncf INPUT,w
movff PCL,TEMP ;Pics are stupid
addwf PCL
goto ACTION0
goto ACTION1
goto ACTION2
goto ACTION3
return
STATE2:
rlncf INPUT,w
movff PCL,TEMP ;Pics are stupid
addwf PCL
goto ACTION0
goto ACTION1
goto ACTION2
goto ACTION3
return
;State actions
ACTION0:
movlw 0x01
movwf NEXTSTATE
return
ACTION1:
movlw 0x02
movwf NEXTSTATE
return
ACTION2:
movlw 0x03
movwf NEXTSTATE
return
ACTION3:
movlw 0x00
movwf NEXTSTATE
return
end
Code Explanation:
Essentially, we have three system variables, NEXTSTATE, PRESENTSTATE and INPUT, when we call FSM the program uses PRESENTSTATE as an offset for a look-up table, calling the current set state. Once a state is loaded, we use INPUT as a offset for the action associated with a state. Thus we get an action that is associated with an input/state combination.
The major downside to this code is that STATE and INPUT MUST BE FORMATTED! If they are not, you will get erratic program behavior. (I.e. if there is 3 states, the first must be equivalent to 0x00, second, 0x01, and third 0x02, same for input)
This code can also be used with interrupts as well.
Micro’s come in many shapes and sizes nowadays, what was once very simple and specialized comes in all sorts of packages with all sorts of peripherals and features. Over the year I’ve put together a healthy collection of many different platforms and devices and I’d like to share my experiences with all of them. I do not claim to be an expert of all the controller lines below, I work mostly with PIC and have a good amount of experience with AVR,I also work mostly in assembly and do little high level programming. However, I still have done plenty of research and I hope I can offer advice that helps.
The way i'm going to do this review is go over several important categories when choosing a controller, generally I see this as most important to least, however some things are interchangeable depending on the target audience and device.
Support
What type of support do outside communities offer/how good are manufacture documents
Programmers (including emulation)
How easy is it to get your code on your chip and to make sure it works.
IDE(s)
How easy is it to write your code.
Languages (including assembly and high level)
What the hell are you writing.
Cost
How big of a loan will you have to take to finish your death bot of doom.
General architectural things will be discussed throughout the review as well in non particular order. (I.e. I will be going on rants and diversions)
With all that said, let the games begin!
Microchip PIC
The first series i will be going over is my favorite. Microcontroller’s Pic architecture is very intuitive and great for hobbyists. It’s a very minimalistic approach to microcontrollers. Everything about a PIC is simplistic, the assembly, the programing, and the IDE. There is very little which is a hassle to do. For beginners, I always recommend PICs since i feel they’re the easiest chip to get started with. The PIC comes in many different varieties including the PIC10, PIC12, PIC16, PIC18,PIC24, PIC32 and DSPpic. The most commonly used lines are the PIC16, mid end 8 bit processor and their flagship PIC18 high end series microprocessor.
Support:
Microchip has always been about the hobbyists, they offer great support and they have tons of great documentation. I personally feel their data sheets are some of the best. Always well organized and very well written. They always supply good code examples in both c and assembly so you spend less time trying to interpret what they’re saying and more time programming.
Programmers:
By far the PICKIT is the best programmer available. It will program all of microchip’s products without hassle, has on board power source, its USB and very portable. Also the pickit supports debug features.
IDE:
There is something really nice about MPLAB, it’s a small download, and it works, very well. It’s a very bare bones ide, but it gets the job done extremely well. Everything is intuitive and whether you’re managing a huge project or writing a small assembly code. MPLAB just works. Simulation is a breeze as well; MPSIM works great and has everything you could ask for. The biggest gripe with MPLAB is that it is rather old and some ancient features will come back to haunt you. For a while if you weren't building in a project file path lengths had to be kept under a certain number of characters, this wasn't fixed until recently.
Languages:
Microchip’s assembly is very minimalistic, on most lines it doesn’t support fancy indirect calling, or software controllable stacks or sometimes even branch instructions(PIC16 has no branch), but for what it’s worth, Microchip’s assembly once again just works. It’s very intuitive as far as assembly goes. Although most people hate the idea of a working register I feel it defiantly simplifies things since we can address all SRAM with it. (no specialized move instructions). Interrupts are simple since there’s only one or two vectors. Indirect referencing is done via a INDF register and a FSR register (one hold the memory address, other holds the contents). Higher level series such as the PIC18’s have indirect referencing to program memory through table instructions but they can be cumbersome. The biggest downsides to PICs are the segmented memory banks. Although on the PIC18’s this isn’t much of an issue when you write small programs,on larger projects it can be a real pain in the butt.
Again I’ve done little programming with C, but microchip offers a limited C compiler for most of their micro lines. As far from what I’ve seen, it works and it’s C, what more could you ask for?
Cost:
Microchip is great when it comes to cost, if you’re a student they offer a hefty discount on their programmers and will send you free chips through their sample programs. Otherwise prices are pretty standard.
Links:
http://microchip.com/ - Microchip's Home Page
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en019469&part=SW007002 - MPLAB download link
http://www.microchip.com/wwwproducts/Devices.aspx?dDocName=en023112 - Sample device page
http://www.microchip.com/samples/ - Link to sample program
http://www.microchipdirect.com/ProductSearch.aspx?Keywords=PG164130 - Pickit 3 programmer
ATMEL AVR
AVR is an industry standard microcontroller and regarded as one of the best. If you want simply the most powerful microcontroller in terms of functionality, AVR is for you.
Support:
Atmel’s support is second to none; if you can manage their website you will find documentation on everything. These guys have some of the technically best datasheets out there. With that said, technically best isn’t always the best. Their datasheets can be a chore to read through at times, but you defiantly get the full picture. Also unlike microchip whom include all their supplementary data in their device datasheet, things like instruction set summaries are supplement documentation and you usually have to hunt them down. (That’s what Google is for). AVR also has generally pretty large communities behind them (*cough* AVRfreaks *cough*) As well, they’re the go to micro in industry and university.
Programmers:
*bangs head on desk* the most frustrating aspect of any AVR chip is programming the damn thing.
There is no one programmer from ATMEL that will program all their chips. Some use ISP some use JTAG some use god knows what. The best thing to do usually is grab a JTAG programmer off of ebay and stick to an ATMEGA series chip. Most AVR microcontrollers support several programming options, this is nice however can bit a bit confusing at time (see above :P). The most common interface is ISP which is your standard In-Circuit Serial Programming.AVRs also support JTAG and other high voltage serial/parallel programming algorithms.(check out the data sheets) You can buy the 40$ AVR Mkii ISP and be able to program most if not all of their stuff. Programming through ISP can be a nightmare especially if you set the wrong fuses and brick your chip (very easy to do). Also ISP is very finicky with the programming speed and sometimes doesn’t work. I’ve even had issues with JTAG. Many times if the proper power up sequence isn’t followed the chip will refuse to talk to the programmer. This is by far the worst experience with AVRs but once you figure out the kinks of whatever setup you have, it’s usually smooth sailing (until you F$*#K up the fuses).
IDE:
AVR study hands down is one of the sexiest worksuites available for a micro. It’s just sooo shiny. And then it crashes. But really, AVR Studio is a great IDE and it’s the complete opposite of MPAB IDE. It’s a bit of a PIA to download and update (requires registration and multiple service packs) but it’s a fully featured modern IDE. One of the biggest problems with MPLAB is how ancient it feels and looks, with AVR Studio this is not an issue. As an IDE it does everything you could want it to do, everything is intuitive and when emulating there are just some really nice features that blow any other IDE out of the water. It’s a great IDE, just wish they would iron out some of the bugs.
Languages:
AVR assembly is both its greatest strength and weakness. In terms of sheer power, the AVR assembler is unmatched and the language is almost flawless. However, there is a steep learning curve associated with AVR and it’s assembly language. This mostly has to do with how it’s memory is arranged and mapped.
AVR memory:
Like all processors we have our CPU, Ram and Rom. In an AVR our program memory is 16 bit long and that constitutes our word length, this program Rom is accessible through our Z pointer. (and our LPM and SPM instructions). We can use program memory to both store instructions as well as ROM lookup tables. By using the .db(Define byte) and .dw(Define Word) we can load Rom with values at assemble time. This is mostly due to the power of the AVR assembler and ability of the Z pointer to indirectly reference program memory. This is an extremely useful feature.
Now the AVR RAM is a bit peculiar. The SRAM is mapped linearly and broken up into sub blocks. We have a General Purpose Register (r0,r31), I/O space (Our IO ports and Special function Registers) and our Data SRAM (everything else). Data SRAM is where we hold our system variables and where the stack pointer resides. Another really powerful aspect is that with AVRs we can use our PUSH and POP instructions to load the stack with system variables as well as control program flow.
However there is a downside to this implementation. Depending what sub block we are addressing, determines which instructions we use. We can generally address any space with our GPRs, however if were loading to IO space we use the in and out instructions, and if we load to data space we use lds and sts. Moving between GPR is done via mov. If you program a lot with AVR, this actually isn’t too bad, and preferred in some cases (prevents data corruption). However, it’s all a gimmick. The memory space is completely linear, there is no reason you can use an out instruction to load to a GPR to data space, it’s the same memory and in some cases you can(play around with it its fun)! The only thing preventing you most of the time is the assembler itself. Because of all these different instructions to do the same thing it can get rather confusing (SBIS, SBRS). For beginners, I do not prefer AVR assembly and I think at times it can be really counter intuitive.
With a PIC, the memory space is linear. Although we have a working register W0, there is only one Mov instruction (From and To W.) which addresses all RAM.
With that said, AVR assembly is great if you know what you’re doing, it’s extremely powerful especially with things such as software stack and its indirect referencing system, but for novices it can bit a bit much.
C, is a completely different story. One way which AVR blows microchip out of the water is through its C compiler and general C support. Out of the box AVR studio works with C and uses a GCC compiler so for those Linux guys they’re covered as well. This is where Microchip could learn from ATMEL.
Cost:
Here is another gripe I have with AVR’s. And it mostly goes back to programmers. There really is no one programmer that does it all, and because of this the costs associated with developing with AVR chips can be quite high. If you use the ATtiny line, you need an ISP programmer if you use ATmega you need a JTAG programmer and if you use anything else, well good luck. Although programmers can be chopped together easily, it’s nice to be able to buy something from the company that you know works (Instead of relying on Chinese clones). Also ATMEL’s sample program is almost nonexistent, you gotta buy all the chips you use, So no love for students.
With that aside, the costs aren’t tremendous, you can get an ISP programmer for around 40$, and the chips themselves are never more than a few dollars. However I wish ATMEL made more of an initiative to make things a little bit friendlier.
Links:
http://www.atmel.com/ - Main website
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail&name=ATAVRISP2-ND - AVR ISP Mkii programmer (for ATtiny Chips)
http://www.atmel.com/dyn/products/product_card.asp?PN=ATmega48 - Sample product page
http://www.atmel.com/dyn/products/param_table.asp?family_id=607&OrderBy=part_no&Direction=ASC List of all their products and features.
*This concludes the part of the article of the chips I actually know a bit about, please only use the following for reference*
TI Launchpad MSP430
This is TI’s attempt at getting back into the minds of hobbyists. This line is meant to be cheap affordable and no frills. The actual processor is built around a simple but powerful assembly language and has very barebones peripherals. TI released an evaluation kit for the MSP430 called the Lanuchpad which main feature is that it only costs 4.30$ and includes theoretically everything you need to get started.
Support:
There seems to be a good amount of support documentation floating around, and TI does a decent job of providing a good amount of documentation. Ti is really trying to make a push into the hobbyist market and offers a wiki for their launchpad product.
Programmers:
Programming depends on the device but for the value line, programming seems to be done via a serial interface. The launchpad evaluation board has a programmer and emulator onboard, so that should be all you need to get going. It will also program other MSP430 devices and not just the value line.
IDEs:
TI provides a link to IAR embedded workbench, which works, most of the time. It’s a decent toolsuite, but doesn’t hold a candle to dedicated suites such as MPLAB or AVR studio. (and it just crashed on me... $*$#@!!!)
Languages:
I haven’t had much time to play with the assembly, but from what I see, it truly looks very “modern.” We have a very small instruction set, but we also have some really powerful assembler directives that allow control of the stack and the ability to easily create ROM tables. It’s the best of both worlds. It’s a really nice step in the right direction with a nice core.
Cost:
4.30$, its cheap and for that it’s worth it in parts alone, if you can get an IDE to work with it, it’s a great chip which has a lot of potential.
Links:
http://processors.wiki.ti.com/index.php/MSP430_LaunchPad_%28MSP-EXP430G2%29?DCMP=launchpad&HQS=Other+OT+launchpadwiki - Launchpad Wiki
https://estore.ti.com/MSP-EXP430G2-MSP430-LaunchPad-Value-Line-Development-kit-P2031.aspx - Buy it
http://focus.ti.com/lit/ds/symlink/msp430g2211.pdf - Datasheet for value line chip
Parallax Propeller
This is quite possibly one of the most interesting processors I’ve ever come across. Parallax builds its processors around “Cogs” or miniature processor cores. Each processor has its own peripherals, shares IO and has access to main memory in a round robin fashion. A typical propeller has 8 cogs which can run at an impressive 20 MIPS, giving you a total of 160MIPS per chip. I’ve found that this chip is defiantly nice and very impressive especially coming from such a small company like Parallax, but I still have a hard time seeing exactly what its really good at. It seems the processor is much geared mostly towards game development (each core has its own video genorator).
There are also a few quirks you should be aware of. First off, there is no rom, so all programs are run off of the ram. Unless you have external EEPROM, every time you reset the chip your program is lost. Part of the startup routine includes looking for external EEPROM and automatically loading its contents into RAM. Another quirk is all the IO is shared via each processor core, not only that, IO control is OR’d with each COG, so things can get pretty messy. Really, you have to check out the documentation for this chip because it is very interesting.
Support:
Parallax is a very small company but their effort is the same as any other large companies. Their datasheet’s are pretty informative and they have just the same documentation you come to expect. Their website is pretty informative and easy to navigate and it’s a breeze getting everything you need to get up and going. However i've yet to find any real support online like there is for the other processor cores mentioned.
Programmers:
Programming of a propeller is done via serial and you can use any USB to serial adapter to do this. The one provided on their website is incredibly cheap and nice and compact. Because of the onboard bootloader, things are pretty no frills here.
IDE:
You can download the free Propellor Tool from Parralax’s website. This is a super simple IDE, again no frills, just what you need to get things working. The best thing about Propellor Tool is the sheer amount of reference code that comes with the IDE. You’ll have plenty of examples for both the SPIN language and assembly. Once you can figure out what you’ll use your chip for, you’ll have no lack of reference code to tear apart.
Languages:
The assembly is pretty standard and does everything you expect it to do however programming for a multicore chip is rather, interesting. Essentially each cog has its own RAM to store its program, while the main system RAM holds your main program. Using a SPIN command you can enable a new processor and you set the origin address of the assembly you would like it to load. On startup, the cog will take that code from the main memory and dump it into its ram. This usually takes a little while but allows each cog to independently run its own code.
If you don’t feel like dealing with that, you can use the high level SPIN language which is a combination of C, BASIC and some really interesting preprocessor directives. I haven’t used it much but you can do some really powerful stuff pretty easily. One of the interesting things is this processor support direct driving of a composite video signal and has instructions to generate text to any NTSC TV set. Pretty cool stuff for a little micro.
Cost:
The propeller is defiantly an expensive chip, but you’ll only need one and the chip is pretty much all you need to get going. If you want to grab a chip “programmer” and eeprom from parallax it’ll run you about 20$ shipped, which isn’t bad at all. So it’s an expensive chip, but that’s only because of the sheer amount of stuff you get in that little hunk of silicon.
Links:
http://www.parallax.com/ - Parallax main site.
http://www.parallax.com/propeller/ - General Information for the propeller
http://www.parallax.com/Store/Microcontrollers/PropellerChips/tabid/142/ProductID/332/List/1/Default.aspx?SortField=ProductName,ProductName - Buy a Propellor here
http://www.parallax.com/Store/Microcontrollers/PropellerTools/tabid/143/List/1/ProductID/398/Default.aspx?SortField=ProductName%2cProductName - Programmer here
http://www.parallax.com/Portals/0/Downloads/docs/prod/prop/WebPM-v1.1.pdf - Datasheet here
Arduino
Ardunino is a hit with the hobbyist community. Combine open source, with tons of support, tons of code, high level language and a super simple interface and Arduino is what you get. Arduino Is essentially a bootlaoder for the popular ATmega series of chips made by ATMEL. Arduino is nothing more than a wrap for AVR chips and a philosophy, provide the support and the hackers will come.
However, there is a dark side to Arduino, with the simplicity a high level language offers, it also brings forth hacktronics and some pretty shoddy engineering. If you’re someone with little electronics experience and you want something cool to play with, Arduino is for you. If you’re an EE who wants to learn microcontrollers I recommend Arduino AFTER you learn a more substantial core. Then you can use Arduino as a powerful development tool and not as a crippling toy. (Seriously what did you expect from someone who prefers assembly over C?)
Support:
Go on any major hobbyist website/hacker community and if you can’t find support for Ardunio you’re doing something wrong. Unlike the corporate driven datasheets and reference documents you will find hacker guides and tons of support from people who just love to hack. The Arduino website is chock full of information as well. This is the beauty of open source, the wealth of information.
Programmers:
Arduino is programmed via USB and usually when you get your Ardunio board it has a USB header on it which is all you need to upload your compiled programs.
IDE:
Arduino’s main IDE is a simple .jar program which is cross platform and extremely minimalistic. You write your sketches and compile them onto your Arduino and off you go. Nothing more is needed. Support for outside compilers is plentiful aswell. No matter what platform you run, you can program with Arduino.
Languages:
Arduino is prized for it’s C like language which is incredibly high level and very powerful. Open source libraries add everything from sound generation to image processing and everything between. Find your library, learn some simple commands and that’s all you need to get going with Arduino. If you actually care what’s going on, good luck(:P).
Cost:
A typical Arduino board will go for around 20$. Part of the Arduino philosophy is the idea of shields. Stack-able modules which connect to your main Arduino board and add features such as sensors and other peripherals. Shields can range from cheap to expensive depending on the functionality. Arduino is very affordable for anyone to jump right in and build some pretty impressive electronics.
Links:
http://www.arduino.cc/ - Main website
http://arduino.cc/en/Main/Software - Programmer
http://www.sparkfun.com/products/9950 - Arduino Uno, latest board
ARM
The holy grail of microcporcessors. These processors are in everything from your Iphone to your toaster. However you’ll never find an ARM chip. ARM simply licenses its processor core for companies to modify at their leisure. At its heart ARM is a general purpose RISC processor.
Support:
The first part of developing with ARM is finding a vendor and figuring out what support they offer. ARM platforms can range from elaborate to very simple and can be an evaluation kit or just a dip chip. Typically ARM processors interface through JTAG or serial and you upload binaries into the Rom.
Programmers:
Programming is typically done through JTAG or serial and varies from manufacturer to manufacturer (Hint, find one which works first)
IDE:
Varies from manufacture to manufacture, however anything that generates ARM binaries can be used (usually).
Languages:
Typically c is used when programming with ARM however an extensive assembly language is usually provided, I’ve yet to find an appropriate assembler.
Cost:
Developing with ARM can be a costly experience or it can be dirt cheap, it just depends on how much time you’re willing to spend banging your head against your desk and wondering why you can’t get the damn chip to work. Unfortunately, if you’re working with ARM you’re already provided with everything you need from whomever you’re working for. If you’re trying to work with ARM you have a lot of research ahead of you.
Links:
http://www.arm.com/ - main ARM website
http://mbed.org/ - Platform based around ARM Cortex m3 processor
http://en.wikipedia.org/wiki/ARM_architecture - Best source of information about ARM
http://www.st.com/internet/evalboard/product/250863.jsp - Really cheap ARM eval board.
X86
HAH!
http://www.intel.com/products/processor/manuals/
http://en.wikipedia.org/wiki/X86_assembly_language
Have fun..
So which is the best?
Honestly, there is no best, nor is there a worst. The best thing sometimes is just to pick a chip and just start working with it. What you should do is rather than pick the “best” or “easiest” chip, pick what works for you best. Also instead of learning what a chip CAN do, learn what a chip CAN’T do, because often times this is what will limit you the most. Understand a chip’s limitations so that when you come across them you know how to deal with them. In either case, happy programming!
I hope this article helped to shed light onto the subject of different processor brands out there. I know my knowledge isn’t complete so I hope anyone who would like to shed light on the caveats I skimmed over to do so. I will gladly add more processors to this list as I come across them and I look forward to updating the sections I glanced over. Even with these faults I hope this serves as a nice intro guide into the world of different processors.
Any questions comments or concerns, email me at Anthony.Tricarichi@sunysb.edu
It's been a while since i posted a project but i think its about time we make use of the tools we have.
I've always wanted to make a simple bot and it should be no surprise that i'm in the solar boat club, so i figured i would combine the two.
I have a small 5W panel in my lab; its too small to directly power any significant equipment and too small to let set on a desk and do nothing.
Usually panels like these are used to passively charge lead acid/whatever batteries. They provide around 12V and usually more than enough current to charge a decently sized battery in a few hours.
However, i wanted to do something different, i wanted to use the panel to power a small robot that had a backup power source. If i made the systems efficient, i wouldn't need that much power to make it move about.
The obvious choice for a backup power source is a battery, although this is true, batteries get a little pesky because you need charge controllers for them. I could design one, but they're not the most thrilling things in the world to build and design.
A better alternative is a capacitor bank. If i stick to my rule of only using minimal power to get about, a capacitor bank makes sense (especially considering how easy they are to charge)
The biggest problem with capacitor banks are the less than spectacular energy density they offer. Energy density is how much energy a medium stores per unit volume. A battery will give you much more energy per unit volume than a capacitor, thus for equal amounts of energy, you need a larger bank (significantly larger). Enter the super-capacitor
Super Caps:
Super-capacitors offer much superior energy density compared to an electrolytic capacitor. The capacitors I am using for this project are 5.5V 1Farad capacitors from: http://www.all-battery.com/. Which you can find here: http://www.all-battery.com/55v1capacitancecoinsupercapacitor-1-1.aspx
Props to all-battery.com for sourcing such cheap and powerful capacitors.
Lets compare the energy densities of our capacitors:
We recall that energy stored in a capacitor is given by the following formula:
We can see that the super-cap has a 100 fold increase in energy density over the electrolytic cap.
How does it do it?
Super-caps are really a hybrid between a traditional capacitor (Separation of plates) and a chemical battery. The key is with super-caps, to use nano-scale barriers to separate our charge, increasing surface area. We also use the space for the dielectric to hold charge (where the icky chemical part comes in). These two things combined help increase our energy density. There is one downside, super-caps sacrifice the ability to store large voltages (because of the nano-sized gaps), have increased leakage currents, and take longer to charge than conventional capacitors. However the ability to store much more energy is worth it.
So why super caps again?
Even at 100 joules per cubic centimeter, a typical alkaline battery dwarfs it at 1100 joules per cubic centimeter. However, the ease of charge and use of a super capacitor bank makes them very attractive. Also another thing to note. Capacitors deliver instantaneous current at rates much higher than a battery. Although a capacitor has lower energy density, the power density is much greater for a capacitor, it can discharge its entire energy contents in a fraction of a second while batteries take seconds to discharge completely. (This of an explosion versus a slow burning match)
The Goods
Each super-cap holds 12 Joules of energy at 5 volts. A typical AA holds about 1kj of energy. So to match the capacity of a AA battery i'd need on the order of 100 super-caps. (Not on my budget) Luckily, we don't need 1kj of energy for our robot, we only need enough energy to move the robot (not far).
For this bot we have 30 super-caps:
They came packed in a tray very well via first class mail. My order got here in a few business days (not bad for free shipping)
Just like electrolytic capacitors, super-caps are polarized. a word of caution with these however. Because of how thin the are, the manufacturer didn't leave enough of the marking band on to show the polarity of the caps (and the leads are equal length). However, it should be noticed that the side with the dimple is + and the flat side is -. Thus in my picture above, the capacitor is facing with the + terminal upwards.
The Pack
For this project we are putting our 30 1Farad capacitors in parallel for a 30F pack, this yields us 375 joules. A little more than 1/3 of a AA battery. Still quite a capacitor pack.
In this bank i have the capacitors in an alternating pattern to put them all in parallel like so:
+|--|++|-
Once you hook all the + together and all the - together, the pack is in parallel.
The backside of the proto-board looks like this: (to give you an idea of how i wired it)
The Idea:
Although 5V isn't a huge system voltage, its convenient for our micro's and motors. at 5v our motors are self-current limiting. They don't draw as much power at 5V as they do at say 12V, this is nice for current limiting. The biggest reason is that these caps are rated at 5V and i'd prefer one large parallel pack rather than a combination of series and parallel.
So, our source of energy is our solar panel:
Solar panels provide power by converting photons into electrons (kinda) Each panel has a few ratings. The open circuit voltage (Voltage between bare terminals) the Short circuit current (Current through a short) and the maximum power point.
For maximum power you want to keep the load of the solar panel at this voltage current point. Since i don't have money for a maximum power point system ill do one better, a switching power supply. Although not a MPPT system, with my switching power supply i can adjust the load on the capacitor bank to adjust the load on the panels, thus with some math and some good logic i can easily implement a sudo-MPPT system using a cheap little switching power supply chip.
I will be using the LM2674 buck converter IC to convert the panel voltage(anywhere from 0 to 18V) into 5V. The advantage of a switching power supply is that it works for a wide range of input voltages and is very efficient.
http://www.national.com/pf/LM/LM2674.html#Overview
(Thanks to nat semi for the samples!)
So that covers the power system, i'll be using a 5 watt panel to charge a 30F capacitor bank via a switching power supply.
The logic:
For the logic on this project i will be using a PIC18F. What model i don't know, but what i would like to do:
-Analog input for sensors (LDRs, color sensors etc)
-Serial In/Out for radio/infra red communications
-PWM out for motor drive
A potential candidate is the PIC18F26J50 i recently sampled a few and after checking them out i'll make my decision.
I also might be introducing the use of C to program. For robots C is ideal because we have to use complex data structures but we don't care how long it takes to process them.
Whats next?
I have to begin fabricating the robot's chassis and i will begin testing the power systems. I have to implement a charge controller on the Cap pack and begin designing the mechanics. So stay tuned!
Also any feedback is appreciated!
Recently I've had the wonderful opportunity to TA ESE 123 at Stony Brook University with Professor David Westerfeld. Over the past semester I've been working in the student lab, helping with their assignments and lab tasks. For the second half of the class however, the students were to build a digital clock combined with a USB charger. The project took advantage of AVR mirocontrollers for the digital clock part of the design. Being a freshman level class, it would be a daunting task to teach not only basic electric theory, but combine that with basic microcontroller theory combined with learning assembly. I decided it would be best to write a handout that went over all the basics of computation theory, microcontrollers as well as completely outline the hardware and software aspects of the digital clock. The resulting document is about 30 pages of insight, knowledge and experience all dedicated to the project this semester of ESE 123. The audience of this document is the beginner and expert alike, I hope that anyone who reads it learns something new.
Attached to this post is the full handout, it introduces a new line of hardware for this blog, the AVR series of microcontrollers. The specific chip used in the project was the ATtiny48 microcontroller. I am also attaching the full commented code.
Get the full writeup here: Write Up
Grab the code here: Code
*Note, the code was written by Professor Westerfeld and cannot be used without his consent.