Это ASM, который я использовал для кода Я пытаюсь написать программу, которая реализует игру для свиней с использованием Verilog. Я должен настроить путь данных и блок управления для этой программы. Я попробовал его на обычной диаграмме ASM, но у меня возникли проблемы с его реализацией в блоке данных и пути управления
Это то, что я делал до сих пор обычным способом
module piggame( clock , counter , reset , push , sum , yes , no , tsum , dice1 );
input clock , reset , push , yes , no ; // push is a button on the board that implements rolling of a dice in high speed
output reg [7:1] sum= 0 , tsum = 0 ; // sum is the total sum and tsum is the sum of the turn
output reg [3:0] counter = 0 ; // counter to count for 5 turns
reg [3:0] present ;// present state register
wire [3:0] d1 ; // dice value recorded from the call to the fucntion changeclock
output reg [3:0] dice1 = 0 ;
parameter s0 = 4'd0 , s1 = 4'd1 , s2 = 4'd2 ;
changeclock uut (.clock(clock),.reset(reset),.Dice1(d1)); // this calls for a dice value were a 100mhz clock is given as an input so that
// the user can have a random dice value .
reg [3:0]next ;
always@ (*)
begin
case(present)
s0 : if ( counter > 6 ) next = s0 ;
else if ( counter < 6 && push == 1 ) next = s1 ;
s1 : if ( push == 0 && d1 ==1 ) next = s0 ;
else if (push ==0 && d1 != 0 ) next = s2 ;
s2 : if ( yes ) next = s0 ;
else if ( no ) next = s0 ;
default :next = s0 ;
endcase
end
always@( posedge clock , posedge reset)
if ( reset) present <= s0 ;
else present <= next ;
always @( posedge clock)
case ( present )
s1 : if ( push == 0 )begin
if ( d1 ==1)
begin
dice1 <= d1 ;
sum <= sum ; counter <= counter+ 1 ;
tsum <= 0 ;
end
else if ( d1 != 1 )
begin
tsum <= tsum + d1;end
end
s2 :if ( yes )
counter = counter ;
else if ( no) begin
sum <= sum + tsum ;
tsum <= 0 ;
counter <= counter + 1 ; end
endcase
endmodule
Я могу генерировать форму волны при моделировании, но во время работы на доске xilinx у меня возникают проблемы с отображением значения кости. Значение не меняется, когда я нажимаю кнопку, которая действует как высокоскоростные часы для генерации случайного значения кости.
Ниже приведен код испытательного стенда, который я использовал для генерации сигнала
module simulation();
reg clock , reset , push ,yes, no ;
wire [3:0] counter ;
wire [7:0] sum , tsum ;
wire [3:0] present , next ;
wire [3:0] dice1 ;
crapgame uuts( clock , counter , reset , push , sum , yes , no , tsum ,
dice1);
initial
clock=0;
always
#5 clock=~clock;
initial begin
reset = 1'b1;#100;
reset = 1'b0;#8000;
end
initial begin
push = 1'b1;#100;
push = 1'b0;#100;
push = 1'b1;#100;
push = 1'b0;#100;
push = 1'b1;#100;
push = 1'b0;#100;
push = 1'b0;#100; end
initial begin
yes = 1'b0;#100;
yes = 1'b0;#100;
yes = 1'b0;#100;
yes = 1'b0;#100;
end
initial begin
no = 1'b1;#100;
no = 1'b1;#100;
no = 1'b1;#100;
no = 1'b1;#100;
no = 1'b1;#100;
no = 1'b1;#100;
no = 1'b1;#100;
end
endmodule