0

我正在尝试在基于 Spartan-6 的 FPGA 上进行伺服工作。

我的代码如下:

`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;

    //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 @* 
    begin

        for(counter = 0; counter < 3000; counter = counter + 1)
        begin
        SERVOPWM = 1; 
        #2;
        SERVOPWM = 0;
        #2;
        SERVOPWM = 1; 
        #2;
        SERVOPWM = 0;
        #2;
        SERVOPWM = 1; 
        #2;
        SERVOPWM = 0;
        #2;
        end

        for(counter = 0; counter < 3000; counter = counter + 1)
        begin
        SERVOPWM = 1; 
        #1;
        SERVOPWM = 0;
        #2;
        SERVOPWM = 1; 
        #1;
        SERVOPWM = 0;
        #2;
        SERVOPWM = 1; 
        #1;
        SERVOPWM = 0;
        #2;
        end

    end


endmodule

我的 ucf 文件几乎就是:

# Clock signal 

NET "M_CLOCK" LOC = P123;


NET "SERVOPWM" LOC = P121 ;//0P1

所以在我的脑海里,我的代码将首先创建一个脉冲波,一直到右边,设置高 2 毫秒,然后低,然后高 2 毫秒,等等并重复。然后,一路向左,持续 1ms 等。我认为这个问题会相对简单,因为我所做的只是将 1 或 0 发送到 IO 引脚,并且我的伺服器连接到 5v,接地,以及有问题的 IO 引脚。

我错过了什么愚蠢/明显/容易的东西吗?还是我缺少某些概念?

提前感谢您的帮助!科迪

4

1 回答 1

0

延迟 (#) 语句未在 verilog 中综合。这样它只会输出最终值。您应该将输出与时钟同步。

我会做的方式是

always @ (posedge clk)
begin
   counter <= counter+1;
end

always @ (negedge clk)
begin
   SERVOPWM <= (counter <= pwm_value);
end
于 2016-12-08T13:24:22.337 回答