The so-called PWM is to use the ratio of high-level time and waveform period to represent a number. If this number becomes a nearly continuous curve after filtering, it is DA conversion; if the voltage to control the motor is expressed by this ratio, then it is motor control. Everything that can be quantified can be expressed in PWM, which is why PWM is widely used.
Methods for generating PWM:
1. Generate a counter that rolls over after a full pulse period.
2. Generate a comparator, which outputs a high level when it reaches the proportional position, otherwise it outputs a low level. The whole process is shown in the figure below.
FPGA is essentially a digital circuit. In order to generate the results in the above figure, we need to design two circuits according to the above two-step process. The first circuit is a counter, and the second circuit is a comparator behind the counter, which monitors the counter output. Once it is higher than the count value corresponding to the duty cycle, it becomes 0, and it is 1 at other times. In this way, PWM is basically realized. This corresponds to the following two pieces of code:
//Counter circuit, cnt_cycle is the counter output count result always@(posedge clk)
begin
cnt_cycle <= (cnt_cycle == (T-1)) ? 0 : cnt_cycle + 1;
end
/ Comparator circuit, pwm_buf is the output PWM result, the red word is the counter input, and the green word is the comparator comparison line /
always@(posedge clk)
begin
pwm_buf <= (cnt_cycle < duty_cycle_buf) ? 1'b1 : 1'b0;
end
In other words, the circuit corresponding to the above two codes is as follows:
Regarding the above circuit, I would like to make a point: the implementation of the counter in FPGA is composed of an adder and a trigger. The adder outputs +1 each time, and the +1 result is given to the output terminal at the next clock. This is not the result of asynchronous 2-frequency division in the digital electronic textbook at all! In addition, I would like to emphasize again that due to the limitations of practical factors in the design of FPGA, some theoretical models in the digital electronic textbook are difficult to apply in large quantities in practice, so many structures and comprehensive results inside FPGA are different from those in the digital electronic textbook, but the basic principles of digital circuits have not changed at all!
There is one last point missing for PWM, because the input duty cycle can change continuously, that is, the comparison line in the first picture will move up and down. In order to avoid affecting the sudden value collected during the counting process, which will eventually lead to an unsmooth duty cycle, the duty cycle input will be collected only after each counting cycle is completed. This is what you see:
always@(posedge clk)
begin
if(cnt_cycle == (T-1)) duty_cycle_buf <= (duty_cycle > T-1) ? T-1 : duty_cycle;
end
Only when cnt_cycle counts a period T, the duty cycle value will be updated, that is, the comparison line will move!
Previous article:What is Pulse Width Modulation? Using buttons to control the PWM duty cycle
Next article:Explanation of three algorithms for PLC programming
Recommended ReadingLatest update time:2024-11-14 22:26
- Popular Resources
- Popular amplifiers
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Design of high-resolution DPWM module for digital power supply
- A low-latency and low-power PWM comparator circuit design
- Peak current mode PWM boost switching power supply chip design_Cui Zheyu
- Red Hat announces definitive agreement to acquire Neural Magic
- 5G network speed is faster than 4G, but the perception is poor! Wu Hequan: 6G standard formulation should focus on user needs
- SEMI report: Global silicon wafer shipments increased by 6% in the third quarter of 2024
- OpenAI calls for a "North American Artificial Intelligence Alliance" to compete with China
- OpenAI is rumored to be launching a new intelligent body that can automatically perform tasks for users
- Arm: Focusing on efficient computing platforms, we work together to build a sustainable future
- AMD to cut 4% of its workforce to gain a stronger position in artificial intelligence chips
- NEC receives new supercomputer orders: Intel CPU + AMD accelerator + Nvidia switch
- RW61X: Wi-Fi 6 tri-band device in a secure i.MX RT MCU
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- About USB2.0 plug-in and switch
- [Atria AT32WB415 Series Bluetooth BLE 5.0 MCU] + Bluetooth communication
- xilinx vivado xdc constraint syntax
- Design and Implementation of Digital Video Conversion Interface Based on FPGA
- [AT-START-F403A Evaluation] VI. FreeRTOS system based on IAR security library (sLib) secondary development mode practice
- About the 2021 E-Sports Championship
- [ST NUCLEO-G071RB Review]——First Look at the Kit
- FPGA Advanced Timing Synthesis Tutorial
- How reliable is Dupont wire???
- Classic Books on Signal Integrity Design