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


(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:  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.