## 0. Table of contents **1. Foreword** **2. Team introduction** **3. Project analysis** **4. Schematic circuit analysis** **5. PCB design analysis** **6 . Physical display** **7. Work assembly** **8. Program design** **9. Summary** ## 1. Preface This work is the signal distortion measurement of question A of the 2021 National College Student Electronic Design Competition. The installation, due to the tight competition time, the work was roughly produced. The work finally won the first prize in the Beijing competition area and the second prize nationally. This is also the first open source project. Everyone is welcome to raise questions and discuss it together. Submit the demonstration video to station b [Demo Video](https://www.bilibili.com/video/BV1wP4y1H7mS/). ## 2. Team introduction Team members: Martin Yi, Sun Yuli, Ling Hao. Martin Yi, majoring in automation at the School of Electronic Information Engineering, Beijing Jiaotong University. Mainly responsible for microcontroller development. Sun Yuli, majoring in electronic science and technology, is mainly responsible for the hardware part, such as circuit design, device selection, circuit welding, etc. Ling Hao, majoring in communication engineering at the School of Electronic Information Engineering of Beijing Jiaotong University, is mainly responsible for the direction of microcontrollers in the team. He started preparing for the electric competition during the winter vacation of his junior year. During this period, he worked on a line patrol car and worked on the C and D questions of the 2019 electric competition. , completed the differential amplification circuit tester for the electronic design competition within the school competition, and finally prepared for the national competition, completing the production of the signal distortion measurement device for question A. ## 3. Project Analysis### 3.1 Basic requirements (1) The peak-to-peak voltage range of the input signal: 300mV~600mV. (2) Input signal fundamental frequency: 1kHz. (3) Input signal distortion range: 5%~50%. (4) It is required that the absolute value of the input signal distortion measurement error |THDx-THDo|≤5%, THDx and THDo are the measured value and nominal value of the distortion respectively. (5) Display the distortion measurement value THDx. (6) The distortion measurement and display takes no more than 10 seconds. ### 3.2 Play part (1) The peak-to-peak voltage range of the input signal: 30mV~600mV. (2) Input signal fundamental frequency range: 1kHz~100kHz. (3) Measure and display the input signal distortion THDx value, requiring |THDx-THDo| ≤ 3%. (4) Measure and display a periodic waveform of the input signal. (5) Display the normalized amplitude of the fundamental wave and harmonics of the input signal, and only display the 5th harmonic. (6) Display the THDx value of the input signal measured and displayed by the measuring device, a periodic waveform, the normalized amplitude of the fundamental wave and harmonics on the mobile phone. (7) Others. ### 3.3 Analysis This question requires that the main controller and data collector used for signal distortion measurement must use TI's MCU and its on-chip ADC, and other off-chip ADC and data acquisition module (card) finished products must not be used, so the signal The MCU of the acquisition module is selected from the processor series produced by TI. Considering that the highest signal frequency required to be measured by the question is 100kHz, and the fifth harmonic requires a sampling frequency of 1MHz to satisfy the Nyquist sampling theorem, the C2000 series processor was selected as the main control chip and its on-chip ADC was used for sampling. C2000 is a 32-bit high-performance real-time microcontroller produced by TI. It has an on-chip 12-bit ADC, the main clock frequency can reach 200MHz, the running speed is relatively fast, and the real-time performance is relatively good. Since there happens to be a 28379D development board in the laboratory, this development board was chosen. For development board information, see [LAUNCHXL-F28379D](https://www.ti.com.cn/tool/cn/LAUNCHXL-F28379D). ![28379D development board.png]

For the data processing part, the frequency domain analysis method is used, and the ADC sampling value is subjected to FFT transformation to obtain the amplitude of different frequencies in the signal. Substitute into the THD calculation formula to obtain the distortion. This solution has low hardware cost and simple circuit. ## 4. Schematic circuit analysis The circuits in this work are all designed using Lichuang EDA. The complete circuit diagram is shown in Appendix 5. However, only the input signal processing part has been prototyped (see attachment 6 for the gerber file of the board designed using the 2017 e-sports competition). ![Schematic_2021 Question A-Signal Distortion Measurement Device_2021-12-09.png]

### 4.1 The DC blocking amplifier circuit is as shown in the figure. The input signal processing circuit is composed of an RC filter circuit and a non-inverting adder circuit: An RC high-pass filter is connected in front of the non-inverting adder to filter out the DC component that may be contained in the signal, and then the non-inverting adder is used to lift and amplify the DC-blocked signal. The non-inverting adder circuit is composed of TI's OPA227 operational amplifier. The OPA227 operational amplifier combines low noise, wide bandwidth and high accuracy, making it ideal for applications requiring both AC and precision DC performance. ![DC blocking amplifier circuit.png]

Since the question requires the frequency range of the input signal to be 1kHz-100kHz and the peak-to-peak voltage range to be 300mV-600mV, the cutoff frequency of the RC filter must be less than 1kHz, so the capacitor C29 in the circuit diagram is 1uF. , the resistance component R43 is taken to be 10kΩ. Let R46=R45=R42=R, then the output voltage of the non-inverting adder is U0=(R41+R)/2R (U_1+U_2), where U1 is the input signal voltage and U2 is the input addition obtained by resistor division. The DC voltage of the device is about 0.33V. The amplification factor of this circuit: Au=(R41+R)/2R=(7k+1k)/(2×1k)=4. The amplified signal meets the microcontroller voltage sampling range of 0~3.3V. ### 4.2 Hysteresis comparator circuit Since the improvement part requires the frequency range of the input signal to be 1kHz~100kHz, the sampling rate cannot be determined when the frequency of the input signal is unknown, so the hysteresis comparator is used to convert the input signal into a square wave, and we get Fundamental frequency, thereby determining the sampling frequency and then performing subsequent processing. The hysteretic comparator circuit is constructed using TI's comparator LM339. The LM339 comparator can be powered by a single power supply over a wide voltage range, and the drain current is not affected by the supply voltage. The hysteresis comparator is a comparator with hysteresis loop transmission characteristics. On the basis of the inverting input single-threshold voltage comparator, a positive feedback network is introduced to form an inverting input hysteresis comparator with double thresholds. ![Hysteresis comparator circuit.png]

The circuit is as shown in the figure. R3 and R4 divide the voltage to obtain the reference voltage Vr=1.35V. The ratio of R2 and R1 and Vr determine the high and low level threshold voltages. Let R2/R1=10, The obtained high-level threshold voltage is about 1.5V, and the low-level threshold voltage is about 1.2V, which meets the threshold level requirements of the converted square wave of the input signal. ## 5. PCB design analysis Notes: (1) The power line and ground wire should be as thick as possible to provide larger current. (2) The relationship between line width is: ground wire > power line > signal line. Usually the signal line width is: 0.2~0.3mm, the thinnest width can reach 0.05~0.07mm, and the power line is 1.2~2.5 mm. (3) The decoupling capacitor should be directly connected to VCC as much as possible and physically close to the chip pins. (4) The digital ground and analog ground should be grounded separately as much as possible. (5) The connection should be streamlined, as short as possible and with as few turns as possible. (6) The outer frame should be as square as possible and the mounting holes should be reserved. Due to time constraints, the amplification circuit part of this competition used the PCB board that was previously made at Lichuang, and the other parts were manually welded on the perforated board. ![PCB welding.jpg]

## 6. Physical display The demonstration video is too large and submitted to station b [Demo Video](https://www.bilibili.com/video/BV1wP4y1H7mS/). ![Work picture.jpg]

## 7. Assembling the work As shown in the picture, the red box is the hysteresis comparator part, the yellow box is the positive and negative power supplies and ground, the blue box is the serial port part, the left blue box is connected to the serial port screen, and the right blue box is connected to Bluetooth. The module location takes into account the location of the pins of the connected microcontroller and is placed according to the principle of proximity. The assembly sequence is to first weld the hysteresis comparator circuit and the input part circuit, then weld the header where the microcontroller is placed, and finally lead out the serial port pin header. ![Work assembly.png]

The main module purchase link is as follows: [Development board](https://detail.tmall.com/item.htm?spm=a230r.1.14.27.6eca3d562tw6fJ&id=624725872138&ns=1&abbucket=15&skuId=4425672800866) [ Serial screen](https://item.taobao.com/item.htm?spm=a1z09.2.0.0.54212e8dtdHvrJ&id=630642252956&_u=92nrab05ce14) [Bluetooth module](https://detail.tmall.com/item.htm? spm=a230r.1.14.16.40f253edXYpzzc&id=24077608890&ns=1&abbucket=15) The Bluetooth module uses HC05, which is compatible with most Bluetooth modules. You can use what you have on hand for testing. Pay attention to the power supply voltage of the Bluetooth module. ## 8. After the programming equipment is powered on, the program starts to be executed. The ADC samples and counts the square wave frequency to obtain the fundamental frequency. After obtaining the time domain data and fundamental frequency of the measured signal, the FFT transformation is performed to obtain the corresponding frequency domain data. Based on the frequency domain amplitude, the frequency domain amplitude of the harmonic frequency point is obtained to calculate the distortion degree and normalized amplitude. The calculation results are transmitted to the serial port screen through serial communication and to the mobile phone through the Bluetooth module, and the calculation results are displayed; continuously This process is cycled and the values are displayed in real time. ![Software flow chart.png]

The mobile APP part uses the WxBit graphical programming system to create an APP that receives data through the HC-05 Bluetooth module and displays it in real time. The Bluetooth module and serial port screen use SCIB and SCIC respectively. ## 9. Summary: First of all, during the three days and four nights of competition, time was tight and it was difficult to design and implement the work in an all-round way. The writing of the final design report was also rushed and lacked a certain quality; secondly, it was not timely. After reading the modifications made by the organizing committee to the answers to the restricted questions of the competition (Question A cannot use any microcontroller other than those generated by TI), it resulted in the solution we originally designed and are already working on (C2000ADC collects signal data and transmits it to STM32 data processing) wasted some precious time; we spent a lot of time and patience on the normal operation of the external circuit, TI microcontroller program debugging, serial screen and mobile phone Bluetooth display, carefully troubleshooting the problem, teamwork, and luckily it was finally completed successfully production of the work. In this open source, if there are any inappropriate or problematic areas, I hope my friends will correct me and learn from each other. The preparations for this e-tournament started during the winter vacation and have ended up taking a year. I learned a lot during the preparation process. I would like to thank everyone in the team for their efforts, and I would also like to thank the three teachers Weisxint, XZhao, and Kurui for their year-long training and guidance (づ ̄3 ̄)づ╭❤~.