### Project Introduction
This work designs and produces a signal distortion measurement device, with a 32-bit MSP-EXP432E development board as the control core, and the periphery consists of a low-pass filter circuit, an adjustable amplifier circuit, a polarity conversion circuit, a zero-crossing comparison circuit, a display screen, and an HC06 Bluetooth module. First, the input signal is filtered through a low-pass filter to remove the high-frequency components, and then the signal is amplified by an adjustable amplifier circuit. On the one hand, the amplified signal is passed through a polarity conversion circuit to make the signal amplitude of all bands as wide as possible between 0-3.3V, and on the other hand, it is converted into a square wave through a zero-crossing comparison circuit so that the microcontroller can obtain the signal frequency. After the microcontroller samples the amplitude and frequency of the input signal, it uses the coherent detection method to extract and calculate the harmonic components to obtain THD, and finally transmits the data to the APP through the Bluetooth module to realize the display of signal distortion. This system has completed all the requirements of the topic, and the test results show that the design has the characteristics of high accuracy and fast response.
- - -
### Project Function Introduction
Introduction and brief introduction to the relevant functions of the project, such as:
1. It can accurately measure the distortion of input signals with a voltage range of 30-600mv and a base frequency of 1kHz-100kHz, with an error of ≤5%;
2. The normalized amplitude of the measured distortion value and the waveform of one cycle can be displayed on the LCD screen, and the calculation time does not exceed 10s;
3. The distortion data can be transmitted to the APP through the Bluetooth module for display.
- - -
### Project Properties
Here you can fill in the completion progress bar of the project, select the check box according to the completed function, or use it as a function completion progress adjustment display
* [x] Schematic design
* [x] PCB design*
[x] PCB proofing* [
x] Welding test
* [x] Functional test
* [x] Program test
- - -
### Circuit explanation
The hardware circuit of this system consists of four parts: low-pass filter circuit, adjustable amplifier circuit, polarity conversion circuit, and zero-crossing comparison circuit.
(1) Low-pass filter circuit design
In order to filter out the interference of high-frequency signals above 500KHz, FilterPro is used to design a low-pass filter with a cutoff frequency of 500KHz, and a two-stage second-order low-pass filter is obtained as shown in Figure 1.
![image.png]

Figure 1 Low-pass filter circuit
(2) Adjustable amplifier circuit design
The adjustable amplifier circuit consists of two parts: a programmable amplifier circuit and an inverting amplifier circuit. The programmable amplifier circuit adjusts the size of the digital potentiometer by judging the range of the signal amplitude by the single-chip microcomputer to control the amplification factor of the first-stage amplifier circuit; the programmable amplifier circuit and the inverting amplifier circuit jointly make the signal amplitude meet the sampling requirements of the single-chip microcomputer. The adjustable amplifier circuit is shown in Figure 2.
![image.png]

Figure 2 Adjustable amplifier circuit
(3) Polarity conversion circuit design
The polarity conversion circuit realizes the signal amplitude increase based on the differential amplifier circuit, so that the signal amplitude of all bands is distributed as widely as possible between 0-3.3V to ensure that the signal sampled by the single-chip microcomputer is full-scale and undistorted. The polarity conversion circuit is shown in Figure 3.
![image.png]

Figure 3 Polarity conversion circuit
(4) Zero-crossing comparison circuit design The
purpose of the zero-crossing comparison circuit is to convert the sinusoidal signal into a square wave signal so that the microcontroller can obtain the signal frequency through the timer. The zero-crossing comparison circuit is shown in Figure 4.
![image.png]

Figure 4 Zero-crossing comparison circuit
**Circuit parameter design analysis**
**![image.png]

- - -
### Software```
C
void GPIOCap_Handler(void)
{
unsigned long ulStatus;
ulStatus = GPIOIntStatus(GPIO_PORTB_BASE, true); // Read interrupt status
GPIOIntClear(GPIO_PORTB_BASE, ulStatus); // Clear interrupt statusif
(ulStatus & GPIO_PIN_5)
{
TempFrequantNum++;
}
}
void Find_AWave(uint16_t *samplebuff,uint16_t *Wavebuff)
{
for(uint16_t i=0;i>8);
sendadcval[2*i+1] = (uchar)(tempbuff[i]);
//UARTprintf("%4dr",tempbuff[i]);
}
}
if(ModeType == 1)
{
for(int i=0;i>8);
sendadcval[2*i+1] = (uchar)(tempbuff[i]);
}
for(int i = 0;i<20;i++)
{
//CalWave20[i] = (float)tempbuff[i]/4096.0f*3.30f;
CalWave20[i] = (float)tempbuff[i];
//UARTprintf("%4dr", tempbuff[i]);
}
}
}
int main(void)
{
uint32_t aimfrequant = 0;
/* Configure the system clock for 120 MHz */
systemClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480),
120000000);
/* Initialize serial console */
ConfigureUART(systemClock);
/* Enable the clock to GPIO Port E and wait for it to be ready */
ADC_Sample(2000000);
spi_init();
MCP41010_SetRes(0 );
FPULazyStackingEnable();
FPUEnable();
InputCapInit();
Timer1A_init();
Uart_Send_Init();
//Usart6Config();
ILI9341_INITIAL();
LCD_Clear(WHITE);
Make_ACG();
/* Wait loop */
while(1 )
{
/* Wait for the conversion to complete */
//while(!bgetConvStatus);
//
// for(i=0;i<200;i++)
// {
//
// UARTprintf("%4drn", srcBuffer[i]);
// }
FindAndResolveData();
if(ModeType == 2)
{
basefre = Get_SinWave_ValidValues(1);
freq2 = Get_SinWave_ValidValues(2);
freq3 = Get_SinWave_ValidValues(3);
freq4 = Get_SinWave_ValidValues(4);
freq5 = Get_SinWave_ValidValues(5);
tempNum = freq2*freq2+freq3*freq3+freq4*freq4+freq5*freq5;
arm_sqrt_f32(tempNum,&tempNum);
tempDHT = tempNum / basefre;
}
if(ModeType == 1)
{
basefre = Get_SinWave_ValidValues_20(1);
freq2 = Get_SinWave_ValidValues_20(2);
freq3 = Get_SinWave_ValidValues_20(3);
freq4 = Get_SinWave_ValidValues_20
(4); freq5 = Get_SinWave_ValidValues_20(5);
tempNum = freq2*freq2+freq3*freq3+freq4*freq4+freq5*freq5;
arm_sqrt_f32(tempNum ,&tempNum);
tempDHT = tempNum / basefre;
}
ADC_Sample(SampleNum);
Normalnization();
PackAndSendBuff(FrequantNum,Normalbasefre,Normalfreq2,Normalfreq3,Normalfreq4,Normalfreq5,tempDHT,sendadcval);
Show_FrequantList();
drawXY();
//SysCtlDelay(4*systemClock/1/3 );
LCD_Clear(WHITE);
if(FrequantNum<20000)
{
SampleNum = FrequantNum * 100;
ModeType = 2; //Select mode 2
}
else if(FrequantNum<=100000)
{
SampleNum = FrequantNum * 20;
ModeType = 1; //Select Mode 1
}
else
{
SampleNum = 2000000;
ModeType = 1; //Select mode 1
}
aimfrequant = FrequantNum;
basefre = 0;
freq2 = 0;
freq3 = 0;
freq4 = 0;
freq5 = 0;
tempNum = 0;
tempDHT = 0;
}
}
```
- - -
###
Schematic diagram:![image.png]

PCB diagram:![DJ96W16A)S{VH}OSA~46@O.png]

3D diagram:![image.png]

Actual diagram:![222.jpg]

APP display diagram:![Cache_211f4b567e8bc1e..jpg]

- - -
### Demo video
Demo video see project attachment
- - -
### Notes
1. Try to make the loop area as small as possible during PCB layout. Secondly, pay attention to prevent circuit oxidation during welding and prevent positive and negative misconnection of the power interface.
2. Before using resistors and capacitors, remember to measure the size of their parameters first to prevent aging components from affecting the stability of the circuit and signal interference;
3. During the test, pay attention to the input and output characteristics of each interface when wiring to prevent wrong connection. Be careful not to use too much force during the use of the SMA socket to prevent interface loss from causing unstable signal transmission.
* **Experience**:
I encountered various problems during the test, but I overcame the difficulties through thinking and active modification. My major is electronic information engineering. This competition allowed me to use the theoretical knowledge of digital signal processing in the experiment, and I am very happy. I hope that my friends will not be discouraged when they encounter difficulties in the production process, and carefully check the problems. I also did something wrong this time. I bought one less component when purchasing. Fortunately, I found this chip on the laboratory board. In the subsequent work, I must be meticulous in my cognition. I learned not only the theory, but also the teamwork ability. Only with smooth teamwork can I complete the task so quickly and with such high quality. In addition, this is my first open source. If there is anything wrong, I hope my friends will correct it and learn from each other.