Question

Im building a clock using HDL system verilog and I need help implementing this instantiation meth...

Im building a clock using HDL system verilog and I need help implementing this instantiation method. Basically what happens is in the top module ClockCounter, positive clock edges are counted and passed into module timer using instantiation. Once the counter reaches MaxCount (59), a carry is generated which increments the minute clock. Once the minute clock reaches 59, another carry is generated which increments the hour clock. In module timer() below, I need help figuring out what variables in each ClockCounter instantiation need to be declared and what type they need to be declared as in module timer(). On a side note the clock will count in military time.

module ClockCounter(input Clk, Run, Reset, input [7:0] MaxCount,
           output [7:0] Count, output reg Carry);

   always_ff@(posedge Clk or posedge Reset) begin
   if (Reset) begin
       Count <= 0;
       Carry <= 0;
   end
   else
    if (Run)
       if (Count < MaxCount) begin
       Count <= Count + 8'd1;
       Carry <= 0;
       end
   else begin
       Count <= 0;
        Carry <= 1;
   end
    end
endmodule


module timer(//variable declarartions)

ClockCounter SecClk (clk_sec, Run_t, Reset_t, fiftynine, Seconds, Carry_scl);
ClockCounter MinClk (Carry_scl, Run_t|set_min_t, Reset_t, fiftynine, Minutes, Carry_mcl);
ClockCounter HrClk (Carry_Mcl, Run_t,|set_hr_t, Reset_t, twentythree, Hours, Carry_hcl);

endmodule

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//I don't understand why set_min_t and set_hr_t is there , except to pause value.

//I have taken these two as ports in top module as you haven't given any information about those. If you need to change in design let me know.

module ClockCounter(input Clk, Run, Reset, input [7:0] MaxCount,
output reg [7:0] Count, output reg Carry);

always_ff@(posedge Clk or posedge Reset) begin
if (Reset) begin
Count <= 0;
Carry <= 0;
end
else
if (Run)
if (Count < MaxCount) begin
Count <= Count + 8'd1;
Carry <= 0;
end
else begin
Count <= 0;
Carry <= 1;
end
end
endmodule


module timer(
//variable declarartions
input clk,Reset_t,Run_t,set_min_t,set_hr_t,
output [7:0]Hours,Minutes,Seconds
);

wire clk_sec,Carry_scl,Carry_mcl,Carry_hcl;
wire [7:0]fiftynine,twentythree;

assign clk_sec = clk;


// Default constant values which will be max count for hours and minutes


assign fiftynine = 59;
assign twentythree = 23;


//Instantiation of clock counter module 3 times for hours,minutes and seconds clock
ClockCounter SecClk (clk_sec, Run_t, Reset_t, fiftynine, Seconds,Carry_scl);
ClockCounter MinClk (Carry_scl, (Run_t|set_min_t), Reset_t, fiftynine, Minutes, Carry_mcl);
ClockCounter HrClk (Carry_mcl, (Run_t|set_hr_t), Reset_t, twentythree, Hours, Carry_hcl);


endmodule

//Testbench
`timescale 1s/100ms
module test;
reg clk,Reset_t,Run_t,set_min_t,set_hr_t;
wire [7:0]Hours,Minutes,Seconds;

always begin
#5 clk = 1'b0;
#5 clk = ~clk;
end

timer TIMER(clk,Reset_t,Run_t,set_min_t,set_hr_t,Hours,Minutes,Seconds);
initial begin
{Reset_t,Run_t,set_min_t,set_hr_t} = 'd0; //Making or initialising all 0's
Reset_t = 1'b1;
@(posedge clk) Reset_t = 1'b0;
Run_t = 1'b1;
#1000000 $finish;
end
endmodule

Wave Default /test/clk /test/Reset t /test/Run t /test/set min t o /test/set hr t o /test/Hours test/Minutes59 ttest/Seconds

Add a comment
Know the answer?
Add Answer to:
Im building a clock using HDL system verilog and I need help implementing this instantiation meth...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Given the following verilog code, draw the corresponding state diagram for it. module mysterious (input reset,...

    Given the following verilog code, draw the corresponding state diagram for it. module mysterious (input reset, clk, TB, TA, output reg [1:0] LB, LA); reg [1:0] cstate, nstate; parameter S0 = 2'b00; parameter S1 = 2'b01; parameter S2 = 2'b10; parameter S3 = 2'b11; parameter grn = 2'b00; parameter ylw = 2'b01; parameter rd = 2'b10; // state register always @ (posedge clk, posedge reset) begin if (reset) cstate <= S0; else cstate <= nstate; end // next state logic...

  • I need help writing a test bench for the following Verilog code module CU(IE, WE, WA,...

    I need help writing a test bench for the following Verilog code module CU(IE, WE, WA, RAE, RAA, RBE, RBA, ALU,                SH, OE, start, clk, reset, Ng5); //nG5 denotes (N>5);    input start, clk, reset;    output IE, WE, RAE, RBE, OE;    output [1:0] WA, RAA, RBA, SH;    output [2:0] ALU;       input wire Ng5;    reg [1:0] state;    reg [1:0] nextstate;    parameter S0 = 3'b000;    parameter S1 = 3'b001;...

  • Modify the Moore FSM below to detect the sequence "110" , simulate using the same test...

    Modify the Moore FSM below to detect the sequence "110" , simulate using the same test bench and create a Moore Transition Diagram for the new sequence 110. module moore_seq (    input clock, reset, x,    output reg z ); //assign binary encoded codes to the states A through D parameter    A = 2'b00,    B = 2'b01,    C = 2'b10,    D = 2'b11; reg [1 : 0] current_state, next_state; //Section 1: Next state generator (NSG)...

  • a Read the following codes in Verilog and the corresponding testbench file. Describe what the codes...

    a Read the following codes in Verilog and the corresponding testbench file. Describe what the codes are doing by adding comments in the code. Then write down the simulation results of res1, res2, res3, and res4, respectively. Source code module vector_defn (num1, res1, res2, res3, res4); input [7:0] num1; output res1; output [3:0] res2; output [0:7] res3; output [15:0] res4; assign res1=num1[2]; assign res2=num1[7:4]; assign res3=num1; assign res4={2{num1}}; endmodule testbench: `timescale 1ns / 1ps module vector_defn_tb; reg [7:0] in1; wire...

  • How do I change these modules so that the communication is bidirectional (inout)? I'm simply not ...

    How do I change these modules so that the communication is bidirectional (inout)? I'm simply not sure how to modify the code. I know i need to add an inout port but I don't know how to do it. I have watched multiple tutorials but I can't figure it out. module mem( input logic clk, we , // write enable bit, active low input logic [n-1:0] in , input logic [m-1:0] addr , output logic [n-1:0] out ) ; parameter...

  • How do I change these modules so that the communication is bidirectional (inout)? I'm simply not...

    How do I change these modules so that the communication is bidirectional (inout)? I'm simply not sure how to modify the code. I know i need to add an inout port but I don't know how to do it. I have watched multiple tutorials but I can't figure it out. module mem( input logic clk, we , // write enable bit, active low input logic [n-1:0] in , input logic [m-1:0] addr , output logic [n-1:0] out ) ; parameter...

  • Need help with this java code supposed to be a military time clock, but I need...

    Need help with this java code supposed to be a military time clock, but I need help creating the driver to test and run the clock. I also need help making the clock dynamic. public class Clock { private int hr; //store hours private int min; //store minutes private int sec; //store seconds public Clock () { setTime (0, 0, 0); } public Clock (int hours, intminutes, int seconds) { setTime (hours, minutes, seconds); } public void setTime (int hours,int...

  • A sequential circuit has one input (X), a clock input (CLK), and two outputs (S and...

    A sequential circuit has one input (X), a clock input (CLK), and two outputs (S and V). X, S and V are all one-bit signals. X represents a 4-bit binary number N, which is input least significant bit first. S represents a 4-bit binary number equal to N + 3, which is output least significant bit first. At the time the fourth input occurs, V = 1 if N + 3 is too large to be represented by 4 bits;...

  • How do I create a testbench with the verilog code below? module ganada(Clk, U1, D2, U2,...

    How do I create a testbench with the verilog code below? module ganada(Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4, CF, S); input Clk, U1, D2, U2, D3, U3, D4, F1, F2, F3, F4; output [6:0] CF, S; reg [6:0] CF, S; reg [1:0] SS, B, NS; initial begin NS=2'b00; SS=2'b00; end always@(posedge Clk) begin    case(NS)    2'b00: CF=7'b1111001; 2'b01: CF=7'b0100100; 2'b10: CF=7'b0110000; 2'b11: CF=7'b0011001; endcase case(SUD) 2'b00: S=7'b1000000;    2'b01: S=7'b1111001; 2'b10: S=7'b0100100; default: S=7'b0000000; endcase if(U1==1 ||...

  • I need a test bench code for this module in verilog. Verilog Code module part6 (А.В.us,G,E,L);...

    I need a test bench code for this module in verilog. Verilog Code module part6 (А.В.us,G,E,L); AlL ((Al --AI --op AIL (us) I-AIL input [2:0]A,B; input us; output G,E.I; reg G,E,L wire [2:0] A,B; always@(A or B) if (us 1)//unsigned mode begin しくーAB: //А is less G-A>B; //B is less 区-A-B; //logical (A equality end --oper AlL1 A[0] & -AIL E<-Ssigned(A) Ssigned(B); //logical equality opera AIL1I -AILI -operat else //signed mode begin しく=$signed(A)<$signed(B); //Ais less G-Ssigned(A)>Ssigned(B);: //B is less end...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT