Project Demo
Before the Hardware assembly, We had connected the IR sensors and their functionality separately. We had connected the IR sensors and motors as shown below:
Arty S7-50 | Motor |
IO3 | in0 |
IO5 | in1 |
IO6 | in2 |
IO11 | in3 |
Arty S7-50 | Sensors |
IO0 | sen[0] |
IO1 | sen[1] |
IO2 | sen[2] |
IO4 | sen[3] |
IO7 | sen[4] |
Now let's run the IR logic to switch the LEDs.
The hardware is ready to be programmed. Create the file named LFR.sv and implemented the following logic.
module LFR ( input wire logic clk, input logic [4:0] sen, output logic [1:0] left_m, [1:0] right_m, [4:0] led ); logic [4:0] sen_val = 0; // Sensor Val logic [7:0] in1 = 8'd0; logic [7:0] in2 = 8'd0; logic [7:0] in3 = 8'd0; logic [7:0] in4 = 8'd0; always_ff @(posedge clk) begin led <= 5'b00000; if (sen_val == 5'b00100) begin //fwd in1 <= 200; in2 <= 0; in3 <= 200; in4 <= 0; led <= 5'b00100; end else if (sen_val == 5'b01000) begin //left in1 <= 100; in2 <= 0; in3 <= 255; in4 <= 0; led <= 5'b01000; end else if (sen_val == 5'b10000) begin //left in1 <= 0; in2 <= 0; in3 <= 255; in4 <= 0; led <= 5'b10000; end else if (sen_val == 5'b00010) begin //right in1 <= 255; in2 <= 0; in3 <= 100; in4 <= 0; led <= 5'b00010; end else if (sen_val == 5'b00001) begin //right in1 <= 255; in2 <= 0; in3 <= 0; in4 <= 0; led <= 5'b00001; end else if (sen_val == 5'b11100) begin //left in1 <= 0; in2 <= 255; in3 <= 255; in4 <= 0; led <= 5'b11100; end else if (sen_val == 5'b00111) begin //right in1 <= 255; in2 <= 0; in3 <= 0; in4 <= 255; led <= 5'b00111; end else if (sen_val == 5'b11111) begin //stop in1 <= 0; in2 <= 0; in3 <= 0; in4 <= 0; led <= 5'b11111; end end always_comb begin sen_val[0] = sen[1] ? 1'b1 : 1'b0; sen_val[1] = sen[1] ? 1'b1 : 1'b0; sen_val[2] = sen[2] ? 1'b1 : 1'b0; sen_val[3] = sen[3] ? 1'b1 : 1'b0; sen_val[4] = sen[4] ? 1'b1 : 1'b0; end pwm m1 (.clk, .duty(in1), .pwm_out(left_m[0])); pwm m2 (.clk, .duty(in2), .pwm_out(left_m[1])); pwm m3 (.clk, .duty(in3), .pwm_out(right_m[0])); pwm m4 (.clk, .duty(in4), .pwm_out(right_m[1])); endmodule
Finally, we implemented a line follower using Arty S7-50. We will be adding a component to this line follower in the next blog.