我正在为数字锁制作一个从 FPGA 上运行的伺服系统。
My code is as follows:
`timescale 1ns / 1ps
/*
1 pin for servo--ORANGE CABLE
red cable-- 5V, brown cable-- GND.
Position "0" (1.5 ms pulse) is middle,
"90" (~2ms pulse) is all the way to the right,
"-90" (~1 ms pulse) is all the way to the left.
servo stuff:
http://www.micropik.com/PDF/SG90Servo.pdf
*/
//All i need to do is set SERVOPWM to 1 and 0 with delays i think
module ServoTestNShit(input M_CLOCK,
output [7:0] IO_LED, // IO Board LEDs
output reg SERVOPWM);
assign IO_LED = 7'b1010101; // stagger led lights just cause
reg [15:0] counter;
reg [15:0] counter1;
initial begin
counter1 = 0;
counter = 0;
end
//use counter to have a 1ms or 2ms or 1.5ms duty cycle for a while inorder to actually run
//because run it this way is asking the servo to move for 1.5ms so it cant atually move that fast
always @ (posedge M_CLOCK)
begin
counter <= counter+1;
counter1 <= counter1+1;
end
always @ (negedge M_CLOCK)
begin
//if (counter1 > 500)
//begin
SERVOPWM <= (counter <= 1);
//end
end
endmodule
目前,无论我发送 2ms 还是 1ms,我都可以让它一直向右转。我遇到的最大问题是试图让它只向右转,然后停止。我尝试过的所有东西要么根本不工作,要么不停地工作,就像我从来没有将 0 发送到 pin 一样。
任何人都可以建议在足够的时间一直旋转到一个方向后将其发送为 0 的最佳方法吗?
谢谢!