Saturday, June 28, 2014

Building a simple  counter using Arduino uno



                                           Figure 1
Counter circuits are one of the most common uses of digital electronics in our daily life. A digital counter  is a system that is designed to perform counting from a given number to a specified value.(in general case 0 to any arbitrary number.)You don’t need an Ardunio board or any other microcontroller to build a counter  but using Ardunio ,we can simplify our task and we can do changes to our design very easily. In this article I’m hoping  to give a small introduction to sequential systems as well.
Counter s are categorized under a family called sequential systems. In electronics there are two kinds of systems .
Ø  Combinational systems
Ø  Sequential systems
The key difference between these two systems are sequential systems’ output depend on the previous output as well as the inputs and combinational systems’ output depend only on it’s inputs. Another key difference is that the sequential systems will typically have a clock. Clock is an essential part of sequential design and it’s the thing that defines the present and previous state.


                                                                  





Figure2


State Diagram 

State diagrams are used to describe a sequential system. It describes how the transition from one state to another state occur and the inputs (inputs of the system as well as the previous state) that triggers the transition.There are 2 kinds of FSM(finite state machines)
  •          Moore state machine -sequential systems which output depend only on states.
  •          Mealy state machine - Sequential systems which output depend on states as well as inputs of       the system.
         Counters are Moore machines since it's output(the corresponding number to each state) only depends on states,there are no inputs to the system.   

Figure 3-State diagram of a 0 to 9 counter

Coding

The following code was used to implement the counter .The reference code is just there for help in writing code since this code is long, coder can just copy and paste and change that piece of code as required to generate the output. I have used a conventional common cathode 7 segment display so there may be a possibility that other 7segments may have different pin configuration.
There are few tricks that I’ve used to simplify coding.
·         I used a for loop to declare the output pins.(you have 7 pins to declare.)
All of them are digital output pins of Arduino .
·         I declared a constant called del to store the delay value in ms . This is very helpful when we want to change the delay time.(That’s the time interval the counter going to stay in each state.)





  The best advantage of implementing circuits using arduino is these circuits can be improved or changed at any stage.if the circuit is built from scratch it is very difficult even to add a small change.but using Arduino you only have to change the code.So it's very convenient if you are intending to do experiments with your design.
You can download my version of this design(source code and Ardunio source code) by Here