DIGITAL CLOCK USING ATMEGA328 IC
My idea was to create a simple digital clock. As I was
familiar with Arduino microcontroller programming, I chose arduino uno for my
project. I wanted my digital clock to look like a product. So, I cannot use my
arduino uno board as it was big and needed plenty of jumper cables for
connections. But I decided to use only the microcontroller chip which is
atmega328. I found on the internet that atmega328 IC can be used like the arduino
uno with a couple of capacitors and a crystal oscillator.
Stage – 1: Preparing block diagram and circuit diagram
The block diagram consists of the atmega328
microcontroller. For that, a start button, a reset button, hour setting button
and minute setting button are connected as input. All these buttons are 4-pin
pushbuttons. And an LED, a 4-digit 7-segment display is used as output.
As I was going to use atmega328 microcontroller, I had to
figure out the pin configuration of that IC. After that I was looking for the
right hardware components. Arduino uno board has a crystal oscillator in it, to
produce clock signals for the microcontroller. I had to look for a 16MHz
crystal oscillator for armega328 chip. A couple of 22pF capacitors are
connected in parallel to the crystal oscillator. A 10k resistor has to be
connected between the reset pin of the microcontroller and the positive
terminal of the power supply. A pushbutton is connected in parallel between the
10k resistor and the negative terminal, to reset the system. A red color LED is
connected to digital pin 6 of the microcontroller with 220 ohms resistor to
indicate seconds passing in the clock. A pushbutton is connected to the digital
pin 13 of the microcontroller to start the clock after setting the time.
Another pushbutton is connected to the digital pin 11 of the microcontroller to
set the minute of the clock. Another pushbutton is connected to the digital pin
12 to set the hour of the clock. The 4-digit 7-segment display is connected to
the appropriate pins to display hours and minutes. I chose a common cathode
display in which all the segments are connected to the positive.
Stage - 2: Programming 4-digit 7-segment display
The main component in the project which is going to show the time is the display. So, I had to learn how to program it first. This display is going to show only numbers. So, I wrote code how to access the different segments to display numbers.
Stage – 3: Code for calculating seconds, minutes and
hours
This was the difficult part of my project. I was trying multiple ways to calculate seconds. If seconds were calculated accurately, then minutes and hours were very easy to calculate. Then I found out that by accessing timers I can calculate time easily. I used millis() function to calculate time. Microcontrollers use milliseconds for time calculation.
Stage – 4: Making the circuit in breadboard with arduino
uno board
The coding part was almost done and it was the time for making the physical circuit. I connected all the components as per the circuit diagram. It worked very well as expected. But I was using the arduino uno board for this. For this project, I had to replace the board with atmega328 chip.
Stage – 5: Testing with atmega328 microcontroller IC
I had to change certain things for implementing the project with atmega328 IC. I needed to provide the power supply separately. The operating voltage of the IC was 5 volts. But I was able to get only 9-volt batteries. So, I had to step down the 9 volts to 5 volts. For that, I used a 7805 voltage regulator IC. It can take up to 12-volts and give out 5-volts. To make the power supply more stable, I used a 10 micro-Farad capacitor across the positive and negative terminals of the power supply.
Everything
was connected perfectly. But, when I switched on the battery, it did not work.
I rechecked each and every connection but still did not work. I tested and
changed certain components, but still did not work. After that, it worked with
some glitches. Then I found out that the connections were not that strong. I
was using an old breadboard and old jumper wires. Then I bought a new
breadboard and new hookup wires for the project. Then it worked fine.
Comments
Post a Comment