Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Verilog HDL line following module

Status
Not open for further replies.

xinhui

Junior Member level 1
Joined
Jun 2, 2015
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
MALAYSIA
Activity points
143
hi... i had faced some problem when i programmed this line following module coding into DE0 Nano board. in this project i use 2 sensor from the Line Following Module. the sensor will give the result of "High" when it senses the white area and "Low" when sensing the black area. this result will saved in P0 and send this result to DE0 nano. All the sensor in LFM is active low. I found that the sensor and also the motor driver are not function. Is it my coding is wrong? how can i hold the value of P0 and store it in different reg?

Code:
module sensorlo(IN,sensor_in,P1,P0,clk_50mhz, clk_5Mhz_led,led_out,reset,ledsensor1,ledsensor2);

input P0,reset,sensor_in;
input clk_50mhz;

output led_out;
output clk_5Mhz_led;
output ledsensor1;
output ledsensor2;
output reg [3:0]IN;
output reg [5:0]P1;

reg Pin1;//Pin is input to the deonano from lfm
reg Pin2;
reg [3:0] count =0;

wire clkout;
clk_5Mhz u1 (clkout,clk_50mhz); //clock divider from 50mhz to 5Mhz

always @(posedge clkout)
begin
if(reset)
count <= 0;
else
begin
count <= count + 1'b1;
case(count)
4'b0000 : P1 = 6'b011111;
4'b0001 : P1 = 6'b011111;
4'b0010 : Pin1<=P0;
4'b0011 : P1 = 6'b111111; //First sensor end

4'b0100 : P1 = 6'b101111;
4'b0101 : P1 = 6'b101111;
4'b0110 : Pin2<=P0;
4'b0111 : P1 = 6'b111111; //Second sensor end

4'b1000 : if(Pin1==1)
				begin 
				if (Pin2 ==1)
				IN=4'b1010;//motor forward
				else
				IN=4'b0010;//motor turn left
				end	
			else 		
				begin
				if (Pin2 ==1)
				IN=4'b1000;//motor turn right
				else
				IN=4'b0000;//motor stop
				end

default : ; 
endcase
end
end
assign led_out = sensor_in; // check output P1
assign ledsensor1 = Pin1;
assign ledsensor2 = Pin2;
assign clk_5Mhz_led = clkout; // check clk_5Mhz pada led[7]
endmodule
 

hi,
did you checked your outputs in a singnaltap analyzer ?

how you are giving data to "P0" ??(when your counter value became 2 and 6 , "P0" must be high)
is it will be always high??
base on your code
4'b1000 : if(Pin1==1)
begin
if (Pin2 ==1)
IN=4'b1010;//motor forward
else
IN=4'b0010;//motor turn left
end
else
begin
if (Pin2 ==1)
IN=4'b1000;//motor turn right
else
IN=4'b0000;//motor stop
end

here your are checking pin2==1 two times !!!! in else condition you misplaced something??
clk_5Mhz u1 (clkout,clk_50mhz);
i prefer to write it like this:
clk_5Mhz u1 (.clkout(clkout),
.clk_50mhz(clk_50mhz));

regards
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top