2016-12-10 1 views
0

디지털 잠금을 위해 서보를 FPGA에서 실행하려고합니다.Servo가 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을 보낸 적이없는 것처럼 논스톱으로 작동합니다.

누구나 한 방향으로 완전히 회전 할 수있는 충분한 시간을 보낸 후 가장 좋은 방법을 제안 할 수 있습니까?

감사합니다!

답변

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

관련 문제