We tested controlling PWM (Pulse Width Modulation) on the KR260 FPGA board.
Using Python (PYNQ), we output PWM signals to control a motor driver board.
We created an original board to control a DC motor and will introduce the details here.
This project is part of a subproject for the AMD Pervasive AI Developer Contest.
Be sure to check out the other projects as well.
***The main project is currently under submission. ***
0. Main project << under submission
2. PYNQ + PWM(DC-Motor Control) << this project
3. Object Detection(Yolo) with DPU-PYNQ
4. Implementation DPU, GPIO, and PWM
6. GStreamer + OpenCV with 360°Camera
7. 360 Live Streaming + Object Detect(DPU)
8. ROS2 3D Marker from 360 Live Streaming
9. Control 360° Object Detection Robot Car
10. Improve Object Detection Speed with YOLOX
11. Benchmark Architectures of the DPU
12. Power Consumption of 360° Object Detection Robot Car
13. Application to Vitis AI ONNX Runtime Engine (VOE)
14. Appendix: Object Detection Using YOLOX with a Webcam
Please note that before running the above subprojects, the following setup, which is the reference for this AMDcontest, is required.
https://github.com/amd/Kria-RoboticsAI
IntroductionThe KR260 FPGA board from AMD (Xilinx) has PMOD connectors, which can be used as PWM pins.
We created a dedicated motor driver board and used PWM to control a DC motor.
The test video below demonstrates the successful PWM control of a DC motor.
And we also tried controlling an LED with PWM.
Circuit Diagram and ArtworkThe circuit diagram and artwork (AW) for the motor driver board are available on GitHub. We used KiCad to create these files.
To connect directly to the PMOD connector, I used a 2.54mm pitch pin header.
This board features a DRV8833 motor driver IC.
If you want to test PWM with LED PCB, please refer to the following GitHub repository:
GitHub Repository for PCB KR260 PMOD Test
Vivado Project Creation for KR260The.tcl file for the Vivado project is located in the following directory.
If you want to create it automatically using the Tcl file, use the following command:
vivado -mode batch -source kr260-pwm-test.tcl
Create Project
We will guide you through the creation steps in Vivado.
Open Vivado, create a project, and name it appropriately. Use the default RTL project type and select the KR260 board.
Create Block Design:
Create a block design in the project file. From the Diagram "+" menu, add the Zynq UltraScale+ MPSoC.
Make four PWM outputs and one GPIO output.
IP Configuration:
While PWM IPs are not edited, configure the GPIO IP to use a single output pin and check the "All outputs" option.(GPIO pins is used as the enable pin for the DRV8833 IC.)
Create HDL Wrapper and XDC file
Right-click the design source and create an HDL wrapper. This will generate the necessary HDL for the IP blocks' inputs and outputs.
Add an XDC file to the project for pin assignments. Assign the following PMOD pins:
We created an XDC file and set pins for PMOD4
- PWM: Pins 1 (H12), 3 (E10), 5 (D10), 7 (C11)
- GPIO: Pin 2 (B10)
set_property PACKAGE_PIN H12 [get_ports pwm_0]
set_property PACKAGE_PIN E10 [get_ports pwm_1]
set_property PACKAGE_PIN D10 [get_ports pwm_2]
set_property PACKAGE_PIN C11 [get_ports pwm_3]
set_property PACKAGE_PIN B10 [get_ports gpio_rtl_0_tri_o[0]]
set_property IOSTANDARD LVCMOS33 [get_ports pwm_0]
set_property IOSTANDARD LVCMOS33 [get_ports pwm_1]
set_property IOSTANDARD LVCMOS33 [get_ports pwm_2]
set_property IOSTANDARD LVCMOS33 [get_ports pwm_3]
set_property IOSTANDARD LVCMOS33 [get_ports gpio_rtl_0_tri_o[0]]
Generate Bitstream
Create the bitstream file. The resulting bit file will be located in the project's impl_1 directory, and the.hwh file will be in the hw_handoff directory.
- The.bit file can be found in the project's ~.runs/impl_1 directory.
- A.hwh file, containing hardware information, is also necessary. It's located in the project folder after generating the bitstream, ~.gen/sources_1/bd/design_1/hw_handoff.
The.hwf file name should match the Bitstream.bit name.
(For example, "design_1_wrapper.bit" and "design_1_wrapper.hwh".)
I renamed them accordingly to transfer the.bit and.hwh files to the KR260.
Below is an example of copying to KR260 at 192.168.11.7:
scp -r pynq-pwm/ ubuntu@192.168.11.7:/home/ubuntu/
Jupyter NotebookWithin the /root/jupyter_notebooks/ directory in KR260, a folder is created to house the executed .ipynb file alongside the .bit and .hwl files produced by Vivado.
Below is an example of copying to the jupyter_notebooks directory on the KR260.
sudo su
cd $PYNQ_JUPYTER_NOTEBOOKS
cd jupyter_notebooks/
ls
cp -rf /home/ubuntu/pynq-pwm/ ./
After KR260 installation, the IP address is confirmed using ifconfig; in my case, it was 192.168.11.9.
Use the Kria-PYNQ environment via Jupyter Notebook to control the PWM. Connect to the KR260 board using a LAN cable and find the IP address using ifconfig
. Access the Jupyter Notebook at http://<IP_ADDRESS>:9090/
.
The test .bit.hwh.ipynb files are available on GitHub.
LED PWM TestBefore controlling the motor, I tested PWM control on an LED.
The test video shows the LED brightness changing with PWM values at 10%, 50%, and 99%.
Connect the motor driver board and DC motor, and use PWM to control them. After loading the FPGA, control the motor in both forward and reverse directions with PWM values at 10%, 50%, and 99%.
The test video below demonstrates the successful PWM control of a DC motor.
Many thanks for reference articles.
- https://www.makarenalabs.com/pwm-on-pynq-how-to-control-a-stepper-motor/
- https://www.xilinx.com/support/documentation/ip_documentation/axi_timer/v2_0/pg079-axi-timer.pdf
- https://www.avnet.com/wps/portal/japan/manufacturers/amd/blog/try-to-control-a-robot-arm-with-kr260-2/
We successfully controlled PWM on the KR260 FPGA board using Python (PYNQ) to output PWM signals and control a motor driver board.
Next, we plan to Object Detection(Yolo) with DPU-PYNQ from the KR260.
3. Object Detection(Yolo) with DPU-PYNQ << next project
Comments