伺服不会在FPGA上停止

科迪·弗里泽尔(Cody Friszell)

我正在努力使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

目前,无论发送2毫秒还是1毫秒,我都可以将其一直向右转。我遇到的最大问题是尝试使其只能向右转然后停止。我尝试过的所有结果最终要么都不起作用,要么就是不停地工作,就像我一开始从未将0发送到图钉一样。

在经过足够的时间将其一直旋转到一个方向后,有人可以建议最好的方法将其发送为0吗?

谢谢!

阿尔珀·库库科穆勒

您需要通过脉宽调制(PWM)调整伺服电压。换句话说,如果您想要10%的电压,则需要SERVOPWM将持续时间设置为持续时间的10%。

我会做的事情是这样的:

module ServoTestNShit(input M_CLOCK,

                             input  [7:0] voltage_percentage,
                             output [7:0] IO_LED, // IO Board LEDs
                             output reg SERVOPWM);    
   reg [7:0] counter;


    initial begin 

    counter = 0;
    end

    // let the counter count for 100 time units
    always @ (posedge M_CLOCK)
    begin
         counter <= counter+1;
         if (counter <= 100)
            counter <= 0;
    end

    // set the output 1 for voltage_percentage/100 of the time
    always @ (negedge M_CLOCK)
    begin
            SERVOPWM <= (counter <= voltage_percentage);
    end



endmodule

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

代码不会在断点上停止

来自分类Dev

jQuery宽度(%)不会在windowResize上停止计算吗?

来自分类Dev

jQuery返回false不会在keydown上停止滚动

来自分类Dev

循环遍历对象数组不会在 if 语句上停止

来自分类Dev

gdb不会在断点处停止

来自分类Dev

fgetc()不会在EOF中停止

来自分类Dev

UIActivityIndicator不会在iOS中停止

来自分类Dev

awatch不会在指定地址停止

来自分类Dev

MySQL不会在关闭时停止

来自分类Dev

(C ++)不会在std :: cin上停止并进入无限循环吗?

来自分类Dev

Visual Studio 2013不会在错误的代码行上停止

来自分类Dev

具有`set -e`的Bash脚本不会在`... && ...`命令上停止

来自分类Dev

Vulkan计算着色器不会在无限循环上停止

来自分类Dev

apt-get不会在Ctrl-c上停止,该怎么办?

来自分类Dev

(C ++)不会在std :: cin上停止并进入无限循环吗?

来自分类Dev

具有`set -e`的Bash脚本不会在`... && ...`命令上停止

来自分类Dev

为什么逻辑评估不会在第一个“假”结果上停止?

来自分类Dev

JScrollPane不会在JPanel上滚动

来自分类Dev

virtualenv不会在Windows上激活

来自分类Dev

Java不会在JPanel上绘图

来自分类Dev

Koken不会在DigitalOcean上加载

来自分类Dev

Steam不会在15.10上启动

来自分类Dev

SharedPreference不会在Android上保存

来自分类Dev

圆圈不会在画布上绘制

来自分类Dev

OnLongClickListener不会在ViewPager上触发

来自分类Dev

pywal不会在startx上运行

来自分类Dev

不会在Ant UNZIP上覆盖

来自分类Dev

不会在 IE 上执行的 CSS

来自分类Dev

IntelliJ IDEA不会在调试模式下停止断言