Question: module Rover ( input clk , input [ 3 : 0 ] SW , input [ 2 : 0 ] IPS, input sw _ ON

module Rover(
input clk,
input [3:0] SW,
input [2:0] IPS,
input sw_ON,
input FREQ,
output [3:0] IN,
output [1:0] EN
);
wire [3:0] speed; // For rover use. Sent to main_stateMachine
reg [11:0] motor_duty; // For rover use. PWM
wire pwm_pulse; // Pulse signal from PWM
assign speed = SW; // Map switches directly to speed
always @*
begin
case(speed)
4'b0000: motor_duty =12'b0000_0000_0000; //0% duty cycle
4'b0001: motor_duty =12'b0000_0000_0001; //25% duty cycle (approx.1/4)
4'b0010: motor_duty =12'b0000_0000_0100; //50% duty cycle (approx.2/4)
4'b0100: motor_duty =12'b0000_0000_1100; //75% duty cycle (approx.3/4)
4'b1000: motor_duty =12'b0000_0001_1111; //100% duty cycle (full)
default: motor_duty =12'b0000_0000_0000; // Default to 0% duty cycle
endcase
end
// PWM for rover motors use. Has a freq of 25kHz.
PWM1 #(12,4095)
motors (
.clk (clk),
.width (motor_duty),
.pulse (pwm_pulse)// Connect pulse to pwm_pulse
);
// Keeps rover on alum tape track
IPS_sensor pathfinding(
.clk(clk),
.IPS(IPS),
.IN(IN)
);
// Main state machine
mainStateMachine main_stateMachine(
.clk(clk),
.sw_ON(sw_ON),
.pulse(pwm_pulse),// Pass PWM pulse to main state machine
.EN(EN),
.state(MSM_state)
);
endmodule
module PWM1 #(parameter SIZE =12, PERIOD =4095)
(input clk,
input [SIZE-1:0] width,
output reg pulse);
reg [SIZE-1:0] count;
initial
begin
count <=0;
pulse <=0;
end
always @ (posedge clk)
begin
count <=(count < PERIOD)? count +1 : 0;
pulse <=(count < width)?1 : 0;
end
endmodule
`timescale 1ns /1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 06/25/202411:54:10 AM
// Design Name:
// Module Name: IPS_sensor
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01- File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module IPS_sensor(
input clk,
input [2:0] IPS,
output [3:0] IN //motor inputs
);
reg [3:0] IN_Last;
assign IN[3:0]=
(~IPS[2] & ~IPS[1] & ~IPS[0])?4'b0000 : // If all IPS lit turnoff
(~IPS[0])?4'b0100 : // go straight
(~IPS[2])?4'b0110 : // go right
(~IPS[1])?4'b0001 : // Go left.
(IPS[2] & IPS[1] & IPS[0])?4'b0000 : // If all IPS not lit
IN_Last; //If right IPS lit, go right. If none lit stop.
//Latch to retain last value.
always @ (posedge clk)
IN_Last <= IN;
endmodule
why are my switches not activating the pwm for the motor control to slow the motors down.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!