2016-12-10 4 views
0

デジタルロック用にサーボをオフにする作業を進めています。サーボでサーボが止まらない

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を持っていなかったように、まったく動作していないか、ノンストップで動作しているかのどちらかで終わります。

誰もが1方向に向かって回転するのに十分な時間の後に0を送る最良の方法を提案できますか?

ありがとうございます!

答えて

0

パルス幅変調(PWM)によってサーボ電圧を調整する必要があります。言い換えれば、10%の電圧が必要な場合は、アウトスピンを持続時間の10%のSERVOPWMに設定する必要があります。

私がやるだろうな方法は次のようである:

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 
+0

私は混乱しています。私は、例えば、私がvoltage_percentageを10に変えるかのように、それがどうして役立つのか分かりません。正しい時間量のためにピンをハイに設定しないので、実際にピンを設定せずに、 。 さらに、なぜservo = counter = voltage_percentageに設定するのですか? 3つすべてを等しくすることの背後にある考え方は何ですか? –

+0

いいえ、私たちはそれらのすべてを等しく設定していません。 '(counter <= voltage_percentage)'は比較(より大きいか等しい)です。言い換えれば、 のように考えることができますif(counter <= voltage_percentage) –

+0

'if(counter <= voltage_percentage) SERVOPWM <= 1; else SERVOPWM <= 0; –

関連する問題