Design of Motor Control System Based on FPGA

Publisher:TranquilSmileLatest update time:2024-05-30 Source: elecfansKeywords:FPGA Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

FPGAs are well suited for precision motor control, and in this project we will create a simple motor control program upon which more complex applications can be built.

Required Hardware


introduce

We can control the motor with a simple 8-bit microcontroller, outputting a simple pulse width modulated waveform. However, when it comes to precision or advanced motor control, nothing beats the determinism and real-time response of an FPGA. The flexibility of the interface also makes it possible to control multiple motors from a single device, providing a more integrated solution.

First, we will learn a little about motor control theory and create a simple example. We all know that we can drive a DC motor and control its speed via a PWM signal. However, driving it efficiently and accurately requires a little more knowledge of motor control theory.

Motor

Believe it or not, one of my favorite subjects at university was Control Theory. In this module, we studied AC and DC motors, understanding both the theory and real-world use cases. There are various types of AC motors that are powered by an AC supply and can be divided into synchronous motors and induction motors. For example, AC motors are commonly used in pumps and compressors.

There are two types of DC motors: brushed and brushless. Of the two types, brushed are the easiest to drive because they require only one power source. In a brushed DC motor, brushes supply current to a commutator that is connected to the rotor and coils. The current induces an electric field in the coils that is repelled by an external magnet (stator). To ensure rotation, the commutator is designed so that the current flows in the opposite direction to ensure continuous rotation.

The second type of DC motor is the brushless motor, which is slightly more complicated to drive because they have no commutator. Instead, the magnets are mounted on the rotor and the coils are wrapped around the stator so that the current in the coils can be controlled and sequenced externally.

The easiest of the two to control is the brushed DC motor, so we'll use that as our example.

Pulse Width Modulation Drive

The theory behind driving a motor with PWM is that you can control the average voltage that the motor gets, and therefore its speed. When the PWM signal has a 100% duty cycle, the motor is at full voltage and runs at full speed. If you provide a 10% duty cycle, the motor will run at 10% of its full speed.

However, to run the motor efficiently, we need to determine the PWM period correctly. A DC motor has a series inductance and series resistance, which means the motor will act as a low pass filter. The frequency is reduced to

c607da5c-439f-11ee-a2ef-92fbcf53809c.png

where the time constant is given by L/R - we can get these values ​​from the motor datasheet.

Therefore, to ensure a stable speed, we need to choose a PWM frequency that is higher than the motor frequency cutoff to ensure that the DC component is observed.

Therefore, we want to choose a frequency that is at least 5 times the cutoff frequency.

FPGA

To get started with this project, we first create a hardware design targeting an FPGA board.

Start by creating a new project

c618914e-439f-11ee-a2ef-92fbcf53809c.png

Name your project

c63f75a2-439f-11ee-a2ef-92fbcf53809c.png

Select RTL project without specifying source

c6657838-439f-11ee-a2ef-92fbcf53809c.png

After creating the project, create a new block diagram

c6878298-439f-11ee-a2ef-92fbcf53809c.png

Pull the system clock onto the block diagram from the Board tab

c6a67b62-439f-11ee-a2ef-92fbcf53809c.png

Do the same for USB UART

c6cf6d6a-439f-11ee-a2ef-92fbcf53809c.png

Adding a MicroBlaze processor from the IP library

c7147298-439f-11ee-a2ef-92fbcf53809c.png

Run the block automation connection, select the local memory size as 32KB and uncheck the interrupt controller

c753f9ae-439f-11ee-a2ef-92fbcf53809c.png c7812226-439f-11ee-a2ef-92fbcf53809c.png

Add AXI timer

c7b3e382-439f-11ee-a2ef-92fbcf53809c.png

Run Connection Automation

c7d26c26-439f-11ee-a2ef-92fbcf53809c.png

Open the Clock Wizard and deselect the Reset Input

c80017d4-439f-11ee-a2ef-92fbcf53809c.png

Adding GPIO

c81f9c9e-439f-11ee-a2ef-92fbcf53809c.png

Re-customize GPIO to 1 bit wide, output only

c84cbc74-439f-11ee-a2ef-92fbcf53809c.png

Select GPIO output and AXI timer PWM and set them to output

c873968c-439f-11ee-a2ef-92fbcf53809c.png

It should look like this when you are finished.

c89fee1c-439f-11ee-a2ef-92fbcf53809c.png

Once synthesis is complete, we can open the synthesis view and assign the IO to GPIO and timer output - for GPIO the pin is J1 and for PWM the pin is L2

c8d5dbee-439f-11ee-a2ef-92fbcf53809c.png

Build the bitstream and export the platform

c925a71e-439f-11ee-a2ef-92fbcf53809c.png

Vitis Design

Open Vitis, create a new application project and select the XSA you just exported.

c9427e5c-439f-11ee-a2ef-92fbcf53809c.png

Enter the project name

c96b7ff0-439f-11ee-a2ef-92fbcf53809c.png

Choose independence

c987fc02-439f-11ee-a2ef-92fbcf53809c.png

Create a new hello world application

c9ba14da-439f-11ee-a2ef-92fbcf53809c.png

The application software is very simple, we will configure the AXI timer according to the required PWM period and the desired duty cycle.



#include

#include "platform.h"

#include "xil_printf.h"


#include "xtmrctr.h"


#define TMRCTR_DEVICE_ID XPAR_TMRCTR_0_DEVICE_ID

#define PWM_PERIOD 1000000 /* PWM period in (500 ms) */

#define TMRCTR_0 0 /* Timer 0 ID */

#define TMRCTR_1 1 /* Timer 1 ID */

#define CYCLE_PER_DUTYCYCLE 10 /* Clock cycles per duty cycle */

#define MAX_DUTYCYCLE 100 /* Max duty cycle */

#define DUTYCYCLE_DIVISOR 2 /* Duty cycle Divisor */


XTmrCtr TimerCounterInst;


void display_menu()

{

//Clear the screen

xil_printf("�33[2J");

//Display the main menu

xil_printf("******************************************


");

xil_printf("**** www.adiuvoengineering.com ****


");

xil_printf("**** Motor Control Example ****


");

xil_printf("******************************************


");

xil_printf("


");

xil_printf("MM10 Motor Control


");

xil_printf("---------------------------------------------

");

xil_printf("


");

xil_printf("Select a Speed:


");

xil_printf(" (1) - Stop


");

xil_printf(" (2) - 25 %


");

xil_printf(" (3) - 33 %


");

xil_printf(" (4) - 50 %


");

xil_printf(" (5) - 66 %


");

xil_printf(" (6) - 75 %


");

xil_printf(" (7) - 100 %


");

xil_printf("

");

}


void set_pwm(u32 cycle)

{

u32 HighTime;

XTmrCtr_PwmDisable(&TimerCounterInst);

HighTime = PWM_PERIOD * (( float) cycle / 100.0 );

XTmrCtr_PwmConfigure(&TimerCounterInst, PWM_PERIOD, HighTime);

XTmrCtr_PwmEnable(&TimerCounterInst);

}


int main()

{

u8 Div;

u32 Period;

u32 HighTime;

char key_input;

u8 DutyCycle;

init_platform();


print("Hello World


");

print("Successfully ran Hello World application");


XTmrCtr_Initialize(&TimerCounterInst, TMRCTR_DEVICE_ID);



Div = DUTYCYCLE_DIVISOR;

XTmrCtr_PwmDisable(&TimerCounterInst);

Period = PWM_PERIOD;

HighTime = PWM_PERIOD / Div--;

XTmrCtr_PwmConfigure(&TimerCounterInst, Period, HighTime);

XTmrCtr_PwmEnable(&TimerCounterInst);

while(1){

display_menu();

read(1, (char*)&key_input, 1);

xil_printf("Echo %c


",key_input);

switch (key_input) {

case '1': //stop

XTmrCtr_PwmDisable(&TimerCounterInst);

break;

case '2': //25%

xil_printf("25%


");

DutyCycle = 25;

set_pwm(DutyCycle);

break;

case '3': //33%

DutyCycle = 33;

set_pwm(DutyCycle);

break;

case '4': //50%

DutyCycle = 50;

set_pwm(DutyCycle);

break;

case '5': //66%

DutyCycle = 66;

set_pwm(DutyCycle);

break;

case '6': //75%

DutyCycle = 75;

set_pwm(DutyCycle);

break;

case '7': //100%

DutyCycle = 100;

set_pwm(DutyCycle);

break;

}

}


cleanup_platform();

return 0;

}

Of course, the motor I chose contains two Hall Effect sensors. The direction of rotation can be determined by the output of one Hall Effect sensor located in front of another Hall Effect sensor.

Rotate clockwise

c9f0beae-439f-11ee-a2ef-92fbcf53809c.png

Counterclockwise rotation

ca2049c6-439f-11ee-a2ef-92fbcf53809c.png

We can use the pulse frequency to determine the speed of the motor, and we will look at this in more detail later in the project.


Keywords:FPGA Reference address:Design of Motor Control System Based on FPGA

Previous article:What problems does BLDC solve? What are the advantages and disadvantages of BLDC motors?
Next article:Steps for configuring the PROFINET X2 interface in the S7-1200 project

Recommended ReadingLatest update time:2024-11-15 05:32

Technical characteristics and differences between ARM, CPLD and FPGA
In the field of embedded development, ARM is a very popular microprocessor with a very high market coverage. DSP and FPGA are coprocessors for embedded development, helping microprocessors to better realize product functions. What are the technical characteristics and differences between the three? The following is a
[Microcontroller]
Technical characteristics and differences between ARM, CPLD and FPGA
Display Technology of Digital Storage Oscilloscope Based on FPGA
  1 Introduction   Liquid crystal display (LCD) has low power consumption, small size, ultra-thin, light weight, and no distortion and convergence error of the geometric figures of the screen, so it has been widely used. Field programmable gate array (FP-GA) chip has the advantages of high density, miniaturization, lo
[Test Measurement]
Display Technology of Digital Storage Oscilloscope Based on FPGA
The two giants have been acquired one after another. What is the future of FPGA?
In 2015, Intel acquired Altera for $16.7 billion. And just this year, AMD officially acquired Xilinx, which is an important milestone for the FPGA field, because Xilinx and Altera are the main suppliers of FPGA. After the two major acquisitions, the industry began to have great concerns about the future of FPGA.   AM
[Embedded]
The two giants have been acquired one after another. What is the future of FPGA?
A Brief Analysis of Intelligent Debugging and Synthesis Technology to Isolate Errors in FPGA Design
If your FPGA design fails to synthesize or does not work as expected on the development board, the reason is often unknown, and it is difficult to find the root cause of the failure among thousands of RTL and constraint source files, many of which may have been written by other designers. Considering the long iteratio
[Power Management]
Keeping the roadmap updated, Lattice launches mVsion 2.0 and Sentry 2.0
After SensAI gained wide market recognition in edge artificial intelligence, Lattice Semiconductor continued to invest in software in 2020, including SensAI 3.0, mVision 1.0 for machine vision, Sentry 1.0 for security applications, and the development environment Lattice Propel. As Lattice CEO Jim Anderson said in t
[Embedded]
Keeping the roadmap updated, Lattice launches mVsion 2.0 and Sentry 2.0
Using ARM and FPGA to build a neural network processor communication solution
  introduction   Artificial neural networks have been widely used in many fields, especially those with the characteristics of distributed storage, parallel processing, self-learning, self-organization and nonlinear mapping. Embedded portable devices are also increasingly used, most of which are embedded applications
[Microcontroller]
Using ARM and FPGA to build a neural network processor communication solution
Implementation of Network Data Encryption Based on MSP430 and Cyclone II
       1 Introduction   With the development of information technology and networking, network communication security issues are becoming increasingly prominent. Field Programmable Gate Array (FPGA) is widely used in the field of encryption due to its flexible design and high reliability. The encryption algorithm im
[Microcontroller]
Implementation of Network Data Encryption Based on MSP430 and Cyclone II
Using Programmable Logic Devices to Implement Flexible Power Management
  Power management generally refers to issues related to the power supply of circuit boards . These issues include:   • Choose from a variety of DC-DC converters to power the board   • Power supply sequencing/tracking   • Voltage monitoring   • All of the above   In this article, power management is simply defined a
[Power Management]
Using Programmable Logic Devices to Implement Flexible Power Management
Latest Embedded Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号