A Scheme for Realizing SPWM Waveform Based on C8051 Single Chip Microcomputer

Publisher:BlissfulBlissLatest update time:2013-01-22 Source: 电源在线网Keywords:C8051 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1 Introduction

  Sinusoidal pulse width modulation (SPWM) technology has been widely used in the fields of AC speed regulation, DC power transmission, variable frequency power supply, etc. In order to improve the control effect of the whole system, high-performance SPWM pulse forming technology has been a problem that people have been exploring. Using hardware circuits such as analog circuits and digital circuits to generate SPWM waveforms is a feasible method, but this implementation method has complex control circuits, poor anti-interference ability, and difficult real-time adjustment. In recent years, people have proposed digital control methods for SPWM waveforms using microcontrollers such as single-chip microcomputers and DSPs [1][2]. Since the microcontroller integrates many control circuits, such as timers, PWM circuits, programmable counter arrays, etc., this method of implementing SPWM has the advantages of simple control circuits, fast running speed, high control accuracy, and strong anti-interference ability. This paper introduces a method of using C8051 single-chip microcomputer to realize variable output frequency SPWM waveforms, and applies the unipolar SPWM wave generated by C8051F040 to a single-phase frequency adjustable inverter power supply. The experimental results confirm the feasibility and effectiveness of using C8051 to realize SPWM waveforms.

2 SPWM Technology Principle

  The basic principle of SPWM technology is to compare a triangular wave carrier with a sine wave to obtain a pulse sequence whose width changes according to the sine law, and use them to drive the switching conversion of the inverter switch tube. There are three methods to realize SPWM waveform by microcontroller: table method, real-time calculation method and real-time calculation method, but the first two do not have real-time processing capabilities [2]. The real-time calculation method requires a mathematical model. One of the more commonly used is the sampling type SPWM method, which is divided into natural sampling method, symmetrical regular sampling method and asymmetrical regular sampling method. This paper adopts the symmetrical regular sampling method, that is, the sampled sine wave (actually a step wave) is intersected with the triangular wave, and the pulse width is obtained from the intersection point. Figure 1 is a typical unipolar symmetrical regular sampling method. It only samples the sine modulated wave at the peak moment of the triangular wave and holds the sampled value. The held value and the intersection point of the triangular wave are taken as the pulse width time. In the figure, Ts is the period of the triangular wave, which is also the sampling period; Ur is the height of the triangular wave, and the sine wave is Ucsinωt. According to the triangle similarity relationship, we get

  so

  Among them, M=Uc/Ur is the modulation ratio, and t is the time of the sampling point (here is the vertex sampling). Then the pulse width is

  The sampling point time t is only related to the carrier ratio N. For the case of Figure 1, t = kTS + θ, where k = 0, 1, 2, ..., N-1, θ = 180/N degrees.


Figure 1 Symmetrical regular sampling method

  In the case of symmetrical regular sampling, as long as the sampling point time t is known, the pulse width tpw and time interval toff within this sampling period can be determined, thereby calculating the width of the high and low pulses of the SPWM waveform.

3 Principle and algorithm of C8051 to realize SPWM waveform

3.1 Introduction to PCA of C8051F Series MCU

  The C8051F series microcontrollers all have a programmable counter array PCA. Taking C8051F040 as an example, the PCA contains 1 dedicated 16-bit counter/timer and 6 16-bit capture/compare modules, which can output 6 PWM waveforms. As shown in Figure 2, there are multiple options for the time base signal of the 16-bit PCA dedicated counter/timer, which can be achieved by configuring the special function registers (SFR) of the relevant system controller. Each capture/compare module has its own I/O line CEXn, and the I/O line of each module can be connected to the port I/O by configuring the cross switch register (XBR0); each module can be configured to work independently, with four working modes: edge-triggered capture, software timer, high-speed output, and so on.

Figure 2 PCA principle block diagram [page]

Output or pulse width modulator. In this article, the variable frequency SPWM waveform is generated by using the high-speed output working mode of the capture/compare module. The principle is as follows:

  When the PCA's 16-bit counter/timer PCA0H (high 8 bits) and PCA0L (low 8 bits) match the 16-bit capture/compare module registers PCA0CPHn (high 8 bits) and PCA0CPLn (low 8 bits), the logic level on the module's CEXn pin will change and generate an interrupt request, setting the corresponding CCFn bit in the control register PCA0CN. When the CCF interrupt is enabled, the CPU will turn to the CCF interrupt service routine. If the I/O line CEXn of the corresponding module is connected to the port I/O, the output level of the corresponding port of the microcontroller will change, which can achieve high and low level output of PWM pulses. Setting the TOGn, MATn, ECOMn and ECCFn bits in the PCA0CPMn register will allow high-speed output mode and CCF interrupts [3].

3.2 SPWM waveform generation method

  The basic principle of using the PCA counter of C8051 to generate SPWM waveform is: under high-speed output and allowing CCF interrupt mode, the pulse width of the pre-calculated SPWM waveform is continuously added to the capture/compare module register PCA0CPn (high 8-bit PCA0CPHn and low 8-bit PCA0CPLn) in the CCF interrupt service program. In this way, when the capture/compare module register and the counter/timer match, the corresponding SPWM waveform with alternating high and low levels is obtained.

  In Figure 3, l0, h0, l1, h1…lmax, hmax are the high and low pulse widths of a unipolar SPWM waveform calculated by the software in real time, where l0 = l0'+T/2. Since the output is a variable frequency SPWM waveform, that is, the modulation wave frequency is variable, different carrier ratios N are set in different frequency bands, so the value of max is only relatively fixed.

 


Figure 3 SPWM waveform diagram


  If the capture/compare module 0 is selected to output this SPWM, first l0' is loaded into the 16-bit capture/compare register PCA0CP0, and the 16-bit counter/timer PCA0H and PCA0L are cleared, and then the PCA counter is started; when the value of the capture/compare register is equal to the value of the counter/timer, the CEX0 pin will jump from the original low level to the high level, and a CCF interrupt will be generated; in the CCF interrupt program, h0 is accumulated to PCA0CP0; during the interrupt process, the value of the counter is continuously increased, and when its value is equal to the value of the changed capture/compare register, the CEX0 pin will jump from the original high level to the low level, and a CCF interrupt will be generated; then l1 is accumulated to PCA0CP0 during the interrupt process. In this way, the CEX0 pin will continuously generate alternating high and low levels, so that an accurate SPWM waveform can be obtained on the corresponding port I/O.

3.3 PCA Register Settings

  In order to implement the above SPWM waveform generation method, it is necessary to set the special function registers related to PCA operation. The details are as follows:
  1) Set the mode selection register PCA0MD.
  2) Initialize the capture/compare registers PCA0CPHn (high byte) and PCA0CPLn (low byte).
  3) Set the capture/compare mode register PCA0CPMn.
  4) Initialize the counter/timer PCA0H (high byte) and PCA0L (low byte).
  5) Set the control register PCA0CN.

3.4 Program Flow

  The main program flow is shown in Figure 4. After the system is initialized, the output frequency is first set through the keyboard, and then the SPWM pulse width calculation program is entered. The modulation ratio N is selected according to the set frequency, the pulse width is calculated, and the max is determined. In the SPWM output program, the PCA special function register is set and the counter is started to start outputting the SPWM waveform.

  In the interrupt service program, first determine the capture/compare module where the match occurs based on the value of CCFn, and then determine whether to add the high-level pulse width value or the low-level pulse width value of the SPWM waveform to the capture/compare module register based on the level state of the module's CEX pin; at the same time, determine the end of an SPWM cycle and the beginning of the next cycle based on whether the pulse width data pointer is equal to max, so as to correctly load the corresponding data. When the carrier ratio N changes, the value of max will change.

 


Figure 4 Program flow chart [page]

  One thing that should be noted is that the CCFn bit and CF bit (counter/timer overflow flag) are set by hardware, but cannot be automatically cleared to 0 by hardware and must be cleared to 0 by software in the interrupt program.

4 Analysis of the minimum pulse problem

  Due to hardware reasons, no microcontroller can output pulses with infinitely small widths, which means that narrow pulses less than a certain width in the ideal SPWM pulse sequence cannot be output normally, which is the minimum pulse problem.

  For the C8051 microcontroller, the minimum pulse that its PCA can output depends on the execution time of its interrupt service program, so its minimum pulse problem cannot be ignored. The specific methods to solve this problem are: ① Use assembly language to write the interrupt service subroutine and apply the most concise and time-saving instructions to reduce the width of the minimum pulse; ② When calculating the SPWM wave pulse width, correct the pulses whose width is less than the minimum width that the PCA can output so that their width is the width of the minimum pulse; ③ Limit the modulation ratio M so that the SPWM pulse sequence does not contain too many small pulses.

5 Experimental Results

  The main circuit of the experiment is a single-phase full-bridge inverter circuit. The main switch tube uses IGBT, which outputs 100V, 50-400Hz adjustable frequency AC voltage. The single-chip microcomputer outputs two complementary (with a certain dead time) unipolar SPWM waves to control the inverter power supply.

  In the experiment, the minimum pulse problem of the output SPWM wave was dealt with, and the interrupt service subroutine was programmed in assembly language, so that the width of the minimum pulse in the SPWM waveform reached 3us, which basically reached the minimum switching period of the IGBT used in the experiment. Figure 4 shows the experimental waveforms of two unipolar SPWM waves, and Figures 5 and 6 show the output voltage experimental waveforms at frequencies of 200Hz and 300Hz respectively:

 

  It can be seen from the experimental waveform that the control effect of the SPWM wave generated by C8051 is better, and the frequency of the output voltage can be adjusted accurately and in real time.

6 Conclusion

  Using C8051 single-chip microcomputer to generate SPWM waveform is a simple and easy method, which has the characteristics of high calculation accuracy and strong real-time adjustment. At the same time, by changing the method of calculating the pulse width of SPWM wave, bipolar SPWM waveform can be easily realized. Therefore, this method is suitable for occasions with different requirements on the polarity, number of paths and frequency of the output SPWM waveform.


References

[1] Li Zicheng et al. Research on SPWM wave formation based on 87C196MC [J]. High Voltage Technology, 2004 (12): 10-12
[2] Lu Huifen. A method for generating SPWM control waveform based on DSP [J]. Mechanical and Electrical Engineering, 2002 (5): 30-34
[3] Li Gang, Lin Ling. High-performance, high-speed microcontroller compatible with 8051 - C8051Fxxx. Beijing: Beijing University of Aeronautics and Astronautics Press, 2002

Keywords:C8051 Reference address:A Scheme for Realizing SPWM Waveform Based on C8051 Single Chip Microcomputer

Previous article:Design of Real-time Clock X1226 Controlled by Single Chip Microcomputer
Next article:Design of three-phase bridge controllable trigger circuit based on ATMEL89S52 single chip microcomputer

Recommended ReadingLatest update time:2024-11-16 16:40

A Scheme for Realizing SPWM Waveform Based on C8051 Single Chip Microcomputer
1 Introduction Sinusoidal pulse width modulation (SPWM) technology has been widely used in the fields of AC speed regulation, DC power transmission, variable frequency power supply, etc. In order to improve the control effect of the whole system, high-performance SPWM pulse forming technology has been a proble
[Power Management]
A Scheme for Realizing SPWM Waveform Based on C8051 Single Chip Microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号