EmbDev.net

Forum: FPGA, VHDL & Verilog need help in counter code


von Basim S. (Company: kfupm) (kurapica)


Attached files:

Rate this post
useful
not useful
i need help in my project which is a counter that counter up or down 
fron 0 to 20

i alraedy did my counter code and its working will in active HDL

but know i need to show the numbers in 7segment in nexys 3 fpga board

i have the codes of the segment but i have a problem when i call the 
module of segment , it is giving me an error in active HDL

can you please tell me what is the error


i am attaching my code and also writing it here


this is my current code :


1
module main
2
  #(parameter N=7)
3
  (
4
  input switch,
5
  input button,
6
  input fastclk,
7
  output [3:0] enable,
8
  output reg[6:0] out
9
  );    
10
  wire[N:0]count;
11
  wire slowclk;
12
  
13
  clock c1(fastclk,slowclk);
14
  Updown u1(switch,button,slowclk,count);
15
  segment s1([3:0]count,[7:4]count,fastclk,enable,out); 
16
  
17
  
18
endmodule
19
20
21
module clock(fastclk,slowclk); //clock code
22
  input fastclk;
23
  output wire slowclk;
24
  reg[25:0]period_count = 0;
25
  
26
  always @(posedge fastclk)
27
    begin
28
      period_count <= period_count + 1;
29
    end
30
  assign slowclk = period_count[25];
31
endmodule
32
33
module Updown // UpDown Counter
34
#(parameter N=7)  
35
  (
36
  input switch,
37
  input button,
38
  input clk,
39
  output reg [N:0]count=8'd0,
40
  );  
41
  
42
   
43
always @(posedge clk)
44
  begin
45
    
46
    if(switch == 1 && button == 1)  // Countup from 0 to 20
47
      begin 
48
        if(count == 8'd20)
49
          count <= 0 ;
50
          
51
        else 
52
          count <= count +1;
53
        
54
      end
55
    else if(switch == 0 && button == 1) // Countdown from 20 to 0
56
    begin 
57
        if(count == 8'd0)
58
          count <= 8'd20 ;
59
          
60
        else 
61
          count <= count -1;
62
        
63
      end  
64
    else count <=8'd0;  
65
  end
66
endmodule
67
68
module mux(A,B,sel,Y); // 2x1 Multiplexer
69
  input [3:0]A;
70
  input [3:0]B;
71
  input sel;
72
  output [3:0]Y;
73
  reg [3:0]Y;
74
  
75
  always @(*)
76
    begin 
77
      if(sel==0)
78
        Y=A;
79
      else 
80
        Y=B;
81
        
82
      end
83
endmodule
84
85
module hex7seg(input wire [3:0]x , output reg[6:0]a_to_g); // Hex to 7seg Code
86
  
87
  always @(*)
88
    
89
    case(x)
90
      0: a_to_g = 7'b0000001;  
91
      1: a_to_g = 7'b1001111;
92
      2: a_to_g = 7'b0010010;
93
      3: a_to_g = 7'b0000110;
94
        4: a_to_g = 7'b1001100;
95
      5: a_to_g = 7'b0100100;
96
      6: a_to_g = 7'b0100000;
97
      7: a_to_g = 7'b0001111;
98
      8: a_to_g = 7'b0000000;
99
      9: a_to_g = 7'b0000100;
100
      'hA: a_to_g = 7'b0001000;
101
      'hB: a_to_g = 7'b1100000;
102
      'hC: a_to_g = 7'b0110001;
103
      'hD: a_to_g = 7'b1000010;
104
      'hE: a_to_g = 7'b0110000;
105
      'hF: a_to_g = 7'b0111000;
106
      default: a_to_g = 7'b0000001;
107
    endcase
108
endmodule
109
110
module segment (a,b,fast,enable,seg7);
111
  input [3:0]a;
112
  input [3:0]b;
113
  input fast;
114
  output [3:0] enable;
115
  output [6:0] seg7;
116
  wire [3:0]e1 = 4'b1110;
117
  wire [3:0]e2 = 4'b1101;
118
  wire slow;
119
  wire [3:0]number;
120
  
121
  clock c1(fast,slow);
122
  mux m1(a,b,slow,number);
123
  mux m2(e1,e2,slow,enable);
124
  hex7seg h1(number,seg7);
125
  
126
endmodule

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Basim Sheikh wrote:
> it is giving me an error in active HDL
> can you please tell me what is the error
Can you please tell the ERROR MESSAGE and the corresponding line?

von Basim S. (Company: kfupm) (kurapica)


Attached files:

Rate this post
useful
not useful
this picture is showing the error line and MESSAGE

: Edited by User
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Basim Sheikh wrote:
> this picture is showing the error line and MESSAGE
A syntax error is the most simple error that can occur. It shows up, 
when some character are not in the expected order. The compiler tells 
you, whats wrong. Correct it and try again. This extremely simple error 
here you must solve on your own. The necessary process is called: 
LEARNING!

I'm the VHDL man, and I don't know Verilog. But it took me less than 1 
minute and a Google search 
https://www.google.de/search?q=verilog+port+list to figure out whats 
leading to this error. Try this here:
1
  segment s1(count[3:0],count[7:4],fastclk,enable,out);

: Edited by Moderator
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.