Altera_Forum
Honored Contributor
15 years agoHelp in verilog code...
I have given a task of writing a verilog code for moving the stepper motor for desired number of steps in either clock wise or CCW direction . i have written the following code but when i simulate it using model sim , it shows high impedance values for all the ports ... the code is given below ...
====================================================== // PROGRAM BLOCK module stepper(out ,n_steps, dir_CW); output reg [3:0]out; input [7:0]n_steps; input dir_CW; integer i; initial begin i <= n_steps; out <= 4'b0000; end always @(n_steps or dir_CW) begin if (dir_CW ==0) begin while(i>=4) begin # 2 out = 4'b1001; # 2 out = 4'b1010; # 2 out = 4'b0101; # 2 out = 4'b0110; i = i - 4; end if (i==3) begin # 2 out = 4'b1001; # 2 out = 4'b1010; # 2 out = 4'b0101; end else if (i==2) begin # 2 out = 4'b1001; # 2 out = 4'b1010; end else if (i==1) begin # 2 out = 4'b1001; end else; end else begin while(i>=4) begin # 2 out = 4'b0110; # 2 out = 4'b0101; # 2 out = 4'b1010; # 2 out = 4'b1001; i = i - 4; end if (i==3) begin # 2 out = 4'b0110; # 2 out = 4'b0101; # 2 out = 4'b1010; end else if (i==2) begin # 2 out = 4'b0110; # 2 out = 4'b0101; end else if (i==1) begin # 2 out = 4'b0110; end else; end end endmodule // TESTING BLOCK module test; reg [7:0]N_STEPS; reg DIR_CW; wire [3:0]OUT; stepper stpr(OUT, N_STEPS, DIR_CW); initial begin $display("no of steps = %b, CW direction = %b, coils output = %b\n", N_STEPS,DIR_CW,OUT); end initial begin N_STEPS= 8'b0001_0000; DIR_CW= 1'b0; //# 100 N_STEPS= 8'd80; DIR_CW= 1'b1; end endmodule ======================================================= please anybody help me out in correcting this code if the logic gets wrong as i m new to verilog ... Regards Umair