Problem understanding System Verilog

Status
Not open for further replies.

redtomato11

Newbie level 1
Joined
Jul 1, 2018
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
27
Hi,
my name ist Tobi and i'm studying Electrical engineering.
I started to learn system verilog and i am trying to program a cyclone 2 on an EP2C5 mini board.
I use Quartus 2 13.0spi1 Web Edition. My problem is weird behaviour in a program that i wrote. It is just supposed to count the number of times
i pressed a button and display the number in binary on 3 LEDs. I have a register as the counter and a module i found on the internet that handles
the button logic. It works, but if i change the mapping between the LEDs and the counter output it doesn't work anymore
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
module getting_pro(
 input PB,
 input clk,
 output LED0,
 output LED1,
 output LED2
 );
 
 reg[2:0] counter;
//reflects state (pushed/not pushed)
 wire PB_state;
//is 1 for one clock cycle if button gets pressed
 wire PB_up;
//is 1 for one clock cycle if button gets released
 wire PB_down;
 
//debouncer module i found
 PushButton_Debouncer debouncer(
 .clk(clk),
 .PB(~PB),
 .PB_state(PB_state),
 .PB_up(PB_up),
 .PB_down(PB_down)
 );
 
//the not is because the LEDs are on when the Pin is 0
//The weired stuff happens here
assign LED0 = ~counter[0];
assign LED1 = ~counter[1];
assign LED2 = ~counter[2];
//if i change it to this
assign LED0 = ~counter[2];
assign LED1 = ~counter[1];
assign LED2 = ~counter[0];
//the leds blink as if counter[0] wouldn't exist 
// it counts up normally and resets normally it just starts with setting counter[1]
 
 always_ff @(posedge PB_down)
begin
  //if counter smaller than 7 count up , otherwise set counter to 0
   if(counter < 3'b111)
    begin
        counter <= counter + 3'b001;
    end
    else
    begin
        counter <= 3'b000;
    end
end
 endmodule




I changed counter[2:0] to counter[0:2] and it has the same behaviour just the other way around with counter[2]


P.S. this is my first forum question. Tell me if i did something wrong
 
Last edited by a moderator:

use a scope to check outputs.
 

Your code looks fine. Something else is happening.
 

Hi,

from your working program,

when you changes form this
assign LED0 = ~counter[0];
assign LED1 = ~counter[1];
assign LED2 = ~counter[2];
to this
assign LED0 = ~counter[2];
assign LED1 = ~counter[1];
assign LED2 = ~counter[0];

are you changing anything else ? (are you changing only this 3 lines of code )

thanks and regards
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…