EmbDev.net

Forum: FPGA, VHDL & Verilog Multiple posedges in sensitivity list


von Joe (Guest)


Rate this post
useful
not useful
I have 2 signals that I need to trigger off of...at the rising edge of 
the first, I need to toggle a bit, and at the rising edge of the second, 
I need to toggle it again.  I have cut the code down to the minimum 
needed to demonstrate the problem:
1
module gen_reset_gate (
2
CLOCK_50,
3
        cref,
4
        cflt,
5
        reset_gate
6
);
7
8
input CLOCK_50
9
input cref;
10
input cflt;
11
output reset_gate;
12
13
reg   reset_state;
14
15
always @(posedge cref)// or posedge cflt)
16
  begin
17
    reset_state=!reset_state;
18
  end
19
20
  assign reset_gate = reset_state;
21
endmodule

It works as-is just triggering off positive edge of cref, or positive 
edge of cflt, but when I remove the comment in the always block and try 
to trigger off either rising edge, it does nothing.  Simulation verifies 
it does nothing, and my development board verifies it does nothing.

I am new to Verilog, so sorry if this is a basic question.

von Lattice User (Guest)


Rate this post
useful
not useful
Simulation does nothing, because reset_state is not initialized. And 
negate an unknown value will yield an unknown value.

Hardware does nothing, because the synthesizer uses the sensitivity list 
only to infer flip-flops and ignores it if you don't follow the required 
coding style. Also a flip-flop with two clock inputs doesn't exist in a 
fpga.

von Joe (Guest)


Rate this post
useful
not useful
Ok, so I'm trying to wrap my mind around what the required coding style 
is.  I can't find any examples to do what I'm trying to do, which is set 
an output (reset_gate) at the first rising edge (cref), then clear it at 
the second rising edge (cflt).

Any constructive help other than you're not doing it right would be much 
appreciated.

von Klakx (Guest)


Rate this post
useful
not useful
Can you show the solution in a schematic of digital Elements?

von Joe (Guest)


Rate this post
useful
not useful
Alright, I got it, in case it will help anyone, here's what I did 
(probably still not in the aforementioned coding style):
1
module gen_reset_gate (
2
        cref,
3
        cflt,
4
        reset_gate
5
);
6
7
input cref;
8
input cflt;
9
output reset_gate;
10
11
reg   reset_state1;
12
reg  reset_state2;
13
14
always @(posedge cref)
15
  begin
16
    reset_state1=!reset_state1;
17
    
18
  end
19
  
20
always @(posedge cflt)
21
  begin
22
    reset_state2=!reset_state2;
23
  end
24
  
25
  assign reset_gate = reset_state1 ^ reset_state2;
26
  
27
endmodule

von bko (Guest)


Rate this post
useful
not useful
Lattice User wrote:

>
> Hardware does nothing, because the synthesizer uses the sensitivity list
> only to infer flip-flops and ignores it if you don't follow the required
> coding style. Also a flip-flop with two clock inputs doesn't exist in a
> fpga.
Ok for VHDL but -
not correct for verilog, coding for a flipflop with async reset
see e.g:
http://www.asic-world.com/examples/verilog/d_ff.html

von Lattice User (Guest)


Rate this post
useful
not useful
bko wrote:
> Lattice User wrote:
>
>>
>> Hardware does nothing, because the synthesizer uses the sensitivity list
>> only to infer flip-flops and ignores it if you don't follow the required
>> coding style. Also a flip-flop with two clock inputs doesn't exist in a
>> fpga.
> Ok for VHDL but -
> not correct for verilog, coding for a flipflop with async reset
> see e.g:
> http://www.asic-world.com/examples/verilog/d_ff.html

This is the coding style for a dff with an async reset. Remove the
1
 if (~reset) begin
from the body, and you will get a synthesis error. But you don't get a 
ff with two clock inputs.

@Joe
There are no coding style issue with your last code. (apart with my 
personal opinion that old module style declaration should be outlawed)

It will however still have some issues.
If on powerup the two state registers will have different values, your 
output is inverted. This depends on the actual FPGA family.

Also it is very sensitive to spikes on the two inputs, assuming they 
come from the outside.

Better would be to synchronise the two inputs to your system clock, and 
use edge detection.
1
reg [2:0] sync_cref;
2
wire edge_cref;
3
always @(posedge sys_clk) sync_cref <= { sync_cref[1:0], cref} ;
4
assign edge_cref = sync_cref[1] & ~sync_cref[2];
On the edge for one signal you then can set your output to 1, and on the 
edge for the other signal reset it to 0. This solves both issues.

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.