Interfacing Servo Motor with DE0 Nano FPGA
Introduction:
Servo motors are widely used for precise angular positioning in robotics and automation applications. When combined with the DE0 Nano FPGA board, servo motors can be controlled and driven directly by the FPGA. The DE0 Nano's programmable logic enables the generation of accurate control signals required by the servo motor. By utilizing the FPGA's GPIO pins and implementing control logic in HDL, such as Verilog or VHDL, the FPGA can produce the necessary PWM signals for controlling the servo motor's position and movement. This integration provides a flexible and customizable solution for achieving precise and dynamic control of servo motors, making it ideal for a variety of robotic and automation projects.
Problem Statement
Interfacing servo motor with FPGA board.
Requirements
- De0 Nano FPGA board
- Switch
- Buck converter
- Level Shifter(3.3v to 5v)
- Jumper wires
- Breadboard
Working
In a system using an FPGA (DE0 Nano), an MG90S servo motor, a buck converter, a switch, and a motor driver, the FPGA serves as the control unit. It generates precise pulse-width modulation (PWM) signals that control the position and movement of the servo motor. These PWM signals are sent to the motor driver, which amplifies the signals and provides the necessary power to drive the motor. To ensure stable power supply, a buck converter is used to step down the input voltage and provide a regulated voltage suitable for the servo motor. The buck converter converts the higher input voltage from a power source into a lower voltage required by the motor.The switch acts as an interface between the FPGA and the control signals. It allows the FPGA to control the on/off state of the motor and select different operating modes. When the FPGA sends the PWM signals to the motor driver, it adjusts the duty cycle of the PWM signal to control the motor's position. The motor driver amplifies the signal and delivers the required current to the MG90S servo motor, which responds by moving its shaft to the corresponding position based on the control signal. The servo motor also incorporates internal feedback mechanisms that help maintain its position accurately.Overall, the FPGA, in conjunction with the motor driver and control components, enables precise control over the servo motor's position and movement in this system.
Circuit Diagram
- Connect LV and the GND pin of the level shifter to 3.3V and the ground pin of FPGA respectively
- Connect HV and the GND pin of the level shifter to 5V power supply and ground of the power supply
- Connect LV1 of the level shifter to GPIO_00
- Connect HV1 of the level shifter to PWM pin of servo



Code
Copy and paste the following code into servo.v or download it from here:
module servo(input clk,output reg servo);
integer countk=0;
integer count=0;
always@(posedge clk)
begin
countk<=countk+1; //incrementing countk for generating PWM
if(countk==1000000)
countk<=0;
count<=count+1; //incrementing count for delay
if(count==20000000) //count=20000000 is eauivalent to 4 seconds
count<=0;
if(count<10000000) //for first 2 seconds
begin
if(countk<120000) //120000 is the TON(on time period) i.e.2400µs for 90 degrees
servo=1;
else
servo=0;
end
if(count>10000000) //for next 2 seconds
begin
if(count<70000) //70000 is the TON(on time period) i.e.1400µs for 0 degrees
servo=1;
else
servo=0;
end
end
endmodule
Output
Once you upload the code, the servo will start to move in 0 >> 90 >> 0 degrees in the order.
Conclusion
Interfacing a servo motor with an FPGA, along with a buck converter and a level shifter, enables precise and flexible motor control in applications such as robotics, automation, and industrial control. The FPGA's programmability allows for customized control algorithms, real-time response, and seamless integration with other system components. The buck converter ensures optimal power supply voltage for the servo motor, while the level shifter bridges voltage level differences. Together, this setup provides accurate servo positioning, velocity, and acceleration control, making it a versatile solution for various motorized systems.