Question

Could you help me understand what happening in this function, also adjust it to have a  period of 2 seconds and duty cycle 50%module complexDivider (clk50Mhz, slowclk) input clk50Mhz;//fast clock output slowClk;1/slow clock reg [26:01 counter; initial begin counter0; end always (posedge clk50Mhz) begin if (counter == 25000000) begin counter <= 1; end else begin counter <= counter + 1; end end endmodule

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

`timescale 1ns/1ps

module complexDivider (clk50Mhz, slowClk);
input      clk50Mhz;   // Input Fast clock
output reg slowClk;    // Output Slow Clock

reg [26:0] counter;

initial
begin           
   counter = 0; // Initial value of counter is 0 as No reset is given
   slowClk = 0; // Initial value of slowClk is 0 else it will drive x
end

always @(posedge clk50Mhz)
begin
//   if (counter == 25000000) begin // this counter value given a slowClk of 1 sec with 50% duty cycle
   if (counter == 50000000) begin // if reaches 50 * (10^6), slowClk is of 2sec with 50% duty cycle
        counter <= 1;
        slowClk <= ~slowClk;       // slowClk toggles when then counter is reached
   end
   else begin
        counter <= counter + 1'b1; // else counter keeps on incrementing
   end
end

endmodule


module testbench;
reg   clk50Mhz;
wire slowClk;

complexDivider DUT (.clk50Mhz(clk50Mhz), .slowClk(slowClk));

always #10 clk50Mhz = !clk50Mhz;

initial
begin
     clk50Mhz = 1'b0;
     #2000000000;
     $finish;
end

initial
begin
     $recordfile("file1.trn");
     $recordvars();
end

endmodule

fa o- curar o how cantanta In the select:

Add a comment
Know the answer?
Add Answer to:
Could you help me understand what happening in this function, also adjust it to have a  period...
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
  • 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...

  • Write a test bench to thoroughly test the Verilog module dff_fe_asyn_h. below is the module ddff_fe_asyn_h.code...

    Write a test bench to thoroughly test the Verilog module dff_fe_asyn_h. below is the module ddff_fe_asyn_h.code Simulate the circuit using ISim and analyze the resulting waveform. Verilog Code for dff_fe_asyn_h is mentioned below:- //DFF module with asynchronous active high reset with negative edge trigger with clock module dff_fe_asyn_h ( input clock, // Clock Input input reset, // Reset Input input data_in, // Input Data output reg data_out // Output Data ); always @ (negedge clock or posedge reset) // triggers...

  • 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...

  • (15 pts) 1. Draw a logic diagram for the Verilog code. module Seq_Ckt ( CLK, PR,...

    (15 pts) 1. Draw a logic diagram for the Verilog code. module Seq_Ckt ( CLK, PR, sel, Q); input CLK, PR, sel; output reg [2:0] Q; reg [2:0] y; assign Q = y; always @ (posedge PR, posedge CLK) begin if (PR== 1) then y <= 3'b111; else if (sel) begin y[2] <= y[1] ^ y[0]; y[1] <= y[2]; y[1]; end else y[2] <= y[2] ; y[1] <= y[1]; y[0]; y[O] <= y[0] <= end endmodule

  • 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...

  • 1&2 and please I need quickly. Q1 (35 pts): Design a combinational circuit that takes 8...

    1&2 and please I need quickly. Q1 (35 pts): Design a combinational circuit that takes 8 bits of input and checks iif the inputs are symmetric or not and produces an output immediately. Example: 10011001 or 11000011 produce 1 and 11011010 or 11001100 produce 0.) (a) Write Verilog RTL for this circuit. (b) Same functionality but output appears next cycle. You can instantiate the design in part a. (c) Same functionality but output appeurs after two cycles. You can instantiate...

  • Consider the circuit in Figure 1. It is a 4-bit (QQ2Q3) synchronous counter which uses four T-typ...

    Consider the circuit in Figure 1. It is a 4-bit (QQ2Q3) synchronous counter which uses four T-type flip-flops. The counter increases its value on each positive edge of the clock if the Enable signal is asserted. The counter is reset to 0 by setting the Clear signal low. You are to implement an 8-bit counter of this type Enable T Q Clock Clear Figure 1. 4-bit synchronous counter (but you need to implement 8-bit counter in this lab) Specific notes:...

  • Please help to complete the code and write the testbench to design the following adder. 1.In...

    Please help to complete the code and write the testbench to design the following adder. 1.In this section, you add pipeline stage. 8 bits are used at every pipeline stage.Use the following template to complete your Verilog coding. // Addition of two 16 bit, 2's complement nos., n1 and n2. 8 bits addition at a time. Result is 17 bits. module adder_b (clk, n1, n2, sum) ; input clk ; input [15:0] n1 ; input [15:0] n2 ; output [16:0]...

  • 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;...

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