**3.2 Power quality monitoring concept**

238 Electrical Generation and Distribution Systems and Power Quality Disturbances

The flowchart of the sampling concept shown below is to illustrate how the concept

To explain the process of the sampling concept flowchart in Fig. 8., it is supposed to follow as the picture shown. After the used registers and utilized variables have been initialized, the procedures will work according to the conditions. That is, if the sampling condition is on operation, the procedure will do the sampling from the analog signals to the digital ones of the 3 channels. And the next procedure is to write the digital sampling data which are packed in the form of data frames to the external memory board. But if the counted data packet from the frame count value is excessive over the maximum limit, it will seek to the beginning of the first address in the external memory. Meanwhile, the data packet which is

direction works according to the objectives of this chapter.

Fig. 8. Flowchart of the sampling concept

**3.1 Sampling concept** 

It is generally a conceptual method to monitor power quality used with the embedded system of LPC2368 microcontroller board as shown in the flowchart of Fig. 9.

Fig. 9. Flowchart of the power quality monitoring concept

A Power Quality Monitoring System

**3.4 Configuration data**

contents of the configuration file are shown below:

**3.5 Ethernet packet stream structure** 

struct fault\_info {

The structure of Ethernet packet stream is shown below:

ip = 192.168.0.200 //Hardware IP id = 1 //Hardware Number port= 2000 // UDP Port

offset0 = 1.246 //Channel 0 Offset offset1 = 1.242 //Channel 1 Offset offset2 = 1.251 //Channel 2 Offset

phase = 3 //Select 1 or 3 Phase System

struct display\_info { /\* Display structure type\*/

3-phase system. \*/

offset.

each node.

};

};

shown in Fig. 11.

Via the Ethernet Network Based on the Embedded System 241

Where *V* is the floating point voltage, *X* is the 12-bits raw data from an A/D sample, *n* is each A/D channel number which varies from 0 to 2, and *Offset* is the zero crossing voltage

To initialize the power quality monitoring system hardware, board configuration file stored on SD-CARD is needed. The board configuration file is a text file named "board.cfg" and the

The advantage of using the configuration file from the SD-CARD is convenient to apply by setting its contents when more power quality monitoring boards are used at

To define the Ethernet packet stream structure sending over the Ethernet network, it is consisted of fault data and electrical measurement information, which is in the place of the TCP packet and will be packed to the UDP packets, then it is transmitted to PC or laptop.

char type; /\* Type of information defined as 0 \*/ char line1 [42]; /\* Data buffer for the 3-phase voltages \*/

char line4 [42]; /\* Data buffer for current date and time \*/

The LPC2368 microcontroller board uses UDP protocol packet to transmit data to a remote computer. UDP protocol is one of protocols in the TCP/IP protocol suite that is used in the place of TCP when a reliable delivery is not required. There is less processing of UDP packets than the one of TCP. UDP protocol is widely used for streaming audio and video, voice over IP (VoIP) and video conferences, because there is no time to retransmit erroneous or dropped packets. The UDP packet which is in Ethernet frame is

 char type; /\* Type of information defined as 1 \*/ char buffer[200]; /\* Data buffer for fault data \*/ char status; /\* Status of the data buffer \*/

char line2 [42]; /\* Data buffer for the status of the AC Lines \*/ char line3 [42]; /\*Data buffer for the frequency values for the

*<sup>X</sup> <sup>V</sup>* = −*Offset* <sup>−</sup> (1)

<sup>12</sup> (2 1) *n n n*

To run the flowchart in order, it must initialize the network chip on LPC2368 microcontroller board, SD-CARD, real-time clock, the RTOS tasks that are modified from A Power Quality Monitoring System for Real-Time Detection of Power Fluctuations (Yingkayun & Premrudeepreechacharn, 2008) and ADE7758 board to get ready for operating its functions. Next, LPC2368 microcontroller sends a control signal to ADUC7024 microcontroller board in order to start doing the sampling process. It reads the voltage and frequency data from ADE7758 board. In case, there is no any fault signals, which are read by LPC2368 microcontroller, the display information of the following values: the data of voltage; frequency; date; time; status and so on, will be sent via network to PC or laptop when it is connected. The LPC2368 microcontroller will take turn to operate its function repeatedly from the start once more. But if ADE7758 board detects the fault signals, it will send the fault signal to LPC2368 microcontroller which stops the sampling process, then, reads the fault data from the external memory board and writes the fault data in SD-CARD for storing. The fault data will be sent to PC or laptop via network when it is connected. LPC2368 microcontroller will start doing the process once more after receiving the next fault signals.

#### **3.3 Data frame**

The data frame, sending to the external memory board, is defined with the head byte, the samples of the 3-phase voltages with 12-bits A/D resolution and the tail byte. The data frame content is shown in Fig. 10.

#### Fig. 10. Data frame

The example of data frame structure which is written in C structure format is shown below:

```
struct adc_info { /* Frame structure */ 
       unsigned char head; /* defined as 0x00 when sampling ON and 0x55 
        when sampling OFF */ 
 unsigned int samples[3];/* 12 bits Analog to Digital Signal from 
        AC lines */ 
 unsigned char tail; /* defined as 0xAA */ 
     };
```
To calculate the floating point voltages from a raw A/D sample, it can be expressed by

$$V\_n = \frac{X\_u}{(2^{12} - 1)} - \text{Offset}\_n \tag{1}$$

Where *V* is the floating point voltage, *X* is the 12-bits raw data from an A/D sample, *n* is each A/D channel number which varies from 0 to 2, and *Offset* is the zero crossing voltage offset.

### **3.4 Configuration data**

240 Electrical Generation and Distribution Systems and Power Quality Disturbances

To run the flowchart in order, it must initialize the network chip on LPC2368 microcontroller board, SD-CARD, real-time clock, the RTOS tasks that are modified from A Power Quality Monitoring System for Real-Time Detection of Power Fluctuations (Yingkayun & Premrudeepreechacharn, 2008) and ADE7758 board to get ready for operating its functions. Next, LPC2368 microcontroller sends a control signal to ADUC7024 microcontroller board in order to start doing the sampling process. It reads the voltage and frequency data from ADE7758 board. In case, there is no any fault signals, which are read by LPC2368 microcontroller, the display information of the following values: the data of voltage; frequency; date; time; status and so on, will be sent via network to PC or laptop when it is connected. The LPC2368 microcontroller will take turn to operate its function repeatedly from the start once more. But if ADE7758 board detects the fault signals, it will send the fault signal to LPC2368 microcontroller which stops the sampling process, then, reads the fault data from the external memory board and writes the fault data in SD-CARD for storing. The fault data will be sent to PC or laptop via network when it is connected. LPC2368 microcontroller will start doing the process once more after receiving the next fault

The data frame, sending to the external memory board, is defined with the head byte, the samples of the 3-phase voltages with 12-bits A/D resolution and the tail byte. The data

The example of data frame structure which is written in C structure format is shown

unsigned int samples[3];/\* 12 bits Analog to Digital Signal from

To calculate the floating point voltages from a raw A/D sample, it can be expressed

unsigned char head; /\* defined as 0x00 when sampling ON and 0x55

struct adc\_info { /\* Frame structure \*/

 AC lines \*/ unsigned char tail; /\* defined as 0xAA \*/

when sampling OFF \*/

signals.

**3.3 Data frame** 

Fig. 10. Data frame

};

below:

by

frame content is shown in Fig. 10.

To initialize the power quality monitoring system hardware, board configuration file stored on SD-CARD is needed. The board configuration file is a text file named "board.cfg" and the contents of the configuration file are shown below:

```
ip = 192.168.0.200 //Hardware IP 
id = 1 //Hardware Number 
port= 2000 // UDP Port 
offset0 = 1.246 //Channel 0 Offset 
offset1 = 1.242 //Channel 1 Offset 
offset2 = 1.251 //Channel 2 Offset 
phase = 3 //Select 1 or 3 Phase System
```
The advantage of using the configuration file from the SD-CARD is convenient to apply by setting its contents when more power quality monitoring boards are used at each node.

### **3.5 Ethernet packet stream structure**

To define the Ethernet packet stream structure sending over the Ethernet network, it is consisted of fault data and electrical measurement information, which is in the place of the TCP packet and will be packed to the UDP packets, then it is transmitted to PC or laptop. The structure of Ethernet packet stream is shown below:

```
struct display_info { /* Display structure type*/ 
        char type; /* Type of information defined as 0 */ 
 char line1 [42]; /* Data buffer for the 3-phase voltages */ 
        char line2 [42]; /* Data buffer for the status of the AC Lines */ 
        char line3 [42]; /*Data buffer for the frequency values for the 
         3-phase system. */ 
 char line4 [42]; /* Data buffer for current date and time */ 
     }; 
     struct fault_info { 
 char type; /* Type of information defined as 1 */ 
        char buffer[200]; /* Data buffer for fault data */ 
        char status; /* Status of the data buffer */ 
     };
```
The LPC2368 microcontroller board uses UDP protocol packet to transmit data to a remote computer. UDP protocol is one of protocols in the TCP/IP protocol suite that is used in the place of TCP when a reliable delivery is not required. There is less processing of UDP packets than the one of TCP. UDP protocol is widely used for streaming audio and video, voice over IP (VoIP) and video conferences, because there is no time to retransmit erroneous or dropped packets. The UDP packet which is in Ethernet frame is shown in Fig. 11.

A Power Quality Monitoring System

Fig. 12. Display window in ordinary state

Fig. 13. Display window in uncommon state

And the researchers have developed the application software for displaying the fault signal which is sent from the monitoring hardware to PC or laptop in order to illustrate the fault data. This developed application software can either save in picture file or print out to take

respectively.

Via the Ethernet Network Based on the Embedded System 243

the computer. Actually, this application gets the display information from the hardware mentioned above and then displays on the PC or laptop screen via the Ethernet network. The application can set date and time and can also receive the fault data from the referred hardware via the Ethernet network. The ordinary state and the uncommon one of the power lines are displayed by application software on PC or laptop shown in Fig. 12 and Fig. 13


Fig. 11. UDP within Ethernet frame

The structures of the Ethernet stream can be illustrated in C programming language are as followings:

```
struct Frame_Header 
{ 
  char Dest_MAC[6]; 
  char Src_MAC[6];
  char Ethernet_Type[2];
}; 
struct IP_Header 
{ 
  char IP_Version; 
  char TypeOfService;
  unsigned int DataSize;
  unsigned int Identification;
  unsigned int Flag;
  char TimeToLive;
  char Protocol; //UDP=0x11
  unsigned int CheckSum;
  char SrcAddr[4];
  char DestAddr[4];
}; 
struct UDP_Header 
{ 
  unsigned int SrcPort;
  unsigned int DestPort;
  unsigned int DataGramLength;
  unsigned int CheckSum;
}; 
struct Ethernet_Stream0 
{ 
  struct Frame_Header frame; 
  struct IP_Header ip; 
  struct UDP_Header udp;
  struct display_info dp; 
  char ZeroByte;
}; 
struct Ethernet_Stream1 
{ 
  struct Frame_Header frame; 
  struct IP_Header ip; 
  struct UDP_Header udp;
  struct fault_info fault; 
  char ZeroByte;
};
```
#### **4. Application software**

Application software is developed and written in Delphi 7 in order to control and to receive informational data from power quality monitoring system hardware and to save the data to

The structures of the Ethernet stream can be illustrated in C programming language are as

Application software is developed and written in Delphi 7 in order to control and to receive informational data from power quality monitoring system hardware and to save the data to

Fig. 11. UDP within Ethernet frame

struct Frame\_Header

 char Dest\_MAC[6]; char Src\_MAC[6]; char Ethernet\_Type[2];

 char IP\_Version; char TypeOfService; unsigned int DataSize; unsigned int Identification;

 unsigned int Flag; char TimeToLive;

struct UDP\_Header

char ZeroByte;

char ZeroByte;

**4. Application software**

 unsigned int SrcPort; unsigned int DestPort; unsigned int DataGramLength; unsigned int CheckSum;

struct Ethernet\_Stream0

struct Ethernet\_Stream1

 struct Frame\_Header frame; struct IP\_Header ip; struct UDP\_Header udp; struct display\_info dp;

 struct Frame\_Header frame; struct IP\_Header ip; struct UDP\_Header udp; struct fault\_info fault;

 char Protocol; //UDP=0x11 unsigned int CheckSum; char SrcAddr[4]; char DestAddr[4];

struct IP\_Header

followings:

{

};

};

{

};

{

};

{

};

{

the computer. Actually, this application gets the display information from the hardware mentioned above and then displays on the PC or laptop screen via the Ethernet network. The application can set date and time and can also receive the fault data from the referred hardware via the Ethernet network. The ordinary state and the uncommon one of the power lines are displayed by application software on PC or laptop shown in Fig. 12 and Fig. 13 respectively.


Fig. 12. Display window in ordinary state


Fig. 13. Display window in uncommon state

And the researchers have developed the application software for displaying the fault signal which is sent from the monitoring hardware to PC or laptop in order to illustrate the fault data. This developed application software can either save in picture file or print out to take

A Power Quality Monitoring System

Via the Ethernet Network Based on the Embedded System 245

(a)

(b)

(c)

(d) Fig. 15. (a) Voltage sags on phase A,B and C, (b) Voltage sag on phase A, (c) voltage sag on

For more advantage, the communication of the power quality monitoring hardware and PC or laptop is not only limited with the only one hardware but also connected to other hard-

phase B and (d) voltage sag on phase C

the data under the considerable analysis of the cause in the faults at later time. The developed application software is shown in Fig. 14.

Fig. 14. Application software for waveform display
