Interface Prototyping

Programming

While working out which serial interface to use between the two microcontrollers, it would be nice to have a PC side program running. What this program would be doing is reading data from the mega328. It would also be useful in debugging the communications between the 2 micros and the computer. Now, a terminal program could be used, but the data would just displayed as ASCII characters. Reading and understanding the data (especially fast data) could be difficult. This is where a GUI interface comes in, it allows a graphical interpretation of the data.

We can prototype electronics, but what about prototyping software? Is it possible, and what about a GUI? It turns out that software prototyping can be done, though it does require some learning. I was looking around, trying to figure out how to program a GUI interface. Since I use Windows 7, I knew I could use C# or Visual Basic. The problem would be the learning curve of the software and the limit of only working with Windows 7. Some people use Mac OS X and others use Linux, so I was looking for something platform independent. So the idea is to use Open Source software to develop the application program came to mind.

The requirements for the software are: easy to learn; tutorials and other reference materials; open source; and OS independent. I program my micros in C and C++, and I know a little Java so I would like something similar. Two languages that I plan to use for rapid prototyping are Processing and Python. Both of these languages allow me to build applications quickly. Processing is the IDE, software, and the language. It is based on Java, but makes coding a GUI much easier. Python on the other hand is just a language, but getting and using an IDE for development is easy.

So while I am developing the software for the communications, I will also be working on software to interpret and graphically display the data on a computer. Until next time, check out the Processing and Python web sites.

Schematic Capture

The Software

It is time to start the schematic. There are many tools out there for drawing your schematic. Some are very expensive, while others are free. Here is a small list of schematic/PCB design programs. The ones I am talking about here are ones that I have used before.

Eagle

I use Eagle from Cadsoft for schematic capture and PCB layout for most of my designs. You can download the freeware version which limits you to 1 schematic sheet, 4″ x 3.2″ board size (100mm x 80mm), and 2 signal layers (top and bottom). This is good for most small hobby boards. The freeware version cannot be used for commercial purposes. The next version is the is Eagle Lite which has the same limitations except you can use it to make commercial products. Eagle Lite sell for $49. Then there is the non-profit version, which sells for $125. Again you cannot use it for commercial boards but you do get 99 schematic sheets, 6 signal layers, and board sizes up to 6.3″ x 4″ (160mm x 100mm). Eagle Standard has all the features of the non-profit version and allows you to use it for commercial purposes. This version does up the price tag to $747 for schematic, layout, and auto-router. The full unlimited version is Eagle Professional. Like I said there are no limits to board size, number of schematic sheets, or signal layers. This one is double the cost at $1494. The thing is I bought the Pro version several years ago and did not pay this much even including the upgrade to the latest version. I guess everyone is increasing their prices. As a side note, this program is considered semi-professional PCB design software.

PCB Artist

PCB Artist is a freeware program provided by Advanced Circuits. Even though it is a free program, I think it is a good program. You can do everything in PCB Artist that can be done in Eagle. The only difference is some schematic and board design features are easier to use in Eagle. Artist has a large parts library, I think even bigger than Eagle. What is really nice is that the output files, for making the PCB, are already formatted for Advanced Circuits (PCB production company). That seems logical since they are giving you the program. It does output standard Gerber files if you wanted to get your board produced by someone else. Did I mention it is free?! Now I have not tried Advanced Circuits PCB service, but I plan to. I want to see their price, quality, and speed of delivery as compared to Sunstone.

PCB123

PCB123 is software like PCB Artist. PCB123 comes from Sunstone Circuits, another PCB production company. The program is free, comes with an extensive parts library, and can even search Digikey for real-time parts availability. There is even a real-time display showing the cost of the board you are designing. Of course this is the price from Sunstone, but that is to be expected. In the past the program was limited and hard to use. Sunstone has been working on the feature set and ease of use to make the program more accessible. With their new version 4 I think they have done a good job. Here is the only issue, you do not get Gerber files. The file the program makes is only for Sunstone so they can make your board. This is not a huge issue as they are giving away a pretty good program and giving you reasonable PCB prices along with it. You’ll just have to decide if it is for you. Personally I order my small run prototype boards from Sunstone as I like the quality and speed of delivery.

Altium Designer

What can I say – this is the full professional package with a price to match. Altium Designer starts at $5000 and can go up from there. What do you get – everything! Schematic capture, PCB Layout, auto-router, auto-component placement, SPICE simulation, signal analysis, FPGA programming environment, microcontroller programming environment, SQL parts database, and can link with your inventory system. It even does more, but I am not going there. Just remember this is what many professionals use at work. I forgot to mention that $5000 is about half of some other companies professional software. I have used it at work, but I cannot afford it for home hobby use.

Coming up

I am going to cut this post in two. I was going to talk about the power supply and show the initial schematic, but I think splitting it will make it easier for people to digest. If you want to know about the software you can read this post, otherwise you can just skip to the next to see the schematic.

Final Design Ideas

Microcontrollers

Atmel microcontroller atmega328

An Atmel ATmega328 microcontroller

Like I have said from the start I will use the Atmel mega328 as the main controller and a tiny24 as a slave micro. When I started looking into the tiny24 a little closer I noticed that 2 of the timer output pins are also 2 of the SPI port pins. I had originally planned to use the SPI port to talk between the mega328 and the tiny24. If I am using the timer outputs, then that will cost me the SPI port. There are some other tricks I can use, like using the timer to generate an interrupt to toggle I/O pins high and low or running a super loop and toggling the output bits based off the timer count. I will have to figure this out soon so that I can draw the microcontroller section of the schematic.

For those who do not understand what I am talking about, the SPI port is a serial port that uses 3 to 4 I/O pins. The formal name is Serial Peripheral Interface Bus. It is used on the circuit board for communications between a micro and support chips. My original plan was to use the timer to generate the 38kHz for the IR LEDs and use the SPI port for transferring the sensor results back to the mega328. That is why this becomes a problem.

Sensors

infrared sesnor

Panasonic PNA4602M

Since we are dealing with a robot that is going to compete in mini sumo, the I need some way of detecting the opponent. The standard sensor in use is a Panasonic PNA4602M. The sensor detects IR radiation modulated at 38kHz and outputs a high signal if it receives such a signal. So I will use the tiny24 to blink some IR LEDs at 38kHz and a few more pins to read the outputs of the PNA4602Ms. The only thing to watch out for is the PNA4602M is sensitive to noise on its power lines, so you need to add 0.1uf caps across the power and ground pins. This will help cut the amount of false positive detections. Also by only turning on 1 IR LED at a time you will reduce false detections.

Sharp also makes similar detectors to the Panasonic unit, except they expect the modulated signal to only last 600uSec. After which it expects to not detect any modulated IR for another 600uSec. This makes this detector a little more difficult to use, but it does have higher immunity to false detections. So I am going to use the PNA4602M, you can decide for yourself if you want to use the Sharp sensor. You will have to look up which Sharp GP1UX series sensor you would want to use..

Motor Driver

Texas Instruments dual motor driver chip

Texas Instrument SN754410 driver

I have selected the SN754410 as the motor driver chip. Along with the driver, I will need a 74AC14 hex inverter chip. This chip will allow me to use simple sign magnitude motor control instead of locked anti-phase control. I know the 754410 uses bipolar transistors which will drop some voltage across the transistor junction, but the easy of use is why I selected the chip. What I can do later, if I feel like it, is design my prototype daughter board with an upgraded motor driver circuit. The 754410 does not come in a surface mount package, but that really won’t cause problems with the PCB design. Again even if I decided to make this a kit, all the parts would be through hole. Since I like to build circuits, I will make a through hole and a surface mount version for myself.  I will leave the decision up to you of which version you want to build.

Power Supply

The power supply is going to be built using a few extra components. This is a robot brain that I am going to be experimenting on, so things can and will go wrong. I am going to add in a little extra protection. Before power gets applied anywhere a P-channel MOSFET is going to provide reverse battery protection. Once power has been regulated down to 5 volts a Zener diode rated for 5.6 volts is going to protect the circuit from accidentally receiving full battery voltage. What about a fuse you ask? Well I plan to put a fuse inline with the battery pack. Rating the fuse is going to take some work. I don’t want it to blow every time the motors start-up, but still need to protect the electronics. So I will just have to do some research.

Other Electronics

So what else am I going to put on the board? I am going to have 1 diagnostic LED for each microcontroller, and an LED for the power supply to let me know it is on. Then there is that audio circuit I was talking about. After looking over all the stuff getting mounted to the board, I have decided to simplify the circuit down to the LM386 audio amp chip and support components. It will still work, just the quality of the audio will be less than ideal. That is ok, the robot will still beep with the best of them.

Next Issue

Well this turned out to be longer than I thought it would be. Next time I will go through what software I will be using for schematic capture, a preliminary parts list, and I will show you the schematic of the power supply section.

Software Tools

Software, Languages, and Tools

This time we are going to look at some of the software, languages, and programming tools for the AVR. This will finish up my overview on the AVR. My next series of articles will be on the new robot brain board that I plan to design and build. The board I am designing will be for Mini Sumo, but could be used for other projects.

Atmel

Atmel again you say, ha! When it comes to AVR development, everything starts with Atmel. Atmel provides a nice tool called AVR Studio. AVR Studio is the IDE (integrated development environment) you use for assembly language and higher level programming. What is nice about AVR Studio is all the features you get with it. An example would be simulation. Write your code, run the simulator, and watch the bits toggle. You can even change the I/O bits to simulate external devices connected to the AVR. One of the features of AVR Studio is that it will link with WinAVR (a toolchain for compiling C/C++ programs). This information has changed somewhat recently. With AVR Studio version 4 and before, you had to install WinAVR separately. Now with Atmel releasing AVR Studio 5, WinAVR is part of the software.

Basic

Where AVR Studio is a tool for coding and testing your program, BASIC is a language. There are a few options when programming in BASIC, and the options come with a nice IDE similar to AVR Studio. I am only going to talk a little bit about two choices, but just do a search and you’ll turn up several options.

BASCOM from MSC Electronics is one of the most popular choices for programming AVRs’ in BASIC. You get a good development environment, with the ability to download your code from within the tool. BASCOM comes in a free 4K code limited edition, and the full tool for $120 US. Download the demo and give BASCOM a try.

mikroBasic from Mikro Elektronika also has a BASIC compiler (yes compiler not interpreter) for the AVR. Again, Mikro provides a full IDE for developing your code. Mikro provides a free 2K code limited version along with a $149 US paid full version. I have not heard much about this program, so I would suggest you do some research before purchasing.

C

When you get to the C programming language you have many more choices. You can go completely free to full professional with the price tag to match. We are going to work our way from cheap (not because of features) to expensive.

WinAVR

WinAVR is the defacto standard when you are talking free C compilers. WinAVR is based on AVR-GCC, which both are based off the GNU compiler toolchain. For Windows PC users you’ll be using WinAVR, while for Mac OS X or Linux it will be AVR-GCC. Don’t worry, they are the same. WinAVR and the rest of the tools are just packaged into a nice Windows installer. There is tons of information out there on WinAVR. Take a look at the WinAVR web site, then hop on over to AVR Freaks for more info.

Here is a short blurb on WinAVR. Programmer’s Notepad comes bundled with WinAVR. PN is a simple IDE for programming in different languages. Again with Atmel including WinAVR in their latest version of AVR Studio, you don’t even need download anything else.

Make Hack Void

Since WinAVR was picked up by Atmel, another group of programmers decided to take on building a toolchain like WinAVR. Make Hack Void is a web site that releases a replacement for WinAVR. They call their tool MHV AVR. I am in the process of testing it to see if it is a good replacement.

Arduino

Another free option that I know of is Arduino. Arduino is hardware, but they also provide free software for programming the Arduino. Arduino is also the programming environment. Arduino is based on Wiring (which itself is based on Processing) which is a simplified C/C++ IDE. It was designed for people without prior microcontroller programming experience. Take a look at the Arduino web site for more information.

Low cost C compilers are not low-cost because they lack features. For the most part the only real difference between high cost professional compilers and the low-cost version is code density. The pro packages can optimize the code better. Dense code does hurt you in the debugging stage as your lines of C code don’t match up to the assembly language listing.

Imagecraft

Imagecraft makes a nice low-cost C compiler that compares well with the more expensive options. Imagecraft’s product is ICCAVR.  The IDE is full featured including an applications building tool. The only thing is the interface looks like it came out of the Windows 16-bit days. The interface is slated for an overhaul in the near future. They have a fully working demo for 45 days. After the 45 day demo period, the program is reduced to 4K code limit. You can also purchase a non-commercial license for $49, and full-blown license for $249. Take a look at their website, as they offer compilers for different microcontrollers.

Mikro Elektronika

Mikro Elektronika also provides a low-cost solution for programming AVRs’ in C. Again, this tool provides a full development environment. The interface looks current and seems to have many project management features. I will say I have no experience with this compiler as of yet, but I have downloaded the full functional (but code limited) demo and intend to try it.

CodeVision

CodeVision is another choice in the low-cost arena. This compiler I do not know much about. They have light and standard versions that range from $127 to $211 US. In this case I will say use at your own risk. The IDE looks nice, but I know nothing about its features. It looks as though it is only a little more advanced than Programmer’s Notepad.

When we get into the professional packages, the pricing really jumps. Now you’ll be spending several thousands of dollars to purchase and several hundred dollars in maintenance fees. Since this is way out of the range of most hobbyists, I am just going to drop names. If you want to take a look, check out their web sites. The big name in AVR development is IAR.  Take a look and see what you think.

C++

It is possible to program the AVR in C++. C++ will take up more code space, but if you are careful it can be done. I am not going to do a full write up as before since most of the tools are the same. Free software again is WinAVR, MHV AVR, and Arduino. They allow C++ programming. Arduino does have some built-in functions that do make life a little easier. As for pro packages, look at IAR. I am not sure if other vendors do C++, but as I always say “just look at their website”.

Finally…

We made it to the end. As you can see there is more information out there than I can fit into a blog. There were a few things I left out of this last article. There are a few free IDEs that I forgot to mention. The one that I use is Eclipse. I plan to show you how to set up a free development environment using Eclipse in a later series of articles. I will add other tools to my Eclipse installation that will make it look and act like a professional package costing thousands of dollars – all free!

So see you next time when we start designing a new brain for my robot.