Azaxa
Newbie level 4
- Joined
- Oct 24, 2014
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 95
I am creating a Time-Multiplexed Quad Seven-Segment Display where the last 2 digits of the display, AN2 & AN3, show the decimal value 00-99 from an input of 8 switches (ignoring values at 100+). I have a few examples of code where the output on the display is correct according to ISim but with synthesis errors, another where the synthesis is correct but display values are incorrect. I believe it has something to do with the binary to BCD conversion from analyzing I/O results from all registers in the code (most likely blocking(=)/non-blocking(<=) procedural assignments)
If anyone could lend a hand on this it would be appreciated.
Synthesis works but display is incorrect:
Display is correct but Synthesis doesn't work giving an error
Both using this test bench/text fixture.
P.S. if you can understand why the binary to BCD converter produces the correct BCD value on the display using hexadecimal switch input values when it should be working with decimal instead that would be helpful; using the second program example. Thanks in advance.
S.D.
If anyone could lend a hand on this it would be appreciated.
Synthesis works but display is incorrect:
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 `timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// module example( input [7:0]sw, input clk,reset, d0, d1, d2, d3, output reg [6:0]seg, output reg dp ); reg [7:0] shift; reg [3:0]val_out; reg [3:0]Q; reg [3:0]val0, val1, val2, val3; reg clkout; reg an0,an1,an2,an3; wire [1:0]s; integer i; always @ (posedge clk) begin if (reset) begin Q <= 4'b0000; end else if(Q !=4'b1111) Q <= Q + 1; else Q <= 0; end assign s[1:0] = Q[3:2]; always@(s) begin an0 = 1; an1 = 1; an2 = 1; an3 = 1; case({s}) 2'b00: an0 = 0; 2'b01: an1 = 0; 2'b10: an2 = 0; 2'b11: an3 = 0; default: {an0, an1, an2, an3} = 1; endcase end always @(s) begin case (s) 2'b00: dp = d0; 2'b01: dp = d1; 2'b10: dp = d2; 2'b11: dp = d3; default: dp = 1'b1; endcase end always @(s) begin case (s) 2'b00: val_out[3:0] = val0[3:0]; 2'b01: val_out[3:0] = val1[3:0]; 2'b10: val_out[3:0] = val2[3:0]; 2'b11: val_out[3:0] = val3[3:0]; default:val_out[3:0] = 4'b0000; endcase end always @(val_out[3:0]) begin case(val_out[3:0]) 4'h0: seg = 7'b0000001; 4'h1: seg = 7'b1001111; 4'h2: seg = 7'b0010010; 4'h3: seg = 7'b0000110; 4'h4: seg = 7'b1001100; 4'h5: seg = 7'b0100100; 4'h6: seg = 7'b0100000; 4'h7: seg = 7'b0001111; 4'h8: seg = 7'b0000000; 4'h9: seg = 7'b0000100; default:seg = 7'b1111111; endcase end always @(sw[7:0]) begin shift[7:0] = sw[7:0]; for (i=0; i<7; i=i+1) begin if (shift[3:0] >= 5) shift[3:0] = shift[3:0] + 3; if (shift[7:4] >= 5) shift[7:4] = shift[7:4] +3; shift = shift << 1; end val3[3:0] <= shift[7:4]; val2[3:0] <= shift[3:0]; val1[3:0] <= 4'b0100; val0[3:0] <= 4'b0110; end endmodule
Display is correct but Synthesis doesn't work giving an error
ERROR:Xst:880 - "example.v" line 102: Cannot mix blocking and non blocking assignments on signal <shift>.
ERROR:Xst:880 - "example.v" line 98: Cannot mix blocking and non blocking assignments on signal <shift>.
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 `timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// module example( input [7:0]sw, input clk,reset, d0, d1, d2, d3, output reg [6:0]seg, output reg dp ); reg [7:0] shift; reg [3:0]val_out; reg [3:0]Q; reg [3:0]val0, val1, val2, val3; reg clkout; reg an0,an1,an2,an3; wire [1:0]s; integer i; always @ (posedge clk) begin if (reset) begin Q <= 4'b0000; end else if(Q !=4'b1111) Q <= Q + 1; else Q <= 0; end assign s[1:0]= Q[3:2]; always@(s) begin an0 = 1; an1 = 1; an2 = 1; an3 = 1; case({s}) 2'b00: an0 = 0; 2'b01: an1 = 0; 2'b10: an2 = 0; 2'b11: an3 = 0; default: {an0, an1, an2, an3} = 1; endcase end always @(s) begin case (s) 2'b00: dp = d0; 2'b01: dp = d1; 2'b10: dp = d2; 2'b11: dp = d3; default: dp = 1'b1; endcase end always @(s) begin case (s) 2'b00: val_out[3:0] = val0[3:0]; 2'b01: val_out[3:0] = val1[3:0]; 2'b10: val_out[3:0] = val2[3:0]; 2'b11: val_out[3:0] = val3[3:0]; default:val_out[3:0] = 4'b0000; endcase end always @(val_out[3:0]) begin case(val_out[3:0]) 4'h0: seg = 7'b0000001; 4'h1: seg = 7'b1001111; 4'h2: seg = 7'b0010010; 4'h3: seg = 7'b0000110; 4'h4: seg = 7'b1001100; 4'h5: seg = 7'b0100100; 4'h6: seg = 7'b0100000; 4'h7: seg = 7'b0001111; 4'h8: seg = 7'b0000000; 4'h9: seg = 7'b0000100; default:seg = 7'b1111111; endcase end always @(sw[7:0]) begin shift[7:0] = sw[7:0]; for (i=0; i<7; i=i+1) begin if (shift[3:0] >= 5) shift[3:0] <= shift[3:0] + 3; if (shift[7:4] >= 5) shift[7:4] <= shift[7:4] +3; shift <= shift << 1; end val3[3:0] = shift[7:4]; val2[3:0] = shift[3:0]; val1[3:0] = 4'b0100; val0[3:0] = 4'b0110; end endmodule
Both using this test bench/text fixture.
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 71 72 73 74 75 76 77 78 `timescale 1ns / 1ps module exampletb; // Inputs reg clk; reg reset; reg d0; reg d1; reg d2; reg d3; reg [7:0]sw; // Outputs wire [3:0] Q; wire [3:0] val0; wire [3:0] val1; wire [3:0] val2; wire [3:0] val3; wire [6:0] seg; wire dp; wire an0; wire an1; wire an2; wire an3; wire [7:0]shift; wire [3:0] val_out; // Instantiate the Unit Under Test (UUT) example uut ( .clk(clk), .reset(reset), .d0(d0), .d1(d1), .d2(d2), .d3(d3), .seg(seg), .dp(dp), .sw(sw) ); always #10 clk = ~clk; initial begin clk = 1'b1; reset = 1'b1; #110; reset = 1'b0; end initial begin $display("If simulation ends prematurely, restart"); $display("using 'run -all' on the command line."); // This should get "3 2.1 0." on the display. d3 <= 1'b0; d2 <= 1'b1; d1 <= 1'b0; d0 <= 1'b1; sw <= 8'h23; #300 sw <= 8'h22; #320 sw <= 8'h21; #320 sw <= 8'h20; #320 sw <= 8'h19; #320 sw <= 8'h18; #320 sw <= 8'h17; endmodule
P.S. if you can understand why the binary to BCD converter produces the correct BCD value on the display using hexadecimal switch input values when it should be working with decimal instead that would be helpful; using the second program example. Thanks in advance.
S.D.