Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Verilog code for 74LS190

Status
Not open for further replies.

nizdom

Member level 2
Joined
Feb 21, 2016
Messages
42
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
358
Hi All,

I am a newbie in Verilog and I wanted to make a code to display the functions of the 74LS190 which is an Up/Down Counter. 74LS190 is a synchronous Up/Down BCD Counter in which the state changes of the counter are synchronous with the LOW-to-HIGH transition of the Clock Pulse Input. I wanted to code something like it will count up from 0 to 9 then back to 0 and count down from 9 to 0 then back to 9. Any help? Can you check the code below if it answers my question and if not, any way I can modify the code?

Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module up_down_counter    (
 out      ,  // Output of the counter
 up_down  ,  // up_down control for counter
 clk      ,  // clock input
data     ,  // Data to load
 reset       // reset input
  );
//----------Output Ports--------------
 output [9:0] out;
//------------Input Ports-------------- 
input [9:0] data;
input up_down, clk, reset;
//------------Internal Variables--------
reg [9:0] out;
 //-------------Code Starts Here-------
always @(posedge clk)
if (reset) 
   begin // active high reset
     out <= 10'b0 ;
   end else 
       if (up_down) 
          begin
             out <= out + 1;
          end else 
              begin
                  out <= out - 1;
              end
endmodule

 
Last edited by a moderator:

Can you check the code below if it answers my question and if not, any way I can modify the code?

You need to make the testbench to perform simulations.
It is part of the job when coding in hdl languages.
 

You need to make the testbench to perform simulations.
It is part of the job when coding in hdl languages.

I am using the Quartus II 9.0 Web Edition so no testbench is required as it is already has simulation. What can you say about the code?
 

I am using the Quartus II 9.0 Web Edition so no testbench is required as it is already has simulation.

Quartus II has a visual interface to make easy you draw the stimuli signals, but it is actually saved within a file in the same language set as the default in project. Regardless, the simulation is that will allow you determine whether it's working properly or not.

What can you say about the code?

I didn't see where in the code you ensure that conting will not exeed 9.
 

Quartus II has a visual interface to make easy you draw the stimuli signals, but it is actually saved within a file in the same language set as the default in project. Regardless, the simulation is that will allow you determine whether it's working properly or not.



I didn't see where in the code you ensure that conting will not exeed 9.

Hi, can you check the code below? I wanted to make an up/down counter that will count up from 0 to 9 then back to 0 and/or count down from 9 to 0 then back to 9.


Code Verilog - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module updown(data_in, clk, enable, dwn_up, load, data_out, ripple, max_min);
 
input [3:0]data_in;
input clk;
input enable;
input dwn_up;
input load;
 
output [3:0]data_out;
output ripple;
output max_min;
 
wire clk, 
     enable,
     dwn_up,
     load;
    // [3:0]data_in;
 
 
reg [3:0]data_out,
    max_min,
    ripple;
 
 
always@(posedge clk)
 
begin    //1
  if (load==1)                                        // checks if program mode is on
    begin //2
      if(enable==0)                                   // will count if enable is low otherwise counter will pause
        begin  //3
           if(dwn_up==0)                              //checks if count up
             begin   //4
              if(data_out==4'b1111)                     //overflow
                begin  //5
                  data_out<=4'b0000;                    //reset
                  max_min<=1;  
                  #10 ripple<=0;
                end    //5
              else
                begin    //6
                  data_out<=data_out+1;                //not overflow
                  max_min<=0;
                  ripple<=1;
                end       //6
             end      //4
           else                                       // else counter will count down
             begin     //7
              if(data_out==4'b0000)                    // check for underflow
                begin    //8
                  data_out<=4'b1111;                    //reset
                  max_min<=1;
                  #10 ripple<=0;
                end      //8
              else                                   //no underflow and counter counts down normaly
                begin    //9
                 data_out<=data_out-1;
                 max_min<=0;
                 ripple<=1;
                end      //9
             end       // 7
        end      //3
      else                                             // enable is 1 thus counter pauses
        data_out<=data_out;
    end    //2
  else                                                //program mode is on
    data_out<=data_in;
end     //1
 
endmodule

 
Last edited by a moderator:

can you check the code below?

It sounds as if you had disregarded the previous recommendation to yourself make the simulation to check the working of code. Did you at least compiled this code ? Taking a quick look did not seem to be anything out of place I but could be wrong; anyway the code lenght certainly could be reduced by using simpler implementations ( e.g reloading data_out variable at overflow/underflow, I guess ). In addition, once it has in lines 38 and 53 a time dependent statement #, it is assumed it will work only in simulation environment, right ?
 

I did simulate the code and it run with no errors. The code above was for 74LS191 and I wanted to modify it because I wanted to implemet 74LS190. When I simulated the code, it counted from 0 to 15. What I wanted to make is after 9, it will go back to 0. What do you think shall I do with code to do this?
 

You should modify the statement :

Code:
if(data_out==4'b1111)

replacing by :

Code:
if(data_out==4'b1010)
 

After analyzing the code, I did the same thing in what you recommended. Thank youuu. :clap:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top