5 Star 33 Fork 18

WangXuan95 / FPGA-FOC

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
GPL-3.0

语言 仿真 部署 部署

English | 中文

 

FpOC

FPGA based Field Oriented Control (FOC) for driving Permanent Magnet Synchronous Motors (PMSM) or Brushless DC Motors (BLDC)

FOC puts forward certain requirements on sensor sampling rate and processor computing. Using an FPGA-based FOC can achieve better real-time performance and is more convenient for multi-channel expansion and multi-channel feedback.

This repository implements FOC based on a angle sensor (such as a magnetic encoder). In other word, it implements a complete current loop which can perform torque control. With this repository, you can further implement more complex motor applications using FPGA or MCU+FPGA.

diagram
Figure1: System diagram.

The code in this repository has detailed comments (in Chinese). If you are familiar with Verilog but not familiar with FOC, you can quickly learn FOC by reading the code.

Technical features

  • Platform independent:Written in pure Verilog, able to run on various FPGAs such as Altera and Xilinx.

  • Support 3 channels of PWM + 1 channel of EN: when PWM=1, the upper MOSFET turns on, and when PWM=0, the lower MOSFET turns on. When EN=0, all 6 MOSFET are turned off.

  • Supports angle sensor and phase current sampling ADC with 12bit resolution. For sensors >12bit, low-order truncation is required. For sensors <12bit, low-bit stuffing is required.

  • Internally uses 16bit signed integer for computation, considering that the sensors are 12bit, so 16bit computation is enough.

Table of contents

 

Demo project: let your motor spin

Figure1 is the system block diagram of the demo project, it has a simple behavior: control the current (torque) of the motor in clockwise and counterclockwise alternately. At the same time, it use the UART to print the target value and actual value of the current in order to monitor the quality of the current loop control.

All the code for this demo are in RTL folder.

Build Hardware

The hardware required to run this demo includes:

  • FPGA board : at least 10 3.3V IO is required, connect to:
    • I2C (2*IO) , connect to AS5600 magnetic encoder (angle sensor)
    • SPI (4*IO) , connect to AD7928 ADC for phase current sampling.
    • PWM (3*IO) , output 3-phase PWM to motor driving MOSFETs (typically on a motor driving board).
    • PWM_EN (1*IO) , output a ENABLE signal to motor driving board, PWM_EN=0 is to turn off all MOSFETs. If there's no enable signal on your motor driving board, left it open.
    • UART (1*IO) , a one-way (only sending) UART, optionally connected to the serial port of the computer, used to monitor the current loop.
  • A PMSM or a BLDC.
  • Motor driving board: Must support 3-phase PWM input signal (the lower arm is turned on when PWM=0, and the upper arm is turned on when PWM=1), and 3 phases low-side resistance sampling + amplifier must be built-in.
  • A magnetic encoder to obtain the roter angle: This demo directly supports AS5600, which needs to be installed on the motor.
  • an ADC to sample 3-phase current: This demo directly supports AD7928.
    • I didn't find any off-the-shelf AD7928 module online, so if you want to DIY, you'll need to draw the PCB yourself.

If you have strong hardware skills, you can prepare the above hardware yourself.

But! It is recommended to directly use a motor driver board with an AD7928 that I drew. Its schematic is shown in Figure2, and I also provide its manufacturing file [gerber_pcb_foc_shield.zip](./gerber_pcb_foc_shield .zip) , you need to take the manufacturing file to proof the PCB, and then solder it according to Figure2.

Note: This board includes the phase current sampling ADC and motor driveing, but does not include the AS5600 magnetic encoder, which needs to be installed on the motor. You need to prepare it additionally.

sch
Figure2: The schematic of my motor driver board, including AD7928 ADC.

This board is open source in LCEDA, see oshwhub.com/wangxuan/arduino-foc-shield .

The reason why this board is designed as an Arduino shield is because many FPGA development boards have an Arduino shield interface (such as DE10-Nano development board) that can be plugged directly into it. It doesn't matter if your FPGA development board does not have an Arduino shield interface, you can directly connect it with Dupont cables (short Dupont cable is recommended).

The motor driver used here is the MP6540 chip, I have only tried to drive the low-power gimbal motor, but not the high-power motor.

Create FPGA project

You need to create an FPGA project and add all the .v source files in the RTL folder (including its subdirectories) to the project. Please use fpga_top.v as the top-level file.

clock config

There is a call to the altpll primitive in fpga_top.v, which convert the 50MHz clock (clk_50m signal) input by the crystal oscillator into a 36.864MHz main clock (clk signal). The altpll primitive is only applicable in Altera Cyclone IV FPGA, if you are using other series of FPGAs, you need to replace it with their IP cores or primitives (e.g. Xilinx's clock wizard).

If the crystal oscillator of your development board is not 50MHz, you need to modify the PLL's configuration to ensure that the frequency of the main clock is 36.864MHz.

In fact, the frequency of the main clock can take any value less than 40MHz. main clock is to drive the FOC system, its frequency will determine the frequency of SVPWM (SVPWM frequency = clk frequency/2048), I choose 36.864MHz because it can make SVPWM frequency = 36864/2048 = 18kHz.

The reason why the frequency of main clock cannot exceed 40MHz is that adc_ad7928.v will generate the SPI clock (spi_sck signal) by dividing the frequency by two, and the ADC7928 chip requires that the SPI clock cannot exceed 20MHz.

pin constraints

The IO connection of fpga_top.v is as follows:

  • clk_50m : connect to the crystal oscillator on FPGA board.
  • i2c_scl, i2c_sda : connect to AS5600's I2C.
  • spi_ss, spi_sck, spi_mosi, spi_miso : connect to AD7928's SPI.
  • pwm_a, pwm_b, pwm_c : connect to 3-phase PWM of the motor driving board.
  • pwm_en : connect to the ENABLE signal of the motor driving board.
    • If there's no ENABLE signal, left it open.
    • If there are 3 ENABLE signals for every 3 phases, then 1-to-3 connect is recommended.
  • uart_tx : optionally connect to the Serial Port of computer (e.g., a UART-to-USB module).

parameter tuning

To make the motor work normally, you need to tune the Verilog parameters of foc_top module which starts from 103 line in fpga_top.v, including:

Parameter Value Range Illustration
INIT_CYCLES 1~4294967293 Determines how many clock (clk) cycles the initialization step takes. The value should not be too small, as there should be enough time for the rotor to return to electrical angle =0. For example, when the clk frequency is 36.864MHz, you can take INIT_CYCLES=16777216, then the initialization time is 16777216/36864000=0.45 seconds.
ANGLE_INV 0 or 1 If the angle sensor is not installed reversely (the rotation direction of phase A → phase B → phase C → phase A is the same as the increasing direction of the reading value of the angle sensor), this parameter should be set to 0. If the angle sensor is installed reversely, this parameter should be set to 1.
POLE_PAIR 1~255 The number of pole pairs of the motor, which is determined according to the motor model (note: electrical angle ψ = number of pole pairs * mechanical angle φ).
MAX_AMP 1~511 The maximum duty of SVPWM, the smaller the value, the smaller torque the motor can achieve. But considering that we use the lower arm resistance sampling method, the value should not be too large to ensure that the lower arms have sufficient time for ADC sampling. In this example, the default value of 9'd384 is sufficient.
SAMPLE_DELAY 0~511 Sampling delay, considering that the 3-phase drive MOSFET needs a certain time from the start of conduction to the current stabilization, so a certain delay is required from the conduction of the three lower arms to the ADC sampling time. This parameter determines how many clock cycles this delay is, and when the delay is over, the module generates a high-level pulse on the sn_adc signal, indicating that the external ADC is "ready to sample". In this example, the default value of 9'd120 is sufficient.

In addition, foc_top module has two input ports Kp and Ki , they are parameters for PID controller. They will affect the quality of control. They can be adjusted at runtime, but you can also input fixed constants for them.

// ports of foc_top.v
input  wire        [30:0] Kp,
input  wire        [30:0] Ki,

After tuning the parameters, you can compile and program to the FPGA. You should be able to see the motor spining clockwize and anticlockwize alternately.

Monitor current using serial port

Connect the uart_tx signal to the computer through UART to USB module (such as CP2102, CH340 module), you can use Serial Assistant, Putty, HyperTerminal, minicom or other serial port software to monitor the controll effect of the current loop.

Note : UART config is 115200,8,n,1

The information printed by the serial port is shown as follow. The first to fourth columns are: actual value of d-axis current, target value of d-axis current, actual value of q-axis current, **target value of q-axis current **. It can be seen that even if the target value suddenly changes from +200 to -200, the actual value can follow the target value, indicating that the PID control of the current loop is available.

     -5       0     206     200 
    -16       0     202     200 
     16       0     192     200 
     15       0     201     200 
      1       0     197     200 
     17       0    -211    -200 
     -6       0    -199    -200 
    -10       0    -210    -200 
     -3       0    -207    -200 
      0       0    -202    -200 
    -15       0    -211    -200 

In addition, you can use the serial plotter of Arduino IDE to display the current following curve in real time. Go to Arduino official website to download Arduino IDE, open it after installation, select the correct COM port in "Tools→Port", then Click "Tools→Serial Port Plotter". It will automatically receive the serial port and use the above 4 columns of data to draw real-time curves.

Figure3 is the current following curves that I obtain. The blue curve is the data in the first column (the actual value of the d-axis current); the red curve is the data in the second column (the target value of the d-axis current); the green curve is the data in the third column (the actual value of the q-axis current); the yellow curve is the 4th column data (target value of q-axis current). It can be seen that the actual value can follow the target value.

wave
Figure3 : current following curve printed by the "Serial Port Plotter" in Arduino IDE.

 

Design code

The following table lists all the Verilog code files in this project, which are in the RTL folder. Combined with Figure1, you can see the role of each module.

File Name Function 备注
fpga_top.v FPGA project's top module
uart_monitor.v UART sender. Can be removed if not used.
i2c_register_read.v Read AS5600 magnetic encoder.
adc_ad7928.v Read AD7928 ADC.
foc_top.v FOC+SVPWM, that is, the blue part in Figure1. Fixed function, generally do not need to be changed
clark_tr.v Clark transform. Fixed function, generally do not need to be changed
park_tr.v Park transform. Fixed function, generally do not need to be changed
sincos.v Sine/Cosine calculator, called by park_tr.v Fixed function, generally do not need to be changed
pi_controller.v PI controller (PID without D). Fixed function, generally do not need to be changed
cartesian2polar.v Cartesian coordinate system to polar coordinate system. Fixed function, generally do not need to be changed
svpwm.v SVPWM 调制器 Fixed function, generally do not need to be changed
hold_detect.v When three lower bridge arms are all turned on, pulse the sn_adc signal after a delay, indicating that the ADC can start sampling. Fixed function, generally do not need to be changed
diagram
Figure1: System diagram.

Figure1 shows the hierarchy of these modules, I have fully considered the rationality of encapsulation and code reuse when designing this module hierarchy:

  • The pink part are the sensor controllers in the FPGA, which is hardware related logic. If the angle sensor and ADC model change, this part of the code needs to be rewritten.
  • The blue part is the fixed algorithm of FOC, it is hardware independent logic, generally does not need to be modified, it is the core code of this library!
  • The yellow part is the user-defined logic in the FPGA, the user can modify the user behavior to realize various motor applications. Or modify uart_monitor to monitor other variables.
  • The orange part is the hardware circuit outside the FPGA, that is, the motor, the motor driver board, and the angle sensor.

In addition, except for the altpll primitives in fpga_top.v, all code in this library is written in pure RTL and can be easily ported to FPGAs from other vendors (Xilinx, Lattice, etc.).

 

RTL simulation

Because I don't have a Verilog model of the motor, I can't simulate the entire FOC algorithm, so I only simulated some of the submodules in the FOC.

The simulation related files are all in the SIM folder, including the files:

File Name Function
tb_clark_park_tr.v Testbench for clark_tr.v (clark transform) and park_tr.v (park transform).
tb_clark_park_tr_run_iverilog.bat Command script to run tb_clark_park_tr.v with iverilog.
tb_svpwm.v Testbench for cartesian2polar.v and svpwm.v.
tb_svpwm_run_iverilog.bat Command script to run tb_svpwm.v with iverilog.

Before using iverilog simulation, you need to install iverilog , see: iverilog_usage

simulate clark_tr and park_tr

Let's run a simulation of the clark transform and park transform first.

Directly double-click tb_clark_park_tr_run_iverilog.bat to run the simulation, the waveform file dump.vcd will be generated after running. Use gtkwave to open dump.vcd. After importing signals, you can see the waveform as Figure4. You need to change these signals to the form of analog display:

  • For the signal declared as signed in the Verilog code, you need to right-click "signal→Data Format→Signed Decimal".
  • Right-click the "signal→Data Format→ Analog→Step" to turn it into the form of analog display.

The simulation waveform in Figure4 shows that:

  • theta θ is an increasmental angle (0→2π→0→2π→...)
  • ia, ib, ic are sine waves generated by θ, ia, ib, ic form a 3-phase sine wave.
  • Transform ia, ib, ic into ialpha (iα), ibeta (iβ) using clark transform to get a pair of quadrature sine waves (phase difference is π/2).
  • Use park transformation to convert (iα, iβ) to the stator coordinate system to get fixed values id and iq.
tb_clark_park_tr
Figure4 : Simulation waveform for clark_tr and park_tr.

simulate cartesian2polar and svpwm

Now run the simulation of cartesian2polar (cartesian to polar) and svpwm.

Directly double-click tb_svpwm_run_iverilog.bat to run the simulation, and the waveform file dump.vcd will be generated after running. Please open dump.vcd with gtkwave, you can see the waveform as Figure5.

Note: The three signals pwma_duty, pwmb_duty, and pwmc_duty are not in the top level. You can find them in the svpwm module.

Interpretation of Figure5 waveform:

  • theta θ is an increasmental angle (0→2π→0→2π→...)
  • x and y are quadrature sine waves generated with θ (in other words, y is a sine wave and x is a cosine wave).
  • Treat (x,y) as a Cartesian coordinate value, then cartesian2polar converts it to a polar coordinate system (rho, phi)=(ρ, φ).
  • Sending (ρ, φ) to svpwm, it will generate 3 saddle waves: pwma_duty, pwmb_duty, and pwmc_duty. If you are familiar with the principle of seven-segment SVPWM, you should know why it is a saddle wave, and I will not introduce it here.
  • pwma_duty, pwmb_duty, pwmc_duty determine the duty cycle of pwm_a, pwm_b, pwm_c respectively. You can zoom in on the waveform to verify this, see Figure6.
tb_svpwm
Figure5 : Simulation waveform of cartesian2polar and svpwm.
tb_svpwm_2
Figure6 : Zoom in Figure5.

 

 

 

 

 

FpOC

基于 FPGA磁场定向控制 (FOC),用于驱动永磁同步电机 (PMSM)无刷直流电机 (BLDC)

FOC控制算法对传感器采样速率和处理器算力提出了一定的要求,使用 FPGA 实现的 FOC 可以获得更好的实时性,并且更方便进行多路扩展多路反馈协同

本库实现了基于角度传感器(也就是磁编码器)的有感 FOC,即一个完整的电流环,可以进行扭矩控制。借助本库,你可以进一步使用 纯FPGAMCU+FPGA 的方式实现更复杂的电机应用。

diagram
图1:系统框图

本库代码有详细的注释,如果你熟悉 Verilog 但不熟悉 FOC ,可以通过阅读代码来快速地学习 FOC (建议先阅读 FOC 原理 [6~9])。一些用户在读代码时向本人反馈了一些疑问,我将它们整理在了 FAQ 里。

技术特点

  • 平台无关 :纯 RTL 编写,可以在 Altera 和 Xilinx 等各种 FPGA 上运行。
  • 支持 3路PWM + 1路EN :PWM=1 时上桥臂 MOS 导通,PWM=0 时下桥臂 MOS 导通。 EN=0 时所有的 6 个 MOS 关断。
  • 支持 12bit 分辨率角度传感器相电流采样ADC。对于>12bit的传感器,需要进行低位截断。对于<12bit的传感器,需要进行低位填充。
  • 内部使用 16bit 有符号整数进行计算,考虑到传感器为 12bit,所以 16bit 计算是够用的。

目录

 

示例程序:让电机转起来

图1 是示例程序的系统框图,它调用了我实现的 FOC 电流环模块 (foc_top.v) 来实现一个简单的行为——控制电机的电流(扭矩)按顺时针、逆时针、顺时针、逆时针地交替运行。同时,使用 UART 打印电流的控制目标值实际值,以便观察 FOC 电流环控制的质量。

该示例的所有代码都在 RTL 目录内。

搭建硬件

运行本示例所需要的硬件包括:

  • FPGA 开发板 :需有至少 10 个 3.3V 的 IO ,用来接:
    • I2C (2*IO) , 用来连接 AS5600 磁编码器。
    • SPI (4*IO) , 用来连接 AD7928 ADC。
    • PWM (3*IO) , 用来输出 3 相 PWM 到电机驱动板。
    • PWM_EN (1*IO) , 用来输出 1 路 EN (使能) 到电机驱动板(PWM_EN=低电平代表所有桥臂关断)。
    • UART (1*IO) ,单向(仅发送)的UART,连接计算机的串口,用于监测电流环的跟随曲线,可不接
  • PMSMBLDC 电机
  • 电机驱动板:要支持3相 PWM 输入信号(PWM=0时下桥臂导通,PWM=1时上桥臂导通),并且要内置低侧电阻采样+放大器对 3 相电流进行放大。
  • 获取转子角度的磁编码器:本库直接支持的型号是 AS5600 ,需要安装在电机上。
  • 相电流采样的ADC:本库直接支持的型号是 AD7928 ,用于采样电机驱动板放大后的 3 相电流
    • 网上似乎找不到现成卖的 AD7928 模块,所以如果你想DIY,就需要自己画 PCB。

如果你硬件动手能力很强,可以自己准备以上硬件。

不过!建议直接使用我画的一个自带 AD7928电机驱动板,它的原理图如图2,我也提供了制造文件 gerber_pcb_foc_shield.zip ,你需要拿制造文件去打样PCB,然后按照图2来焊接。

注意,这个板子包括了相电流采样的ADC电机驱动板的功能,但不包括 AS5600 磁编码器,磁编码器是需要安装在电机上的,需要你额外准备。

sch
图2:电机驱动板原理图,其中 AD7928 ADC 用来采样三相电流

这个板子在立创EDA开源,见 oshwhub.com/wangxuan/arduino-foc-shield

这个板子之所以被设计成 Arduino 扩展板的样子,是因为很多 FPGA 开发板也具有 Arduino 扩展板接口(比如 DE10-Nano 开发板),可以直接插上去。如果你的 FPGA 开发板没有 Arduino 扩展板接口也没关系,直接用杜邦线连接即可(建议用短的杜邦线)。

这里使用的电机驱动器是 MP6540 芯片, 我只试过驱动小功率云台电机,没试过大功率电机。

建立FPGA工程

你需要建立 FPGA 工程,把 RTL 目录(包括其子目录)里的所有 .v 源文件加入工程,请以 fpga_top.v 作为顶层文件。

时钟配置

fpga_top.v 中有一处调用了 altpll 原语,用来把开发板晶振输入的 50MHz 时钟(clk_50m 信号)变成 36.864MHz 的主时钟(clk 信号),altpll 原语只适用于 Altera Cyclone IV FPGA,如果你用的是其它系列的 FPGA,需要使用它们各自的 IP 核或原语(例如 Xilinx 的 clock wizard)替换它。

若你的开发板的晶振不是 50MHz ,你需要修改 PLL 的配置,保证主时钟 clk 信号的频率是 36.864MHz 即可。

实际上,主时钟 clk 的频率可以取小于 40MHz 的任意值。clk 是 FOC 系统的驱动时钟,clk 的频率会决定 SVPWM 的频率(SVPWM频率=clk 频率/2048),我选 36.864MHz 是因为可以让 SVPWM 频率 = 36864/2048 = 18kHz,只是为了凑个整数。

clk 的频率不能超过 40MHz 的原因是 adc_ad7928.v 会通过二分频来产生 SPI 时钟(spi_sck),而 ADC7928 芯片要求 SPI 时钟不能超过 20MHz。

引脚约束

fpga_top.v 的 IO 连接方法如下:

  • clk_50m : 连接在 FPGA 开发板的晶振上。
  • i2c_scl, i2c_sda : 连接 AS5600 (磁编码器) 的 I2C 接口。
  • spi_ss, spi_sck, spi_mosi, spi_miso : 连接 AD7928 (ADC芯片) 的 SPI 接口。
  • pwm_a, pwm_b, pwm_c : 连接电机驱动板的 3 相 PWM 信号。
  • pwm_en : 连接电机驱动板的 EN (使能) 信号。
    • 如果电机驱动板没有 EN 输入,则不接。
    • 如果电机驱动板有 3 路 EN 输入,每路对应 1 相,则应该进行一对三连接。
  • uart_tx : 连接 UART 转 USB 模块,插入计算机的 USB 口,用于监测电流环的跟随曲线,可不接

调参

要让电机正常工作,你需要在 fpga_top.v 中的第103行开始,根据实际情况调整 foc_top 模块的参数(Verilog parameter),包括:

参数名 取值范围 说明
INIT_CYCLES 1~4294967293 决定了初始化步骤占多少个时钟(clk)周期。该值不能太小,因为要留足够的时间让转子回归电角度=0。在clk频率为 36.864MHz 的情况下,可以取 INIT_CYCLES=16777216,则初始化时间为 16777216/36864000=0.45 秒。
ANGLE_INV 0, 1 若角度传感器没装反(A相→B相→C相→A相 的旋转方向与角度传感器的读值的增大方向相同),则该参数应取 0。若角度传感器装反了(A相→B相→C相→A相 的旋转方向与 角度传感器的读值的增大方向相反),则该参数应取 1 。
POLE_PAIR 1~255 电机极对数,根据电机型号决定(注意:电角度ψ = 极对数 * 机械角度φ)
MAX_AMP 1~511 SVPWM 的最大振幅,该值越小,电机能达到的最大力矩越小;但考虑到使用3相下桥臂电阻采样法来采样电流,该值也不能太大,以保证3个下桥臂有足够的持续导通时间来供ADC进行采样。在本例中,使用默认值 9'd384 即可。
SAMPLE_DELAY 0~511 采样延时,考虑到3相的驱动 MOS 管从开始导通到电流稳定需要一定的时间,所以从3个下桥臂都导通,到 ADC 采样时刻之间需要一定的延时。该参数决定了该延时是多少个时钟周期,当延时结束时,该模块在 sn_adc 信号上产生一个高电平脉冲,指示外部 ADC “可以采样了”。在本例中,使用默认值 9'd120 即可。

另外,foc_top 模块具有输入端口 KpKi ,它们是 PID 控制器的参数,会影响控制的质量。它们可以在运行时调整,不过你也可以给他们输入固定的常数。

// ports of foc_top.v
input  wire        [30:0] Kp,
input  wire        [30:0] Ki,

调好参后,综合并烧录到 FPGA 后,应该能看到电机正反交替运行。

用串口监视电流环

uart_tx 信号通过 UART 转 USB 模块 (例如 CP2102、CH340 模块) 连接到电脑上,就可以用串口助手Putty等软件来监测电流环的跟随效果。

注: UART 的格式是 115200,8,n,1

以下是串口打印的部分信息。其中第1~4列分别为:d轴电流的实际值d轴电流的目标值q轴电流的实际值q轴电流的目标值。可以看到,即使目标值从+200突变到-200,实际值能跟着目标值走,说明电流环的 PID 控制是有效的。

     -5       0     206     200 
    -16       0     202     200 
     16       0     192     200 
     15       0     201     200 
      1       0     197     200 
     17       0    -211    -200 
     -6       0    -199    -200 
    -10       0    -210    -200 
     -3       0    -207    -200 
      0       0    -202    -200 
    -15       0    -211    -200 

另外,你可以借用 Arduino IDE串口绘图器来实时显示电流跟随曲线。前往Arduino官网下载 Arduino IDE,安装后打开,在“工具→端口”中选择正确的COM口,然后点击“工具→串口绘图器”,串口绘图器会自动接收串口并使用上述4列数据画实时曲线图。

图3 是我这里绘制出的电流跟随曲线。蓝色曲线是第1列数据(d轴电流的实际值);红色曲线是第2列数据(d轴电流的目标值);绿色曲线是第3列数据(q轴电流的实际值);土黄色曲线是第4列数据(q轴电流的目标值)。可以看到实际值能跟着目标值走。

wave
图3:电流跟随曲线

 

设计代码详解

下表罗列了该工程使用的所有 Verilog 代码文件,这些文件都在 RTL 目录下。结合图1就能看出每个模块的作用。

文件名 功能 备注
fpga_top.v FPGA工程的顶层模块
uart_monitor.v UART 发送器,用于数据监测 不需要的话可以移除
i2c_register_read.v I2C 读取器,用于读取 AS5600 磁编码器
adc_ad7928.v AD7928 读取器
foc_top.v FOC+SVPWM (即图1中的蓝色部分的顶层) 固定功能,一般不需要改动
clark_tr.v Clark 变换 固定功能,一般不需要改动
park_tr.v Park 变换 固定功能,一般不需要改动
sincos.v 正弦/余弦计算器,被 park_tr.v 调用 固定功能,一般不需要改动
pi_controller.v PI 控制器(PID没有D) 固定功能,一般不需要改动
cartesian2polar.v 直角坐标系转极坐标系 固定功能,一般不需要改动
svpwm.v SVPWM 调制器 固定功能,一般不需要改动
hold_detect.v 监测3个下桥臂都导通时,延迟一段时间后触发 sn_adc 信号,指示ADC可以开始采样 固定功能,一般不需要改动
diagram
图1:系统框图

图1展示了这些模块的层次,我在设计模块层次时充分考虑了封装的合理性和代码重用 :

  • 粉色部分是FPGA内的即传感器控制器,是硬件相关逻辑,如果角度传感器和 ADC 型号变了,这部分代码需要重写。
  • 蓝色部分是FPGA内的 FOC 的固定算法,是硬件无关逻辑,一般不需要修改,是本库的核心代码!
  • 黄色部分是FPGA内的用户自定逻辑,用户可以修改 user behavior 来实现各种电机应用。或者修改 uart_monitor 来监测其它变量。
  • 淡橙色部分是FPGA外部的硬件电路,也就是电机、电机驱动板、角度传感器这些东西。

另外,除了 fpga_top.v 中调用的 altpll 原语外,该库的所有代码都使用纯 RTL 编写,可以轻易地移植到其它厂商(Xilinx、Lattice等)的 FPGA 上。

 

RTL仿真

因为我并没有电机的 Verilog 模型,没法对整个 FOC 算法进行仿真,所以只对 FOC 中的部分模块进行了仿真。

仿真相关的文件都在 SIM 文件夹里,其中包括文件:

文件名 功能
tb_clark_park_tr.v 对 clark_tr.v (clark变换) 和 park_tr.v (park变换)的仿真程序
tb_clark_park_tr_run_iverilog.bat 用 iverilog 运行 tb_clark_park_tr.v 的命令脚本
tb_svpwm.v 对 cartesian2polar.v 和 svpwm.v 的仿真程序
tb_svpwm_run_iverilog.bat 用 iverilog 运行 tb_svpwm.v 的命令脚本

使用 iverilog 仿真前,需要安装 iverilog ,见:iverilog_usage

clark_tr和park_tr的仿真

我们先来运行 clark 变换和 park 变换的仿真。

双击 tb_clark_park_tr_run_iverilog.bat 可以直接运行仿真,运行完后会生成波形文件 dump.vcd 。请用 gtkwave 打开 dump.vcd ,导入图4中的这些信号,可以看到如图4的波形(需要你把这些信号改成模拟信号显示的形式,才能看得到图4这种效果:第一步,对于 Verilog 代码中声明为 signed 的信号(有符号数),需要右键该信号→Data Format→Signed Decimal。第二步,右键该信号→Data Format→Analog→Step ,即可把它变成如图的模拟信号的样子)。

对该图4波形的解读:

  • theta 是一个不断递增的角度(0→2π→0→2π→...)
  • ia, ib, ic 是用 theta 生成的正弦波,相位各自相差 (2/3)*π (也就是说 ia, ib, ic)构成了三相正弦波。
  • 使用 clark 变换把 ia, ib, ic 变换成 ialpha, ibeta ,得到一对正交的正弦波(相位相差 π/2 )。
  • 使用 park 变换把 ialpha, ibeta 变换到定子坐标系,得到定值 id 和 iq (因为实际的计算误差,所以得到的是近似的定值,而不是严格的定值)。
tb_clark_park_tr
图4:对 clark_tr 与 park_tr 仿真的波形。

cartesian2polar和svpwm的仿真

现在来运行 cartesian2polar (直角坐标转极坐标系)和 svpwm 的仿真。

双击 tb_svpwm_run_iverilog.bat 可以直接运行仿真,运行完后会生成波形文件 dump.vcd 。请用 gtkwave 打开 dump.vcd ,可以看到如图5的波形。

注意: pwma_duty、pwmb_duty、pwmc_duty 这三个信号不在顶层,你要在 svpwm 这个模块内才能找到这三个信号。

图5波形的解读:

  • theta 是一个不断递增的角度(0→2π→0→2π→...)
  • x 和 y 是用 theta 生成的正交的正弦波(或者说,y是正弦波,x是余弦波)
  • 把 (x,y) 视作直角坐标值,然后 cartesian2polar 把它转换成极坐标系 (ρ, φ) ,也即 (rho, phi)
  • 把 (rho, phi) 输给 svpwm ,产生了 pwma_duty、pwmb_duty、pwmc_duty 这三个马鞍波。如果你熟悉七段式 SVPWM 的原理,就应该知道为什么是马鞍波,这里不做赘述。
  • pwma_duty、pwmb_duty、pwmc_duty 分别决定了 pwm_a, pwm_b, pwm_c 的占空比(duty这个单词就是占空比的意思)。
tb_svpwm
图5:对 cartesian2polar 与 svpwm 仿真的波形。

放大波形,可以看到确实是 duty 值越大,对应的 pwm 信号的占空比就越大,如图6

tb_svpwm_2
图6:图5的放大。

 

FAQ

一些用户在读代码时向本人反馈了一些疑问,我将它们整理如下。

关于 PCB 设计

  • 相电流低压侧3电阻采样需要运放放大电流信号才能作为AD输入,但你开源的PCB似乎找不到运放放大?
  • : 我开源的PCB使用了一体化的三相无刷电机驱动芯片MP6540(U1),3相电流采样电阻和放大器是集成在里面的。请注意MP6540的 SOA, SOB, SOC 三个引脚,它们就是三相电流放大后的电压输出。

关于 FOC 中的数学计算

  • 三电阻采样后的电流重构的那部分代码如何理解?为什么 ia = ADCb + ADCc - 2*ADCa ?

  • : 我们知道电机的相电流 ia, ib, ic 是双极性的(即有正有负的,分别代表流出电机和流入电机),但我们常用的ADC往往都是单极性的(即只能采样正电压)。那么,相电流采样-放大电路就必须考虑双极性到单极性的转换问题,工程上用的方法往往都是反向放大加偏置(包括MP6540内置采样-放大电路也是这种方案),它输出给ADC的电压遵循公式: ADCa = -R × ia + Voff ADCb = -R × ib + Voff ADCc = -R × ic + Voff 其中 R 是放大系数(R>0,也叫跨阻放大系数,因为 R 的量纲和电阻一样),因为反向放大所以加了负号。Voff 是偏置电压,以此保证 ADCa, ADCb, ADCc 是单极性的。另外又有基尔霍夫电流定律(KCL): ia + ib + ic = 0 联立以上公式,推出: 3 * Voff = ADCa + ADCb + ADCc 令 R = 1/(3*k) ,于是: ia = (Voff - ADCa) / R = k × (3 * Voff - 3 × ADCa) = k × (ADCa + ADCb + ADCc - 3 × ADCa) = k × (ADCb + ADCc - 2×ADCa) 于是就有了你问的 ia = ADCb + ADCc - 2×ADCa 。 你肯定会疑惑,系数 k 哪儿去了?这个并不在乎,因为整个FOC都是线性系统,通过调整PID参数,能跑就行,系数只在理论分析时有用。

  • : 你的程序里是不是都没有在乎系数K,包括clark变换中得到的Iα和Iβ和ia、ib、ic也并没有满足严格的公式关系,程序中得到的Iα和Iβ是理论值的2倍。这是不是也可以用调整PID参数的思想来解释?

  • : 是的,我很多地方的代码也与理论公式的系数不同,比如 clark 变换公式本来是: Iα = Ia - Ib/2 - Ic/2 Iβ = √3/2 * (Ib - Ic) 我多乘了个2: Iα = 2 * Ia - Ib - Ic Iβ = √3 * (Ib - Ic) 这是出于避免整数计算的截断导致的数据位丢失,比如 Ib/2 就会让 Ib 的最低 bit 丢失。不过实际上这种小误差基本不会影响控制质量。这种系数问题可以通过 PID 调参来消除。

  • : 你的代码中的 cartesian2polar.v 是把电压矢量从转子直角坐标系 (Vd, Vq) 变换到转子极坐标系 (Vrρ, Vrθ),目的是什么?

  • : 书上一般会说 SVPWM 模块输入的是定子直角坐标系下的电压,但我实现的 SVPWM 输入的是定子极坐标系下的电压,两种方法在数学上是等价的。而且 SVPWM 在 FPGA 里用查找表(ROM)实现,因此两种方法对电路复杂度影响不大。另外,输入极坐标系的 SVPWM 还带来 2 个好处和 1 个代价,好处 1 是更方便在开发过程中让电机开环地转起来(只需要让角度递增即可)。好处 2 是极坐标系下的 park 变换更简单,只需要用电压在转子坐标系中的角度减去电角度就能得到电压在定子坐标系中的角度。 代价是需要在 PID 的后面、park 变换的前面实现一个直角坐标系转极坐标系的运算,即 cartesian2polar.v

关于 ADC 采样时机

  • AD7928只有一个T/H(采样保持器),也就意味着这个AD一次只能保持一个通道的数据,也就是说当通道1 打开的时候采集A相的电流,然后采集完再打开通道2采集B相的电流,那么这并不是一个同步采集的过程,如何实现AD采样三相电流的同步输出?

  • : 在电流采样问题上,我们与大多数 FOC 方案相同,因为 MP6540 里的采样电阻在下桥臂,所以规定 SVPWM 在每个控制周期(约 55us,对应频率18kHz)内至少有一段时间里 3 相都是下通上闭,称为采样窗口。FOC的基础振幅(也就是 foc_top.v 里的 MAX_AMP 参数)越大,采样窗口越短。当 MAX_AMP=9'd511 (最大值) 时,采样窗口长度就是 0 了。而默认的 MAX_AMP=9'd384 大概会让采样窗口长度为十几us。 AD7928 只有一个T/H,所以采样窗口内要做 3 次采样,这个过程是 hold_detect.v 和 adc_ad7928.v 共同控制的,hold_detect.v负责在采样窗口开始时延迟一段时间(来让电流趋于稳定)后发出 sn_adc 信号脉冲,来告诉 adc_ad7928.v 可以开始工作了(可以通过 foc_top.v 里的 SAMPLE_DELAY 来调整该延迟)。然后 adc_ad7928.v 内部就会自动串行地完成 3 个通道的采样,最后再同步提交3个采样结果(提交的同时产生 o_en_adc 信号脉冲)。注意adc_ad7928.v是一个通用的 AD7928 控制器,每收到一个 i_sn_adc 信号脉冲,就进行一系列串行采样。其中采样多少次,每次采样哪一个通道,都可以通过 adc_ad7928.v 里的 parameter 来配置。所有通道采样结束后,产生o_en_adc信号脉冲,同时同步提交所有通道的结果。 我把 foc_top.v 用来连接 ADC控制器的接口(也就是sn_adc, en_adc, adc_a, adc_b, adc_c 这几个信号)设计成同步读入3通道数据,是出于通用性、简约性和可移植性的原则考虑,因为这样的同步读入接口是 ADC 的一种高度抽象,最容易让人理解其时序(即,sn_adc脉冲命令ADC控制器开始工作。en_adc指示ADC读取器结束工作,同时 adc_a, adc_b, adc_c 上产生结果)。如果用户用了其它 ADC 型号,只需按照这个时序的抽象来具象地编写 ADC 控制器即可,而 foc_top.v 并不关心拟用的是1个串行的ADC还是3个并行的ADC,反正你都要给我同步提交。当然,用户必须自己算好 hold_detect.v 的延时 + ADC 采样三个通道(也即 sn_adc 脉冲和 en_adc 脉冲的时间差) 是小于采样窗口的长度的。

  • 进行串行采样的时候不会出现这样的问题:第一个时钟周期采到的是A相的电流,第2个时钟周期采的是B相,第3个时钟周期采到的是C相,而我们知道相电流是正弦变化的,这三个时钟周期采的A B C 三相电流并不是同一时刻的相电流,因此这将产生误差,而时钟周期是很短的,是不是产生的误差几乎可以忽略不计呢?

  • : 首先指正一个不准确的地方, AD7928 的接口是 SPI (一种串行接口),其采样是多个时钟周期(而不是一个时钟周期)内完成的。因此三相的采样间隔是几十个时钟周期(具体数字我忘了,你可以仿真确定一下)。 虽然不同步,但3相的采样毕竟都是在同一个控制周期的采样窗口(几微秒)内。而相电流的变化通常以控制周期(即几十微秒)为尺度变化,例如 3000r/min(50r/s)的转子,若极对数=7,其相电流是350Hz(周期28ms)的正弦波,其变化在几微秒内是可以忽略的。

 

参考资料

GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/> Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. <one line to give the program's name and a brief idea of what it does.> Copyright (C) <year> <name of author> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: <program> Copyright (C) <year> <name of author> This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see <https://www.gnu.org/licenses/>. The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read <https://www.gnu.org/licenses/why-not-lgpl.html>.

简介

FPGA-based Field Oriented Control (FOC) for driving BLDC/PMSM motor. 基于FPGA的FOC控制器,用于驱动BLDC/PMSM电机。 展开 收起
Verilog 等 2 种语言
GPL-3.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Verilog
1
https://gitee.com/wangxuan95/FPGA-FOC.git
git@gitee.com:wangxuan95/FPGA-FOC.git
wangxuan95
FPGA-FOC
FPGA-FOC
main

搜索帮助