Commit f8593c6e authored by Majd Hafiri's avatar Majd Hafiri
Browse files

Merge branch 'counter-20ms' into 'main'

added pwm generator

See merge request !5
parents 475d28b0 72b6d129
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 06/18/2022 01:04:52 AM
// Design Name:
// Module Name: pwm_generator
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module pwm_generator(
input clk,
input [17:0] position,
output logic pwm
);
logic [20:0] counter = 21'd0;
always @(posedge clk) begin
if(counter == position) //counts the width of the pulse ( this value is changed when using push buttons to change angle)
pwm = 1'b0;
if(counter == 21'd2000000) begin //counts the refresh rate which is 20 ms
counter <= 21'b0;
pwm = 1'b1;
end
else
counter <= counter + 1'b1;
end
endmodule
......@@ -25,12 +25,40 @@ module robotic_arm(
output slowClk
);
logic [17:0] positionServoOne, positionServoTwo, positionServoThree, positionServoFour = 18'd100000;
logic [3:0] pwmSignals = 4'b0000;
slow_clock slow_clock_instance(
.clk(clk),
.slowClk(slowClk)
);
/*
instantiating four instances of PWM generator and generate pwm signals for the 4 servos
*/
pwm_generator pwm_instance_servo1(
.clk(clk),
.position(positionServoOne),
.pwm(pwmSignals[0])
);
pwm_generator pwm_instance_servo2(
.clk(clk),
.position(positionServoTwo),
.pwm(pwmSignals[1])
);
pwm_generator pwm_instance_servo3(
.clk(clk),
.position(positionServoThree),
.pwm(pwmSignals[2])
);
pwm_generator pwm_instance_servo4(
.clk(clk),
.position(positionServoFour),
.pwm(pwmSignals[3])
);
endmodule
......@@ -85,6 +85,13 @@
<FileSets Version="1" Minor="31">
<FileSet Name="sources_1" Type="DesignSrcs" RelSrcDir="$PSRCDIR/sources_1" RelGenDir="$PGENDIR/sources_1">
<Filter Type="Srcs"/>
<File Path="$PSRCDIR/sources_1/new/pwm_generator.sv">
<FileInfo>
<Attr Name="UsedIn" Val="synthesis"/>
<Attr Name="UsedIn" Val="implementation"/>
<Attr Name="UsedIn" Val="simulation"/>
</FileInfo>
</File>
<File Path="$PSRCDIR/sources_1/new/slow_clock.sv">
<FileInfo>
<Attr Name="UsedIn" Val="synthesis"/>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment