ArdIAC – Arduino Illustrative Aid to Computation

Way back in high school, I received a copy of the CardIAC computer simulator (https://en.wikipedia.org/wiki/CARDboard … omputation, there is also a great description with programs and an emulator: https://www.cs.drexel.edu/~bls96/museum/cardiac.html) from my math teacher. The CardIAC is Bell Lab’s Cardboard Illustrative Aid to Computation, a great introduction to how computers operate on a very low level.  Earlier I had been introduced to the school district’s (School District 214, in North-Western Chicagoland) HP-2000 computer and taken to it like a duck to water. In learning HP’s TSB (Time Share BASIC) I wrote my first emulator, a CardIAC emulator. Unfortunately, I have no memory of the user interface, only the background. Over the past several years, I have wanted to recreate my emulator, but in hardware.

A while back, I ran across the Kim-Uno (a 6502-based KIM computer simulator: http://obsolescenceguaranteed.blogspot. … o-uno.html) which stirred my creativity. I recently ordered an Arduino Nano (http://www.banggood.com/ATmega328P-Ardu … 59231.html) and several Nokia 5110 LCD modules (http://www.banggood.com/5Pcs-LCD-Module … 45893.html.) Time to play.

Prototype001

Here is my prototype as of this point
(note that I have not done the initial wiring yet.)

I prefer to do my prototyping off of a CAD drawing, and then when everything works, it already matches up and so I can just have some boards manufactured.  So, this is what the ArdIAC drawing looks like to this point.

Simduino-001

The ArdIAC, so far. The bottom portion is an existing hex keypad, that I designed for my store.

The next step is to get the prototype LCD wired up, and then load some testing code to display something on the LCD.

Since the CardIAC only has 100 words of memory, and the Arduino Uno has 2K bytes of RAM, this will be enough to simulate the CardIAC.  However, I am thinking of adding an external serial RAM, so that this thing can simulate/emulate more complex systems.

Ideas? Question? Suggestions?

Expanding Your 2313 Experimenter System

In the book Introduction to Microcontrollers, I alluded to the ability to expand your 2313 Experimenter System (2313ES.)  On page 70, I showed a drawing of a breadboard attached to a 2313ES.  This week, we will go ahead and expand our 2313ES with a medium-sized breadboard – this will provide pretty decent expansion capability, but will allow the 2313ES to keep it’s portability.

To start off, you will want to pick a piece of plastic, or something, to use as a base.  In this example, we use a plastic base plate from Tamiya (http://www.wrighthobbies.com/product.php?productid=62&cat=16&page=1 – Eddy was thinking about offering the base plates separately, write to him and ask him about this,) but you could use just about any

This is actually a cutting board which was included with a cheese & cracker gift set purchased years ago. It will make a nice little development kit base.

This is actually a cutting board which was included with a cheese & cracker gift set purchased years ago. It will make a nice little development kit base.

flat-surfaced item.  Consider a small piece of thin plywood, a small piece of metal, or plastic, cut from the side of something from the trash, a small clipboard without the metal clip, or maybe even the inside of the lid of a plastic pencil case (back-to-school specials abound right now.) The important thing here, is to just make sure that your kit and breadboard (and battery box, if you want it,) will fit.

Once you find your base, peel the backing off of the sticky foam tape on the bottom of your breadboard, and stick the breadboard into place on your base.   Next you can solder two small pieces of jumper wire to the two power rail holes on your 2313ES printed circuit board 2313ES Exp-1(PCB.) Now, peel the backing off of the 2″X2″ foam tape that was included in your kit, and use it to mount your 2313ES near your breadboard.  Then plug the the power wires into the power rails of your breadboard (you could also use the left-most holes in the power rail female headers, of your 2313ES, for a less permanent solution.) Finally, mount your battery box (if you want it) to your base; make sure that you leave access to both the sliding door and the power switch, as they are on opposite sides of the battery box.  Also, if your breadboard has dual power rails on the top and bottom, you will need to connect the two +V, and the two Gound, rails, as we have on the right side of the photos.

Once you get your 2313ES and breadboard mounted, you will want to test the connections 2313ES Exp-2to make sure that everything is wired up properly. You can use a simple “blinkenlight” (http://www.instructables.com/id/Ghetto-Programming%3a-Getting-started-with-AVR-micro/#step6 – this is the same as the small test device that you built while testing your 2313ES,) to test power; place the negative lead (the one with the resistor) into the ground power rail, and the positive lead into the 2313ES Exp-3+V power rail.  Place the power selection jumper over the Pgmr jumpers and connect the programmer and the LED should light up.  You can also simulate the blinkenlight by just plugging an LED and resistor in to the breadboard.

If the LED does not light up, there is a bad connection between the 2313ES and your breadboard.  Remember to disconnect power before changing any of  the wiring, here. Recheck the wires connecting the two pieces.  If you soldered the wires to the holes in the 2313ES, then disconnect one from the breadboard and temporarily replace it with a jumper plugged into the 2313ES’ female header for the power rail.  Connect power again and check that the LED lights up.  If it does, then the wire that you replaced is bad; recheck the soldering and maybe replacing the wire.  If the LED still does not work, then remove power, temporarily replace the other wire and check again.  Again, do not forget to jumper the top and bottom V+ and Ground rails together.  LESSON LEARNED – When I first connected this breadboard, I accidentally connect both V+ and Ground to the same rails – not good!  Fortunately, this system is pretty durable.  The USBASP (or the USB port on the computer) detected the short, and just shut down the power to prevent damage.  As soon as I corrected that goof, everything worked again.

Once you get the LED to light, you may want to permanently mount the LED and resistor.  2313ES Exp-4Take a look at the photo for how you may want to do this.  Once you get the parts placed and working, you will want to cut the leads short (make sure that you remember which LED lead is for the cathode (negative.)  This will keep the LED and resistor neat and out of the way – in fact, you may want to use a tiny bit of glue, or epoxy (or hot glue) to 2313ES Exp-5keep them in place, it will be more durable that way.

This will provide a quick, and easy, pilot light, to let you know when your 2313ES has power applied.  Just remember that the LED does draw power, even if you are not running any useful program on your Tiny2313 chip.  This is not a lot of current, about 20mA, but it will help to drain your battery, if you are using the battery pack.  Just make sure that you turn off the power switch on your battery box when you are not using the experimenter kit.

Next week, we will start adding stuff to the breadboard expansion.  Stay tuned.

Developing New Products

Today, we are going to start looking at developing new products.  We will begin with getting to know our development kit (starting off with the 2313 Experimenter System.)  This new product was developed, specifically to allow engineering students to learn about microcontrollers, and how to use them.  As an advanced part of learning how to use microcontrollers, you can use the 2313 Experimenter System to develop new products.

2313 ES

The 2313 Experimenter System

The 2313 Experimenter System (from now on, let’s call it the 2313ES for simplicity) provides you with an AVR ATtiny2313A microcontroller, from Atmel, a programming port, three LED lights, two push-button switches, a speaker, and two servo-motor/sensor I/O ports.  In addition, the 2313ES provides the ability to draw it’s power either from the programming port, or a battery – complete with protection from reversed polarity.  There are also two power strips available, to easily provide ground and +V connections for your circuits.  Right next to these power rails, there are additional drill holes to allow you to easily extend power to an optional breadboard.  Our first “product” will not be using the breadboard (don’t worry, we will expand the 2313ES later on.)

The Product
A couple of my kids have had to have braces.  Every kid who has had braces, has heard the Toothbrushing Timeradmonition from the doctor to “make sure that you brush for three full minutes.”  Of course, when you are doing something that you don’t enjoy, time seems to crawl.  It is very difficult for a kid (of any age) to brush for a full three minutes – it seems to take forever.  So, our first product will be a simple tooth-brushing timer.  The requirements for this product will be pretty simple: start timing and let the user know when the three minutes have passed (by the way, you could also use this for a “time out” timer for young children for when they misbehave.)

The doctor’s office gave both of my kids a simple “hour glass”-style sand timer for them to use, and it does the job; however, I think that it can be improved.  That is what we will work for in this development project.

Developing The Timer
Let’s start off with the hardware side of the timer. Take your 2313ES and make sure that the programming cable is not attached and that the battery box is not turned on.  Now, run a 2313ES - LED & Speaker Connectedshort jumper wire from the the second from the right-most hole (or pin) on the Tiny2313 socket, labelled PB0, to the right-most LED (like the blue wire in the drawing to the right.)  Take a second wire and connect PB1 to the speaker terminal (as shown in yellow.)  This will give us all that we need to start developing the program (the firmware) for our new tooth-brushing timer.  That is one of the beautiful things about development kits (or dev kits;) it is really simple to set up your system for developing new products.  In fact, that is where the dev kit gets it;s name.

The Program
The program that will run our timer, is called the firmware – this is software that is always there, and cannot be easily changed (like you would change from a word processor to an internet browser on your desktop, or laptop, computer.) Normally, you would not want to change the program on your program on a control system.

We will develop our firmware in MCS Electronic’s BASCOM-AVR, as we used in the book, Introduction to Microcontrollers.  Launch your BASCOM program and enter the following:

‘ Title: Tooth-brushing Timer
‘ Author: Art Granzeier, Granzeier Consulting  – Use your name here.
‘ Date: 13 Oct 13  – Use today’s date here.
‘ Description: Delay for 3 minutes and then alert the user.

‘ Configuration Section
$regfile = “ATtiny2313a.dat”     ‘ Specify the micro
$crystal = 1000000                    ‘ Frequency for internal RC clock
$hwstack = 32                             ‘ Default – Use 32 for the HW stack
$swstack = 10                              ‘ Default – Use 10 for the SW stack
$framesize = 40                          ‘ Default – Use 40 for the frame space

Config PortB = Output

‘ Main Program
‘ Pause for 3 minutes

‘ Alert the user
‘ LED on

‘ Tone from speaker

End

(Note: don’t try to copy and paste from this page – the HTML code will make BASCOM cry.  Instead, use the .BAS file that I have posted here: http://files.granzeier.com/Downloads/Toothbrush.bas.  Read through the rest of this post first, because this .BAS file contains all of the additional statements as described below.)

This will provide the frame, or skeleton, for our new program.

Now, we need to start the program by counting up for three minutes, when the timer is turned on.  As we covered in the book, you could use the waitms command to wait for a specified number of milliseconds (thousandths of a second.)  Looking through the BASCOM manual (you did download that when you installed BASCOM, right?) we find that there is another command, related to the waitms – the wait.  Looking at this command, we see that this will wait for a specified number of whole seconds.  For longer delays, this is what we need.  Under the comment about pausing for three seconds, type the line:

Wait 180

This will cause the program to pause for 180 seconds, or three minutes.

Next, we need to notify the user that they have been brushing long enough. Under the LED on comment, under Alert the user, type this line:

Set PortB.0

This will cause the LED to turn on, just like the first experiment in the Intro book.  And, now, since we want the user to be notified, even if the kid is not watching the timer, we would add the following line under the tone comment:

Play PortB.1, 500, 125

That is all that we need to meet the initial product requirements for our new timer.  Make sure that the power selection jumper is set to power your 2313ES from the programmer.  Next, take your programmer and connect it up to your 2313ES and plug it into your computer.  Compile the timer program and download it into your ATtiny2313.  Now, unplug the programming cable from the 2313ES, and (with the battery box turned off) switch the power selection jumper back to the battery position.

Now, turn your battery box switch on, and wait.  Remember, that three minutes is a long time, when you are just watching and waiting (remember, “a watched pot never boils.”)  About three minutes after you turn the timer (err, your 2313 Experimenter System) on, the LED will light, and a short tone will come from the speaker.

Well, congratulations on developing your first product!  Of course, this is really the very beginning of your development process.  What you have here is more like your first, rough draft of a term paper; it will still need some clean-up work.  We will cover that in our next blog post.  Until then, play with the program and see what happens when you change things in the program.  Note that the sound statement has three parameters: the first is the pin on which you want the sound pulses to appear; the second is the duration (actually, it is the number of pulses — it will change depending on the tone;) the third parameter is the tone (again, it is not really the tone, but rather the delay between the pin going high and low.)  Take the numbers that I have presented and play with them to get a sound that you like.  Also, since three minutes is a pretty long time when you are experimenting, you will want to change the delay time in the wait statement.  I used five seconds, so that it still seems to be a timer, but it is not a painful wait. Just make sure to put it back to three minutes before we continue next time.

Until, next time – keep on learning.

The Ultimate RISC Gets Hardware

(In a nasal, Andy-Rooneyish tone) “Have you ever noticed how some things just stay new?”

Well, Prof. Jones’ paper is like that.  It seems that every time I look at the paper, I see something new.  Take for instance figure 2, the block diagram: I have been going over that paper on-and-off for a few years.  Even so, I came up with the block diagram that I posted earlier.  Hmmm, it seems that when I took another look at figure 2, I just tried fitting some 74LS00 series chips in place; what do you know?  They fit!  I looked at the buffer (the triangle pointing up, on the right side of the diagram) and thought that it could be a simple tri-state buffer; perhaps a couple/few 74LS241 Octal 3-State Drivers?

Next, I looked to the left a bit and noticed that the rectangle right next to the driver was really a latch, such as the 74LS373 or ‘374 (now what is the difference between those again?  Oh yeah, one is edge triggered and the other is level triggered.)  Whoa, those latches in Prof. Jones’ figure 2 look mighty close to these chips.  In fact, with the exception of the triggers being inverted from Prof. Jones’ design, and the fact that the address latch is not buffered (just keep the output enabled for that one), those chips will work admirably.

After looking through my old, handy-dandy 7400 TTL list (http://en.wikipedia.org/wiki/List_of_7400_series_integrated_circuits), and doing a couple more replacements, I came up with this:

Notice that, as I’ve mentioned, the PC, ADDR and TEMP latches are inverted from Prof. Jones’ description.  This can be easily handled by simply inverting the bits in the sequencer for those signals.

Also, the address decoding for the PC Register is the small box in the lower-left corner.  It is simply a large AND gate looking for all the address bits to be high (the highest address) along with the write signal high.  This will latch the data on the data bus into the 74LS374 holding the PC Register.

The sequencer will be a simple 74LS188 ROM (or actually half of one) programmed with the data from figure 3 in Prof. Jones’ paper.  The address lines for this ROM will be tied to a 4-bit binary up counter (such as a 74LS161) clocked by the system clock.  The eight bits per address location will line up with the eight signals coming in on the left-side of figure 2.

Next up will be creating a schematic of each part of figure 2, and the 74LS188 ROM with the counter and clock.  I would like the clock to be variable, including down to single step, so that the operator can see each step as it is executed.

Also, January is the Winter Warmup for the Retrochallenge contest.  I will be entering again (didn’t do as well as I would have liked last summer), but am not sure what I will be doing for that.  Check out my RC blog at http://retrochallenge.granzeier.com.

Additionally, I recently purchased a few of the LaunchPads from Texas Instruments.  We will be going through an introduction to them in the next few weeks.

 

 

 

 

A Revelation!

Still working on getting the hang of this blogging stuff.  Just thought of something – guess what?  I don’t HAVE to stay on one project until it is completed.  (All right, you veteran bloggers, you can stop laughing now and get up off the floor; ok, so I can be slow on some things sometimes.)  As an engineer, you will rarely get the chance to work on a single project until completion, and so it will be with this blog too.

Anyway, I do have an update to the Ultimate RISC computer that Professor Jones described.  I started to write the emulation for the Parallax QuickStart board (http://www.parallax.com/Store/Microcontrollers/PropellerDevelopmentBoards/tabid/514/ProductID/748/List/0/Default.aspx?SortField=ProductName,ProductName) .  I really love this little board, and when I add Bean’s Propeller Embedded BASIC (PE-BASIC, http://forums.parallax.com/showthread.php?123678-PE-Basic-Version-0.16-July-11-2011&highlight=pe-basic) it feels kind of like the old small computers from the ’70s.

Well, back in the mid-70s, I wrote an emulator for Bell Labs’ CardIAC computer (http://en.wikipedia.org/wiki/CARDboard_Illustrative_Aid_to_Computation.)   This cardboard computer taught the user how computers work on a very basic level.  Because of the CardIAC, I was light years ahead in understanding machine (and thus assembly) language.  Then, back in the early-90s, I dusted it off and morphed it into a visual CPU simulator for a microprocessor course that I was teaching.  Once more, I was starting to work on it to morph it into this Move computer.  I wanted it to be in “kinda” hardware (the Propeller would output an address and read/write to an external memory or I/O device.

After getting a good start, I decided that I was really doing a “proof of concept” project with this.  I really want to do a complete H/W Move Computer, not just a hardware emulation.  So, I am going to re-do this project:  the first implementation will be a purely software version (written in something with a little more horsepower than PE-BASIC, sorry Bean, but an integer-only language without any string handling or other things, while great for an embedded control system, leaves a bit to be desired for this Move Computer.)

My second implementation will then be a simple 4-bit proof of concept done in SSL (Small-Scale Logic) and MSL (Medium-Scale Logic) ICs, such as the 74LS00 or maybe the 4000 family chips.  This will be followed by an actually usable 16-bit or more computer, again done in SSL and MSL.

Here is the block diagram for my Move Computer:

The Control unit will need to generate 8 signals:

Internal to CPU:

  • MAR_WR (Memory Address Register Write or Load)
  • MDR_WR (Memory Data Register Write or Load)
  • MDR_RD (Memory Data Register Read)
  • PCRADDR_RD (Program Count Register Address – hardwired to all 1s, I.E. FFFF)
  • CTRL_RESET (Reset the binary counter to the micro-instruction step)

And external to CPU

  • WR (Write – for Memory or I/O)
  • RD (Read – for Memory or I/O)
  • PCR_INCR (PCR Increment)

Reset:

All control signals go to 1
ACCU (Accumulator) = 0000
PCR (Program Count Register) = 0000

The microcode for the CPU will be pretty simple.  The processor will fetch the contents of the source location and then store it in the destination location.

Fetch the contents of the next Source memory location in the program into the MDR.

1)  PCRADDR_RD = 0 & MAR_WR = 0
2)  PCRADDR_RD = 1, MAR_WR = 1
3)  MAR_WR = 0
4)  MAR_WR = 1, PCR_INCR = 0
5)  PCR_INCR = 1, RD = 0
6)  MDR_WR = 0
7)  MDR_WR = 1
8)  RD = 1

Store the contents of the MDR into the next Destination memory location in the program.

1)  PCRADDR_RD = 0 & MAR_WR = 0
2)  PCRADDR_RD = 1, MAR_WR = 1
3)  MAR_WR = 0
4)  MAR_WR = 1, PCR_INCR = 0
5)  PCR_INCR = 1, MDR_RD = 0
6)  WR = 0
7)  WR = 1
8)  MDR_RD = 1

This looks like it will work, next I will test it in software.  If I stay with this microcode, you will notice that it takes exactly 16 steps.  I would not need the CTRL_Reset signal in that case, just running the sequencer clock beyond the 15(Decimal) or 1111b would start it over again without any need to reset the counter.

Well, that seems to be it for the initial design phase, I will implement it in software and present it in the next posting of this project (with other posts between these, of course.)

The Ultimate RISC

Having been working with computers since 1975, I have long wanted to build my own CPU.  In my playing research, I ran across a paper by Professor Douglas W. Jones of the University of Iowa (http://www.divms.uiowa.edu/~jones/arch/risc/).  This article really captured my imagination, and I have not been able to get it out of my mind.  This is, pretty much, the ultimate in simplified CPU design.

Professor Jones’ paper presents the design for a computer with only a single instruction.  At first, (having grown up watching the 8080 being trumped by the Z-80 and then Intel upping it’s own 8080 with the 8085 followed by the 8086 and so on…) my mind had a difficult time wrapping itself around a single instruction actually being useful.  Prof. Jones even discusses some real-world single-instruction computers at the end of his paper.

People who deal with logic know that any logic can be generated from only NAND gates.  Thus, a computer which can only perform a NAND operation should be able to emulate all other operations.  Likewise, it turns out, a computer which does nothing more than subtracting one number from another and then jumping to a new location can emulate all other operations.  Wikipedia discusses some of those computers in their article on One Instruction Set Computer (http://en.wikipedia.org/wiki/One_instruction_set_computer).

Prof. Jones presents another type of single instruction computer, the MOVE computer.  The only instruction available to this CPU is the MOVE command.  This does bring up a few difficulties such as: how does the CPU modify it’s program flow… How do you do logic or arithmetic functions, etc.

His paper covers all that pretty well.  After reading his paper, it started to strike me as being an insanely simple architecture.  I think that this is a good way for people to get into the design of a CPU.  My next project will be an implementation of this MOVE computer in hardware (probably just an MPU emulating the CPU to begin with.)