Question

In: Electrical Engineering

Using the programing language of Verilog I attempted to make a counter to count from 0...

Using the programing language of Verilog I attempted to make a counter to count from 0 to 9 then loop back to 0 using the internal clock of the FPGA cyclone IV from altera. the code is posted at the bottom

I get the following errors

Error (10663): Verilog HDL Port Connection error at Encryption.v(9): output or inout port "clk" must be connected to a structural net expression

Error (10285): Verilog HDL Module Instantiation error at Encryption.v(9): instance "" specifies 3 actual port connections but module "clockgen" only expects 2

Error (12153): Can't elaborate top-level user hierarchy

Can someone help me debug this code so it can count up to 9

module Encryption(SW, CLOCK_50, OUT, HEX0);

input[1:0]SW;

input CLOCK_50;

output reg[6:0] HEX0;

output [3:0]OUT;

wire S1, S2, S3;

clockgen(CLOCK_50, 25000000,clk);

Tflipflop(SW[0], clk, SW[1], OUT[0]);

and(S1, clk, SW[0], OUT[0]);

Tflipflop(S1, clk, SW[1], OUT[1]);

and(S2, S1, OUT[1]);

Tflipflop(S2, clk, SW[1], OUT[2]);

and (S3, S2, OUT[2]);

Tflipflop(S3, clk, SW[1], OUT[3]);

always

begin

case(OUT)

4'b0000: HEX0 = 7'b1000000;

4'b0001: HEX0 = 7'b1111001;

4'b0010: HEX0 = 7'b0100100;

4'b0011: HEX0 = 7'b0110000;

4'b0100: HEX0 = 7'b0011001;

4'b0101: HEX0 = 7'b0010010;

4'b0110: HEX0 = 7'b0000010;

4'b0111: HEX0 = 7'b1111000;

4'b1000: HEX0 = 7'b0100000;

4'b1001: HEX0 = 7'b0010000;

4'b1010: HEX0 = 7'b0001000;

4'b1011: HEX0 = 7'b0000011;

4'b1100: HEX0 = 7'b1000110;

4'b1101: HEX0 = 7'b0100001;

4'b1110: HEX0 = 7'b0000110;

4'b1111: HEX0 = 7'b1001110;

endcase

end

endmodule

module Tflipflop(En, Clk, Clear, Q);

output Q;

input En, Clk, Clear;

reg Q;

always @(posedge Clk)

if (Clear == 0)

begin

Q = 1'b0;

end

else

begin

Q = En^Q;

end

endmodule

module clockgen(clk_in, clk_out);

input clk_in;

output[3:0] clk_out;// count up to 9 length must be 4 so [3:0]

reg[3:0] counter = 0; //temp variable

always@(posedge clk_in)

begin

if(counter< 9)

counter<=counter+1;//manupulate temp variable

else

counter = 0;

end

assign clk_out = counter;//assigning temp variable value(counter in always block) to the output variable

endmodule

Solutions

Expert Solution

Your mistake is you had intiated clock gen with three input in encryption but although in clock gen there are two arguments so i had corrected this code\.

module Encryption(SW, CLOCK_50, OUT, HEX0);

input[1:0]SW;

input CLOCK_50;

output reg[6:0] HEX0;

output [3:0]OUT;

wire S1, S2, S3;

clockgen a1 (CLOCK_50, clk);

Tflipflop b1 (SW[0], clk, SW[1], OUT[0]);

and c1 (S1, clk, SW[0], OUT[0]);

Tflipflop d1(S1, clk, SW[1], OUT[1]);

and e1(S2, S1, OUT[1]);

Tflipflop f1(S2, clk, SW[1], OUT[2]);

and g1 (S3, S2, OUT[2]);

Tflipflop h1 (S3, clk, SW[1], OUT[3]);

always

begin

case(OUT)

4'b0000: HEX0 = 7'b1000000;

4'b0001: HEX0 = 7'b1111001;

4'b0010: HEX0 = 7'b0100100;

4'b0011: HEX0 = 7'b0110000;

4'b0100: HEX0 = 7'b0011001;

4'b0101: HEX0 = 7'b0010010;

4'b0110: HEX0 = 7'b0000010;

4'b0111: HEX0 = 7'b1111000;

4'b1000: HEX0 = 7'b0100000;

4'b1001: HEX0 = 7'b0010000;

4'b1010: HEX0 = 7'b0001000;

4'b1011: HEX0 = 7'b0000011;

4'b1100: HEX0 = 7'b1000110;

4'b1101: HEX0 = 7'b0100001;

4'b1110: HEX0 = 7'b0000110;

4'b1111: HEX0 = 7'b1001110;

endcase

end

endmodule

module Tflipflop(En, Clk, Clear, Q);

output Q;

input En, Clk, Clear;

reg Q;

always @(posedge Clk)

if (Clear == 0)

begin

Q = 1'b0;

end

else

begin

Q = En^Q;

end

endmodule

module clockgen(clk_in, clk_out); //Only two arguments here

input clk_in;

output[3:0] clk_out;// count up to 9 length must be 4 so [3:0]

reg[3:0] counter = 0; //temp variable

always@(posedge clk_in)

begin

if(counter< 9)

counter<=counter+1;//manupulate temp variable

else

counter = 0;

end

assign clk_out = counter;//assigning temp variable value(counter in always block) to the output variable

endmodule


Related Solutions

Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a Verilog module that implements a certain 4-bit counter. The module should include two more input variables: “updown” and “count2”. If “updown” is 1, the circuit should count up (by 1s); if it is 0 it should count down (by 1s). If “count2” has a value of 1, the circuit should instead count up by 2s; otherwise it will have no effect (the circuit counts...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a...
Verilog counter problem: Using the attached 4-bit up-counter module and testbench as a template, write a Verilog module that implements a certain 4-bit counter. The module should include two more input variables: “updown” and “count2”. If “updown” is 1, the circuit should count up (by 1s); if it is 0 it should count down (by 1s). If “count2” has a value of 1, the circuit should instead count up by 2s; otherwise it will have no effect (the circuit counts...
A)  Design 0?379 count?up counter with BCD counter blocks if input clear signal is synchronous. B) Design...
A)  Design 0?379 count?up counter with BCD counter blocks if input clear signal is synchronous. B) Design 0?379 count?up counter with BCD counter blocks if input clear signal is Asynchronous. C) Design of 1/577 frequency divider with BCD count?up counters (Clear signal is Asynchronous)
I want to make 5 sec counter from 1000Hz input frequency using D or JK flip-flops....
I want to make 5 sec counter from 1000Hz input frequency using D or JK flip-flops. Anyone can help me with logic circuits and excitation table. Also, 5-bit parallel load register with flipflop.
programing language JAVA: Design and implement an application that reads a sentence from the user, then...
programing language JAVA: Design and implement an application that reads a sentence from the user, then counts all the vowels(a, e, i, o, u) in the entire sentence, and prints the number of vowels in the sentence. vowels may be upercase
Programing Language: Java The Problem: You are writing a program that encrypts or decrypts messages using...
Programing Language: Java The Problem: You are writing a program that encrypts or decrypts messages using a simple substitution cipher. Your program will use two constant strings. One will represent the code for encryption: going from the original message (called the plaintext) to the encrypted version of the message. The other will be “abcdefghijklmnopqrstuvwxyz” (the lowercase alphabet. Your program will ask the user whether they want to 1) encrypt a message, 2) decrypt a message, or 3) quit. If they...
SOLVE FOLLOWING a.   Desgin and VERILOG code of a 3 bit up down counter USING T...
SOLVE FOLLOWING a.   Desgin and VERILOG code of a 3 bit up down counter USING T FLIP FLOP..... b. using behavioural module.Write a verilog discription of an N-BIT up down binary counter. Record the simulation output waveform in observation.....
I need this program in  Paython programing language wants to maintain a list of quiz Questions, refer...
I need this program in  Paython programing language wants to maintain a list of quiz Questions, refer to as their Question Pool, in an external data file. Each Question should have the question text, point value, four answer choices, and the correct answer stored. Since they want to keep it fun, each question should also store witty retorts given as Feedback text to the user along with the answer. The application should have a Graphical User Interface (GUI), which allows the...
Design a synchronous counter of four-bit using D flip‐flops and gates (AND, OR etc.) *use verilog...
Design a synchronous counter of four-bit using D flip‐flops and gates (AND, OR etc.) *use verilog language modules and test and explain briefly
(Write/Design) both the RTL and Testbench using the Verilog HDL language of the five input majority...
(Write/Design) both the RTL and Testbench using the Verilog HDL language of the five input majority using the structure modeling approach. NOTE: Design means RTL code and Testbench covering all possible corner cases
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT