Subscribe Us

Header Ads

Real Time Alarm Clock Project.

All part --> part 1 part 2 part 3 part 4 part 5 final

 Real Time Alarm Clock 


For Design The functionality of alarm clock We need to Require 6 diffrent module.

Think for Digital Wrist watch 


As you Can see in upper figure we have to require this 4 button functionality. For that now i introduce 6 different module which we can make same functionally which shown us 23:59 time formate.


1>Time Generator Block.
2>Alarm Controller.
3>Counter.
4>key register.
5>Alarm Register.
6>Display Driver.


After this instantiate all module in top module

This are the 6 diffrent module require Lets go throw One by one With theory>>RTL>>Test bench For each module


Time Generator

Basically Timing generate One second and one Minute pulse base on clk Here We use 256 HZ clk.

So.

Each 256 cycle we get ---One second pulse
And                       ----One minute pulse we get at 256*60=15360 as we know this concept.


Logic

rst high One second and one minute is going to zero.

same for 

rst count is high One minute and one second pulse is zero. 

we use rst count lets say your time at 11:30 and between 11:31 your reset count is 1 then it start from o second .

if fast watch is high 

One minute pulse we get at 256 clk same time as one second this signal we use for fast verification only

---------------------------------------------------------------------------------------------------------------

RTL

//Timing generator

 

module TimingGen(clk,rst,rst_count,fast_watch,one_minute,one_second);

 

input clk,rst,rst_count,fast_watch;

output reg one_minute,one_second;

reg [13:0]count_min;

reg [7:0]count_sec;

reg one_minute_temp;

 

always@(posedge clk)

begin

 

    if(rst)

    begin

        count_sec<=0;

        one_second<=0;

    end

   

    else if(rst_count)

    begin  

        count_sec<=0;

        one_second<=0;

    end

   

    else

    begin

        if(count_sec==255)

        begin

        count_sec<=0;

        one_second<=1;

        end

        else

        begin

        count_sec<=count_sec+1;

        one_second<=0;

        end

    end

end

 

always@(posedge clk)

begin

 

    if(rst)

    begin

        count_min<=0;

        one_minute_temp<=0;

    end

   

    else if(rst_count)

    begin  

        count_min<=0;

        one_minute_temp<=0;

    end

   

    else

    begin

        if(count_min==15359)

        begin

        count_min<=0;

        one_minute_temp<=1;

        end

        else

        begin

        count_min<=count_min+1;

        one_minute_temp<=0;

        end

    end

end

 

always@(posedge clk)

begin

    if(fast_watch)

    one_minute<=one_second;

    else

    one_minute<=one_minute_temp;

end

endmodule

       

 TEST BENCH

//Timing generator test bench

 

`timescale 1ms/1us

 

module TimingGen_tb();

 

reg clk,rst,rst_count,fast_watch;

wire one_minute,one_second;

 

TimingGen TG(clk,rst,rst_count,fast_watch,one_minute,one_second);

 

initial

begin

    clk=0;

    forever #1.953125 clk=~clk;

end

 

 

task initialize();

begin

    {clk,rst,rst_count,fast_watch}=0;

end

endtask

 

task reset();

begin

    @(negedge clk)

    rst=1;

    @(negedge clk)

    rst=0;

end

endtask

 

task reset_count();

begin

    @(negedge clk)

    rst_count=1;

    @(negedge clk)

    rst_count=0;

end

endtask

 

task fast(input a);

begin

    @(negedge clk)

    fast_watch=a;

end

endtask

 

initial

begin

    initialize;

    reset;

    fast(1);

    repeat(255)

    begin

    @(negedge clk);

    end

   

   

    fast(0);

   

    reset;

   

    repeat(15370)

    @(negedge clk)

   

    #5;

end

 

initial

$monitor($time,"Input clk=%b,rst=%b,rst_count=%b,fast_watch=%b Output one_minute=%b,one_second=%b",clk,rst,rst_count,fast_watch,one_minute,one_second);

 

initial

#61100 $finish;

 

endmodule

   

   

 ----------------------------------------------------------------------------------------------------------------------------


Display Driver

For display driver We need to display 4 diffrent time .


                            2                3                    :            5                            9

                        ms hr        ls hr                               ms min                   ls min


ms(msb)

ls(lsb)

for each we require one lcd display driver So first we need to write LCD driver and then instantiate 4 lcd driver in display driver.

----->LCD Display driver



Logic

Show_a=1 ------display time=alarm time

show new time=1-----display time ==key

show_a and show new time both zero then display time=current time

alarm time==current time then sound alarm =1


here you give 4 bit key but you get data as 8 bit for that you have to require BCD to ASCII converter Table like this


BCD

ASCII

0000

‘h30

0001

‘h31

0010

‘h32

0011

‘h33

0100

‘h34

0101

‘h35

0110

‘h36

0111

‘h37

1000

‘h38

1001

‘h39


Like This You have to convert

RTL

//lcd display driver

 

module LCDdriver(show_a,show_new_time,alarm_time,current_time,key,sound_alarm,display_time);

 

input show_a,show_new_time;

input [3:0]alarm_time,current_time,key;

output reg sound_alarm;

output reg [7:0]display_time;

reg [3:0]display_value;

 

always@(*)

begin

    if(show_new_time)

        display_value=key;

    else if(show_a)

        display_value=alarm_time;

    else

        display_value=current_time;

       

    if(current_time==alarm_time)

        sound_alarm=1'b1;

    else

        sound_alarm=1'b0;

end

       

always@(display_value)

begin

        case(display_value)

        4'b0000 : display_time=8'h30;

        4'b0001 : display_time=8'h31;

        4'b0010 : display_time=8'h32;

        4'b0011 : display_time=8'h33;

        4'b0100 : display_time=8'h34;

        4'b0101 : display_time=8'h35;

        4'b0110 : display_time=8'h36;

        4'b0111 : display_time=8'h37;

        4'b1000 : display_time=8'h38;

        4'b1001 : display_time=8'h39;

        default : display_time=8'h00;

        endcase

        

       

end

 

endmodule


 TEST BENCH

//lcd display driver test bench

 

module LCDdriver_tb();

reg show_a,show_new_time;

reg [3:0]alarm_time,current_time,key;

wire [7:0]display_time;

wire sound_alarm;

 

 

LCDdriver LD(show_a,show_new_time,alarm_time,current_time,key,sound_alarm,display_time);

 

initial

begin

    show_a=0;

    show_new_time=0;

    alarm_time=0;

    current_time=0;

    key=0;

end

 

initial

begin

    show_a=1;

    show_new_time=0;

    alarm_time=4'd5;

    current_time=4'd6;

    key=4'd7;

   

    #10;

    show_a=0;

    show_new_time=1;

    alarm_time=4'd5;

    current_time=4'd6;

    key=4'd7;

   

    #10;

    show_a=0;

    show_new_time=1;

    alarm_time=4'd5;

    current_time=4'd5;

    key=4'd7;

   

    #10;

    show_a=1;

    show_new_time=1;

    alarm_time=4'd5;

    current_time=4'd5;

    key=4'd7;

   

    #10;

    show_a=0;

    show_new_time=0;

    alarm_time=4'd5;

    current_time=4'd5;

    key=4'd7;

   

    #10;

    show_a=1;

    show_new_time=0;

    alarm_time=4'd12;

    current_time=4'd5;

    key=4'd7;

end

 

initial

$monitor("Input show_a=%b,show_new_time=%b,alarm_time=%d,current_time=%d,key=%d Output sound_alarm=%b,display_time=%h",show_a,show_new_time,alarm_time,current_time,key,sound_alarm,current_time);

 

initial

#100 $finish;

 

endmodule

 

________________________Continue With display drive

    

Instantiate Lcd display driver module 4 time shown below and in this you have to think on how sound alarm is turn on just think on it.. if you not get it then reffer the RTL

RTL

//display driver rtl

 

module displayDriver(current_time_ms_hr,current_time_ms_min,current_time_ls_hr,current_time_ls_min,

                    alarm_time_ms_hr,alarm_time_ms_min,alarm_time_ls_hr,alarm_time_ls_min,

                    key_ms_hr,key_ms_min,key_ls_hr,key_ls_min,

                    show_a,show_new_time,

                    sound_alarm,

                    display_ms_hr,display_ms_min,display_ls_hr,display_ls_min);

 

input show_a,show_new_time;

input [3:0]current_time_ms_hr,current_time_ms_min,current_time_ls_hr,current_time_ls_min,

                    alarm_time_ms_hr,alarm_time_ms_min,alarm_time_ls_hr,alarm_time_ls_min,

                    key_ms_hr,key_ms_min,key_ls_hr,key_ls_min;

   

output sound_alarm;

wire sound_alarm1,sound_alarm2,sound_alarm3,sound_alarm4;

output [7:0]display_ms_hr,display_ms_min,display_ls_hr,display_ls_min;

 

LCDdriver D1(show_a,show_new_time,alarm_time_ms_hr,current_time_ms_hr,key_ms_hr,sound_alarm1,display_ms_hr);

LCDdriver D2(show_a,show_new_time,alarm_time_ms_min,current_time_ms_min,key_ms_min,sound_alarm2,display_ms_min);

LCDdriver D3(show_a,show_new_time,alarm_time_ls_hr,current_time_ls_hr,key_ls_hr,sound_alarm3,display_ls_hr);

LCDdriver D4(show_a,show_new_time,alarm_time_ls_min,current_time_ls_min,key_ls_min,sound_alarm4,display_ls_min);

 

assign sound_alarm=(sound_alarm1 & sound_alarm2 & sound_alarm3 & sound_alarm4);

 

endmodule

   

 

TEST BENCH

//display driver rtl test bench module displayDriver_tb(); reg show_a,show_new_time; reg [3:0]current_time_ms_hr,current_time_ms_min,current_time_ls_hr,current_time_ls_min, alarm_time_ms_hr,alarm_time_ms_min,alarm_time_ls_hr,alarm_time_ls_min, key_ms_hr,key_ms_min,key_ls_hr,key_ls_min; wire sound_alarm; wire [7:0]display_ms_hr,display_ms_min,display_ls_hr,display_ls_min; displayDriver DD(current_time_ms_hr,current_time_ms_min,current_time_ls_hr,current_time_ls_min, alarm_time_ms_hr,alarm_time_ms_min,alarm_time_ls_hr,alarm_time_ls_min, key_ms_hr,key_ms_min,key_ls_hr,key_ls_min, show_a,show_new_time, sound_alarm, display_ms_hr,display_ms_min,display_ls_hr,display_ls_min); initial begin {show_a,show_new_time,current_time_ms_hr,current_time_ms_min,current_time_ls_hr,current_time_ls_min,alarm_time_ms_hr,alarm_time_ms_min,alarm_time_ls_hr,alarm_time_ls_min,key_ms_hr,key_ms_min,key_ls_hr,key_ls_min}=0; end task stimulus(input a,b,input [3:0]a1,a2,a3,a4,c1,c2,c3,c4,k1,k2,k3,k4); begin show_a=a; show_new_time=b; alarm_time_ms_hr=a1; alarm_time_ls_hr=a2; alarm_time_ms_min=a3; alarm_time_ls_min=a4; current_time_ms_hr=c1; current_time_ls_hr=c2; current_time_ms_min=c3; current_time_ls_min=c4; key_ms_hr=k1; key_ls_hr=k2; key_ms_min=k3; key_ls_min=k4; end endtask initial begin stimulus(1,0,4'd1,4'd2,4'd3,4'd0,4'd2,4'd3,4'd0,4'd0,4'd1,4'd1,4'd1,4'd1); #5 stimulus(0,1,4'd1,4'd2,4'd4,4'd0,4'd1,4'd2,4'd4,4'd0,4'd1,4'd1,4'd1,4'd1); #5 stimulus(0,0,4'd2,4'd2,4'd3,4'd5,4'd2,4'd3,4'd5,4'd0,4'd1,4'd3,4'd1,4'd1); end initial $monitor("Input show_a=%b,show_new_time=%b,current_time_ms_hr=%d,current_time_ls_hr=%d,current_time_ms_min=%d,current_time_ls_min=%d,alarm_time_ms_hr=%d,alarm_time_ls_hr=%d,alarm_time_ms_min=%d,alarm_time_ls_min=%d,key_ms_hr=%d,key_ls_hr=%d,key_ms_min=%d,key_ls_min=%d Output sound_alarm=%b,display_ms_hr=%h,display_ls_hr=%h,display_ms_min=%h,display_ls_min=%h",show_a,show_new_time,current_time_ms_hr,current_time_ls_hr,current_time_ms_min,current_time_ls_min,alarm_time_ms_hr,alarm_time_ls_hr,alarm_time_ms_min,alarm_time_ls_min,key_ms_hr,key_ls_hr,key_ms_min,key_ls_min,sound_alarm,display_ms_hr,display_ls_hr,display_ms_min,display_ls_min); initial #100 $finish; endmodule






_________---->Continue click on this link part2



Post a Comment

0 Comments