04-25-2012 10:30 PM
I have a very simple piece of Verilog code (see below) that I'm struggling to synthesise correctly using XST (ISE 13.4). Behavioural simulation is correct; however, post-translation simulation is not, neither is generated net-list. If I turn KEEP_HIERARCHY option on during synthesis, then the synthesised netlist is correct and post-translation simulation matches behavioral.
Am I doing something wrong with Verilog?
I have 2 modules. One module is a processing element (PE):
module PE( input L, input C, input R, input AL, input AC, input AR, input BL, input BC, input BR, output [0:0] D_o ); wire [3:0] sum; // Compute how many neighbors are HIGH assign sum = (L + R + AL + AC + AR + BL + BC + BR ); // If 3 are HIGH or 2 are HIGH and Center is HIGH output 1 assign D_o = (sum == 4'd3) || ((sum == 4'd2) && C); endmodule
And another module instantiates 4 of these PEs to process a stream of incoming data (4 bits at a time).
As I need 3x3 neighbourhood, I use a shift register to store 3 of the last data elements. The outputs of the register are connected to the inputs of the instantiated PEs:
module PEarray ( input CLK, input CE, input [3:0] Darray_i, output Darray_o0, output Darray_o1, output Darray_o2, output Darray_o3 ); reg [3:0] left, centre, right; // store previous, current and future data // Instantiate 4 processing elements // Each processes a 3x3 neighbourhood: Above left (AC), Above Centre (AC), Above Right (AR) // Left, Centre, Right // Below Left(BL), Below Centre (BC), Below right (BR) PE element0( .L(left), .C(centre), .R(right), .AL(left), .AC(centre), .AR(right), .BL(0), // Boundary condition: out of bounds = 0 .BC(0), .BR(0), .D_o(Darray_o0) ); PE element1( .L(left), .C(centre), .R(right), .AL(left), .AC(centre), .AR(right), .BL(left), .BC(centre), .BR(right), .D_o(Darray_o1) ); PE element2( .L(left), .C(centre), .R(right), .AL(left), .AC(centre), .AR(right), .BL(left), .BC(centre), .BR(right), .D_o(Darray_o2) ); PE element3( .L(left), .C(centre), .R(right), .AL(0), // Boundary condition: out of bounds = 0 .AC(0), .AR(0), .BL(left), .BC(centre), .BR(right), .D_o(Darray_o3) ); // One piece of data is fed every clock cycle // Shift register to store left, centre and right required to process 3x3 neighbourhood always @(posedge CLK) begin right <= Darray_i; centre <= right; left <= centre; end endmodule
Thanks for help in advance.
04-26-2012 05:37 PM
I tried rewriting the PE module as a function:
function [3:0] PEf; input L,C,R,AL,AC,AR,BL,BC,BR; begin : PEfunc reg [3:0] sum; sum = L + R + AL + AC + AR + BL + BC + BR; PEf = (sum == 4'd3) || ((sum == 4'd2) && C); end endfunction
And using it in the following way:
assign Darray_o1 = PEf( left, centre, right, left, centre, right, left, centre, right);
And now the synthesis is correct and so as post-translation simulation.
I really don't understand why it doesn't work as a module... Any hints?