OpenCores
no use no use 1/1 no use no use
Help in verilog ...
by capricorn_umair on Jul 27, 2010
capricorn_umair
Posts: 1
Joined: Jul 14, 2010
Last seen: Sep 17, 2010
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 out 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
RE: Help in verilog ...
by narendra_27 on Jul 27, 2010
narendra_27
Posts: 7
Joined: Aug 19, 2009
Last seen: Dec 8, 2014
I am not addressing ur current problem.
but the code u have written is ok for simulation purpose.
The delays u have mention will be ignored in systhesis, aswell as while running with
FPGA.I think the code u have written wont work in reality.

My suggestion make it a ring counter with initializing with 1010 r whtever u want to be cyclic.
run that counter with specified clock speed. For that u need to use system(FPGA) clock and divided that clock for the speed u want and apply that clock to ur ring counter that will work out ur goal.

I tried this in my robotics experiment........... u may get issuses related to driving stpper motor with FPGA driving capabilities too..........
RE: Help in verilog ...
by narendra_27 on Jul 27, 2010
narendra_27
Posts: 7
Joined: Aug 19, 2009
Last seen: Dec 8, 2014
did u understnad what i said........
RE: Help in verilog ...
by umairhhhs on Dec 9, 2012
umairhhhs
Posts: 2
Joined: Sep 23, 2012
Last seen: Jan 20, 2013
no if there is not any problem with this code why it would not run
RE: Help in verilog ...
by ravi_stylish on Dec 9, 2012
ravi_stylish
Posts: 1
Joined: Jul 18, 2012
Last seen: Apr 7, 2022
Hi,
I think there is no problem with ur rtl. But in test block replace $display with $monitor and try and get back soon with ur reply.
RE: Help in verilog ...
by payalravi on Dec 9, 2012
payalravi
Posts: 1
Joined: Apr 5, 2011
Last seen: Sep 3, 2018
Hi dear,

remove Initial from the main block and then try code..$ disply is in test bench so that is fine..instead of initial try soem other logic

regards
Ravi
RE: Help in verilog ...
by r_hakola on Dec 9, 2012
r_hakola
Posts: 1
Joined: Nov 6, 2008
Last seen: Oct 1, 2014
First issue as stated above you are running an asynchronous process in an FPGA. This will not execute as you expect outside of simulation.

initial
begin
i out end

The above does not do anything. I does not get initialized and remains at '0'.

always @(n_steps or dir_CW)
You enter the routine on changes of n_steps or dir_CW but only use dir_CW in the routine.
You use the uninitialized i within the routine to count the number of steps. You probably wanted to initialize i = n_steps.

In the routine itself for a count of >= to 4 you decriment i but do not decriment i for other counts. this is fine since you want to terminate the routine when you go to zero but you do not use i as an entry into the routine at the always statement.

What should be happening if this actually compiled with the initial statment above is that you would enter the code but do nothing because i is undefined. If the initial statement was corrected, you would enter the code execute the code once and stop since i is not in the entry criterea.

Hope this helps,
Ron
no use no use 1/1 no use no use
© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.