[Serialization] An example of FPGA-based HDL series-DC motor PWM control

Source: Internet
Author: User

[Serialization] FPGA OpenGL series instances

DC motor PWM Control Based on OpenGL

I. Prerequisites

In the previous article, I summarized the control of the stepper motor. This time I will learn about the control of the DC motor. First, we will briefly understand the difference between the stepper motor and the DC motor.

(1) step-by-step movement of stepper motors, DC motors usually adopt continuous movement control.

(2) The stepping motor adopts direct control mode. Its main Commands and control variables are step positions. The DC Motor uses the motor voltage as the control variable and the position or speed as the command variable.

(3) If a DC motor needs to be fed back to the control system, it will indirectly control the motor position. Most stepper motor systems are operated in open-loop mode.

1. What is a DC motor?

A rotating motor that outputs or inputs DC power. It is called a DC motor. It is a motor capable of mutual conversion between DC power and mechanical energy. When it is used as a motor, it is a DC motor, and the electric energy is converted into mechanical energy. When the generator is used as a DC generator, the mechanical energy is converted into electrical energy.

 2. What is PWM?

PWM (Pulse Width Modulation) is a analog control method that modulated the bias of the transistor gate or base pole according to the corresponding load changes, to realize the switching voltage regulator Power Supply output transistor or transistor conduction time change, this way can make the power supply output voltage remain constant when the working conditions change, it is a very effective technology that uses the digital output of a microprocessor to control analog circuits.

3. Implementation of DC motor drive on the Development Platform

The drive part of the DC motor in the Development Board is shown in section 1.1. FPGA is used to design a bipolar PWM generator consisting of 0 and 1.

Figure 1.1 drive circuit of a DC Motor

Ii. Experimental Platform

Quartus II 7.2 integrated development environment, FPGA-MBoard, byteblster II download cable

Iii. Lab Objectives

1. Understand the control method of DC motor PWM.

2. It has the speed control function.

Iv. Experiment implementation

For detailed implementation steps, refer to the [serialization] FPGA-based OpenGL series instance -------- 8-3 Encoder

1. Enter the code in the design file.

1 // bytes //--------------------------------------------------------------------------------------------------
2 // Title: pwm
3 // Author: liwei
4 // Generated: Thu Jun 16 22:30:12 2005
5 // bytes //-------------------------------------------------------------------------------------------------
6'timescale 1ns/1 ps
7
8 module pwm (enable, rst, Dir, clk, spd_sel, MA );
9
10 input rst;
11 input clk;
12 input enable; // control switch
13 input Dir; // control direction
14 input [1:0] spd_sel; // Speed Control
15
16 output [1:0] MA; // Motor Control
17
18 reg [] cnreg;
19 reg [15:0] cnt;
20 reg [15:0] cnt_r;
21 reg pulseout;
22 reg [1:0] MA_r;
23
24 parameter period = 'd10000;
25 assign MA = MA_r;
26
27 always @ (posedge clk or negedge rst)
28
29 begin
30 if (! Rst) // Reset
31 begin
32 cnreg <= #1 16 'b0;
33 cnt <= #1 16' b0;
34 pulseout <= #1 'b0;
35 end
36 else
37 if (enable = 1 'b0) MA_r <= 2 'b00;
38 else
39 begin
40 MA_r [0] <= pulseout;
41 MA_r [1] <= ~ Pulseout;
42
43 if (Dir = 1 'b1) cnreg <= cnt_r;
44 else if (Dir = 1 'b0) cnreg <= period-cnt_r;
45
46 cnt <= cnt + 1;
47 if (cnt = cntReg-1) pulseout <= #1 'b1; // set half of the cycle time
48 else if (cnt = period-1) // set the cycle time
49 begin
50 pulseout <= #1 'b0;
51 cnt <= #1 'b0;
52 end
53 end
54 end
55
56 always @ (spd_sel)
57 begin
58 case (spd_sel)
59 2 'b00: cnt_r <= period-'d3500;
60 2 'b01: cnt_r <= period-'d2500;
61 2 'b10: cnt_r <= period-'d1750;
62 2 'b11: cnt_r <= period-'d1000;
63 endcase
64 end
65
66 endmodule

2. Analysis

Thinking: (1) how to control clockwise and clockwise rotation? (2) How is the speed controlled?

38th rows ~ Line 1: a bipolar PWM generator is generated by two pins.

Conclusion:

(1)Take MA_r [0] as the standard. When the time of status 0 is greater than the time of status 1, the motor rotates clockwise. Otherwise, the motor rotates clockwise.

Then let's see how the code above controls the time of status 0 and the time of status 1. It is not hard to see that the length of time is determined by the direction variable Dir (43rd, 44 rows) and the preset value cnt_r (59th rows ~ 62nd rows. You can try it out.

(2)The speed is determined by the duty cycle. The greater the duty cycle, the faster the speed.Of course, the ratio is greater than 1.

How is the duty cycle determined? This is composed of 59th rows ~ The values in the row 62nd are determined. These values can be defined by yourself, but must be between 0 and ~ Between 10000, the duty cycle here refers to the value not less than, when the value is set to 5000, it will get the slowest speed.

3. The. bsf file generated by the design file, as shown in external interface 1.2.

Figure 1.2 external interface Diagram

4. Pin allocation

Enable is connected to the buttons to control the switch; rst is connected to the reset signal; Dir is connected to the buttons to control the rotation direction; clk is connected to the system clock; spd_sel is connected to two buttons to adjust the rotation speed; MA is connected to the DC motor.

5. Experiment results

The switch, speed, and direction are controlled by the switch.

If you are interested, you can compare it with the previous article to deepen your impression. [Serialization] example of FPGA-based OpenGL series -------- stepper motor driver control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.