A
Adam
Guest
I have a verilog design and testbench I made using Webpack 4.2 and am
simulating it using Modelsim5.5e. It has a stack pointer(SP) in it that I
need to initialize to a value for simulation. How do I do this in Verilog?
My target device is an xc2s100 but I'm wondering if there is a general way
to do it. The code I'm working on is below(an Am2909 sequencer). This is
my first design(other than simple registers/muxes) so any feedback
appreciated.
Thanks,
Adam
module Am2909(S,FE_N,PUP,RE_N,OR,ZERO_N,OE_N,Cn,R,D,CP,Y,Cn4);
input [1:0] S;
input FE_N;
input PUP;
input RE_N;
input [3:0] OR;
input ZERO_N;
input OE_N;
input Cn;
input [3:0] R;
input [3:0] D;
input CP;
output [3:0] Y;
output Cn4;
integer i; //Loop control
reg [3:0] AR;
reg [3:0] uPC; //Internal registers
reg [3:0] MUXOUT, Iout, Y;//Non registered signals
reg Cn4; //Incrementer Carryout
reg [1:0] SP; //Stack pointer
reg [3:0] stacks [3:0]; //Stack registers
wire [3:0] STK; //Stack data output
assign STK = stacks[SP]; //Assign stack output
always@(negedge CP) begin
if(FE_N == 0 && PUP == 1) begin
stacks[SP] = uPC; //Push uPC into stacks[SP] on negative edge
end
else stacks[SP]=stacks[SP];
end
always@(posedge CP) begin
if(RE_N==0) AR = R;
else AR = AR;
uPC = Iout;
if(FE_N==0) begin //If file enable is true do push/pop
if(PUP==1) begin
SP = SP + 1;
end
else SP = SP - 1; //Pop stack pointer
end
end
always@(MUXOUT or Cn) begin
if(Cn==1) begin
if(MUXOUT=='hF) begin
Iout = 'h0;
Cn4 = 1;
end
else begin
Iout = MUXOUT + 1;
Cn4 = 0;
end
end
else begin
Iout = MUXOUT;
Cn4 = 0;
end
end
//Data source select
always@(S or ZERO_N or OR or uPC or AR or STK or D) begin
if(ZERO_N==0) MUXOUT = 'h0;
else begin
case (S)
'b00:MUXOUT = uPC;
'b01:MUXOUT = AR;
'b10:MUXOUT = STK;
'b11:MUXOUT = D;
endcase
for(i=0;i<4;i=i+1) begin
if(OR==1) MUXOUT = 1;
end
end
end
//Output enable
always@(MUXOUT or OE_N) begin
if(OE_N==1) Y = 'bZZZZ;
else Y = MUXOUT;
end
endmodule
simulating it using Modelsim5.5e. It has a stack pointer(SP) in it that I
need to initialize to a value for simulation. How do I do this in Verilog?
My target device is an xc2s100 but I'm wondering if there is a general way
to do it. The code I'm working on is below(an Am2909 sequencer). This is
my first design(other than simple registers/muxes) so any feedback
appreciated.
Thanks,
Adam
module Am2909(S,FE_N,PUP,RE_N,OR,ZERO_N,OE_N,Cn,R,D,CP,Y,Cn4);
input [1:0] S;
input FE_N;
input PUP;
input RE_N;
input [3:0] OR;
input ZERO_N;
input OE_N;
input Cn;
input [3:0] R;
input [3:0] D;
input CP;
output [3:0] Y;
output Cn4;
integer i; //Loop control
reg [3:0] AR;
reg [3:0] uPC; //Internal registers
reg [3:0] MUXOUT, Iout, Y;//Non registered signals
reg Cn4; //Incrementer Carryout
reg [1:0] SP; //Stack pointer
reg [3:0] stacks [3:0]; //Stack registers
wire [3:0] STK; //Stack data output
assign STK = stacks[SP]; //Assign stack output
always@(negedge CP) begin
if(FE_N == 0 && PUP == 1) begin
stacks[SP] = uPC; //Push uPC into stacks[SP] on negative edge
end
else stacks[SP]=stacks[SP];
end
always@(posedge CP) begin
if(RE_N==0) AR = R;
else AR = AR;
uPC = Iout;
if(FE_N==0) begin //If file enable is true do push/pop
if(PUP==1) begin
SP = SP + 1;
end
else SP = SP - 1; //Pop stack pointer
end
end
always@(MUXOUT or Cn) begin
if(Cn==1) begin
if(MUXOUT=='hF) begin
Iout = 'h0;
Cn4 = 1;
end
else begin
Iout = MUXOUT + 1;
Cn4 = 0;
end
end
else begin
Iout = MUXOUT;
Cn4 = 0;
end
end
//Data source select
always@(S or ZERO_N or OR or uPC or AR or STK or D) begin
if(ZERO_N==0) MUXOUT = 'h0;
else begin
case (S)
'b00:MUXOUT = uPC;
'b01:MUXOUT = AR;
'b10:MUXOUT = STK;
'b11:MUXOUT = D;
endcase
for(i=0;i<4;i=i+1) begin
if(OR==1) MUXOUT = 1;
end
end
end
//Output enable
always@(MUXOUT or OE_N) begin
if(OE_N==1) Y = 'bZZZZ;
else Y = MUXOUT;
end
endmodule