dstr
Newbie level 2
- Joined
- Aug 12, 2014
- Messages
- 2
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 21
always @(posedge clk or posedge reset)
begin
if (reset)
output <= 1'b0;
else
output <= a & b;
end
process (clk, reset)
begin
if (reset = '1') then
output <= '0';
elsif rising_edge(clk) then
output <= a AND b;
end if;
end;
process (a, b, c)
begin
if rising_edge(a) then
output <= b AND c;
end if;
end;
My first question is:
In VHDL I must explicitly test both 'reset' and 'clk'.
In Verilog testing 'reset' is enough! Why?
always @(posedge clk or posedge reset or posedge enable)
begin
if (reset)
output <= 1'b0;
else if (enable)
output <= 1'b1;
else
output <=a & b;
end
In Verilog there is no need to explicitly test at clocking edge,in above code else statement is executed in synchronous to clocking edge(posedge of clock).suppose if you have more number of edge sensitivity list like in the fallowing code
First it will look for posedge of reset if it is false,then it will look for posedge of enable if it is also false thenCode:always @(posedge clk or posedge reset or posedge enable) begin if (reset) output <= 1'b0; else if (enable) output <= 1'b1; else output <=a & b; end
last else statement is executed in synchronous to clock edge only.
intial
begin
reset = repeat(5) @(negedge clock) 1;
reset = @(negedge clk) 0;
end
Besides what std_match mentions about the level sensitivity of the reset signal there are other problems with this example.In Verilog there is no need to explicitly test at clocking edge,in above code else statement is executed in synchronous to clocking edge(posedge of clock).suppose if you have more number of edge sensitivity list like in the fallowing code
First it will look for posedge of reset if it is false,then it will look for posedge of enable if it is also false thenCode:always @(posedge clk or posedge reset or posedge enable) begin if (reset) output <= 1'b0; else if (enable) output <= 1'b1; else output <=a & b; end
last else statement is executed in synchronous to clock edge only.
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 module test2 (); reg [1:0] out; reg a; reg b; reg clk; initial begin clk = 1; forever clk = #500 ~clk; end initial begin a = 0; b = 0; #100; a = 0; b = 1; #100; a = 1; b = 1; #100; a = 1; b = 0; #100; a = 0; b = 0; #100; a = 1; b = 0; #100; a = 1; b = 1; #100; a = 0; b = 1; #100; a = 0; b = 0; end always @ (posedge clk or a or b) begin if (!a && !b) begin out <= 0; end else if (!a && b) begin out <= 1; end else if (a && !b) begin out <= 2; end else begin out <= 3; end $display ("%t - ab = %b", $time, out); end endmodule
0 - ab = xx
100 - ab = 00
200 - ab = 01
300 - ab = 11
400 - ab = 10
500 - ab = 00
600 - ab = 10
700 - ab = 11
800 - ab = 01
1000 - ab = 00
2000 - ab = 00
3000 - ab = 00
Code Verilog - [expand] 1 2 3 always @ (posedge clk or reset) if (reset) out <= 0; else out <= in;
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 always @(posedge clk or posedge reset or posedge enable) begin if (reset) out <= 1'b0; else if (enable) out <= 1'b1; else out <=a & b; end
Yes, you better avoid it with recent FPGAs. Asynchronous set/reset or asynchronous preload will be emulated by an unpleasant construct with latches and XORs around the register.Also I never code stuff like this as both Altera and Xilinx have obsoleted all their devices that directly support both an asynchronous set and reset that can be used simultaneously (like Xilinx's old 3000 series devices).
module simple_and(
input clk,
input reset,
input enable,
input a,
input b,
output reg c
);
always @ (posedge clk,posedge reset,posedge enable)
if (reset)
c<=1'b0;
else if (enable)
c<=1'b1;
else
c<= a & b;
endmodule
module tb_sim_and;
// Inputs
reg clk;
reg reset;
reg enable;
reg a;
reg b;
// Outputs
wire c;
// Instantiate the Unit Under Test (UUT)
simple_and uut (
.clk(clk),
.reset(reset),
.enable(enable),
.a(a),
.b(b),
.c(c)
);
initial begin
// Initialize Inputs
clk = 0;
reset = 0;
enable = 0;
a = 0;
b = 0;
#10;
reset= 1'b1;
enable =1'b0;
a<=1'b1;
b<=1'b0;
#4;
reset= 1'b1;
enable =1'b1;
a<=1'b1;
b<=1'b0;
#4;
reset= 1'b1;
enable =1'b1; //for case 2 enable= 1'b0;then it becomes 0 to 1 transition when reset becomes low
a<=1'b1;
b<=1'b0;
#7;
reset= 1'b0;
enable =1'b1;
a<=1'b1;
b<=1'b1;
#30;
reset= 1'b0;
enable =1'b0;
a<=1'b1;
b<=1'b1;
end
always #30 clk = ~ clk;
endmodule
Did you read my post #5? If you don't add the posedge for reset then enable (poor choice of name it is a set or preset) statement will be taken when the falling edge of reset occurs. Why don't you try running my testcase and look at the outputs and when they occur.With above discussion i came to know that asynchronous control signals reset ,enable are all level sensitive unlike edge sensitive ,even though we specify them as edge sensitive in sensitivity list .But still they are not level sensitive as far as simulations are concerned.In simulations they look for edge only.
Did you read our comments in #6, #7, and #8 about using registers with both asynchronous reset/preset? If you are developing for an ASIC that has async reset/preset registers in the library then fine go ahead and use them (though I don't see the necessity of using such a logic element, unless you like trying to develop constraints for asynchronous designs and getting them to meet timing). As your original post is in the programmable logic area and current generation FPGAs don't have both async reset/preset (simultaneous), we recommend you avoid using such constructs as they produce some ugly external logic around the register to create the appearance of having both async inputs.Below program is a simple asynchronous reset,preset (enable ) type register.I dont know whether this type of register is used generally or not,i tested for two cases i assigned two control signals reset ,enable asynchronously.
Well VHDL suffers from the same issue, they just hid it by forcing one to include extra statements in the process body that says the signal in the sensitivity list is edge or level. The signals in the sensitivity list still trigger the process on their transitions (i.e. edges).Using edge-sensitive events for level-sensitive functions always seemed counter-intuitive to me.
The sensitivity list in VHDL has no effect for synthesis. The synthesized function is fully specified by the body. The sensitivity list is only a help to reduce the simulation time. For synthesizeable code an output can not change without an input change, so it is logical that the simulator only executes a process when there is an input edge.Well VHDL suffers from the same issue, they just hid it by forcing one to include extra statements in the process body that says the signal in the sensitivity list is edge or level. The signals in the sensitivity list still trigger the process on their transitions (i.e. edges).
I don't exactly understand what this comment means related to the problem presented in post #9.How can you in Verilog describe a clocked register with both asyncronous set and reset? You need "posedge reset" in the sensitivity list to avoid setting the output at the negative edge, but if "set" is active the simulator must execute the process at the negative edge of reset (if reset has higher priority than set).
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 always @(posedge clk or posedge reset or posedge enable) begin if (reset) out <= 1'b0; else if (enable) out <= 1'b1; else out <=a & b; end
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?