xinhui
Junior Member level 1
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