6
A Low-Cost Embedded Platform for Synchronised Wide Area Frequency Measurement A. M. Damle Nayak Power Systems Pvt. Ltd. Email: [email protected] A. M. Kulkarni Indian Institute of Technology Bombay Email: [email protected] Abstract—Implementation of a frequency measurement device based on ARM-embedded computer viz. Raspberry Pi is presented. This device is used as a part of a wide area frequency measurement system implemented at Indian Institute of Technology Bombay. Free and open source software is used including Linux based operating system patched with a real- time development framework. This serves as a low-cost high performance alternative to the existing frequency measurement device which uses two computers: a general purpose computer and a micro-controller board. This system may be used for carrying out other wide area measurements as well. Index Terms—Wide Area Frequency Measurement, Xenomai, Raspberry Pi, Network Time Protocol (NTP). I. I NTRODUCTION WAMS for system/grid monitoring provides real-time information to the operator. Monitoring grid frequency is an important component in WAMS, since electro-mechanical oscillations or swings can be observed directly in the grid frequency. Time-stamped frequency measurements taken over a wide area tell how the power system is transitioning after experiencing a disturbance. The Frequency Measurement Device (FMD) [1] makes use of two computers: MSP430 micro-controller [2] for frequency measurement and a general purpose computer running a RTAI patched GNU/Linux operating system time-stamping the measurement. This device, as a whole, although accurate, has several hardware and software components reducing reliability. The system is difficult to maintain, bulky, and costly. A need was felt to develop a portable, compact, rugged, and a reliable platform for frequency measurement without compromising on performance and accuracy. Therefore, a new FMD is implemented using a single ARM- based embedded computer Raspberry Pi—complemented by a square-wave generator circuit. The operating system used on Raspberry Pi is Raspbian with its kernel replaced with Linux patched with a real-time framework called Xenomai. Raspberry Pi harbours all the necessary hardware required for measurement of frequency; time-stamping; and communication with the external server. The server- side tasks of post-processing the frequency and location information remain unchanged making the replacement of the previous FMD [1] easier. The use of free software, the NTP, and Raspberry Pi makes the device inexpensive, portable, compact, and elegant. The deployed system utilises a square-wave generator circuit similar to the previous FMD, while eliminating completely the MSP430, the serial communication interface, and the general purpose computer running an RTAI/Linux real-time operating system. The time synchronisation is done using Network Time Protocol [3]. The time synchronisation accuracy using NTP is found to be adequate [1] for studying oscillations like generator swings and track frequency variations in the grid. II. DESCRIPTION OF THE RASPBERRY PI BASED WIDE AREA FREQUENCY MEASUREMENT DEVICE The new wide area frequency measurement device consists of the following hardware components: a square- wave generator circuit; and a NTP synchronised client-side computer viz. Raspberry Pi. Hardware components in this FMD are described next. A. Square-Wave Generator Circuit The square-wave generator circuit consists of a step-down transformer, an RC filter, a zero crossing detector (ZCD) and converter circuit. The 230 V AC supply is stepped down to 12 V passed through an RC filter to the ZCD circuit, which comprises of an OPAMP and a diode. The negative half- cycle of the square-wave is clipped and an output at 3.3 V is generated, which is fed directly to the general purpose input/output (GPIO) pin on Raspberry Pi. A program is written to detect the rising edges on the GPIO pin. Figure 1 shows the schematic. 230V AC Supply 230V Step Down Transformer R C RC Filter Zero-Crossing Detection and Converter Circuit 3.3V Square Wave AC Supply Raspberry Pi 12V AC Supply Fig. 1. Square-Wave Generator Circuit B. Raspberry Pi Raspberry Pi [4] is a low cost, credit-card sized embedded computer from a registered educational charity based in the UK—the Raspberry Pi Foundation. This 978-1-4799-5141-3/14/$31.00 c 2014 IEEE

A Low-Cost Embedded Platform for Synchronised Wide · PDF fileA Low-Cost Embedded Platform for Synchronised Wide Area Frequency Measurement ... called Xenomai; 3)C programming

Embed Size (px)

Citation preview

Page 1: A Low-Cost Embedded Platform for Synchronised Wide · PDF fileA Low-Cost Embedded Platform for Synchronised Wide Area Frequency Measurement ... called Xenomai; 3)C programming

A Low-Cost Embedded Platform for SynchronisedWide Area Frequency Measurement

A. M. DamleNayak Power Systems Pvt. Ltd.Email: [email protected]

A. M. KulkarniIndian Institute of Technology Bombay

Email: [email protected]

Abstract—Implementation of a frequency measurementdevice based on ARM-embedded computer viz. Raspberry Piis presented. This device is used as a part of a wide areafrequency measurement system implemented at Indian Instituteof Technology Bombay. Free and open source software is usedincluding Linux based operating system patched with a real-time development framework. This serves as a low-cost highperformance alternative to the existing frequency measurementdevice which uses two computers: a general purpose computerand a micro-controller board. This system may be used forcarrying out other wide area measurements as well.

Index Terms—Wide Area Frequency Measurement, Xenomai,Raspberry Pi, Network Time Protocol (NTP).

I. INTRODUCTION

WAMS for system/grid monitoring provides real-timeinformation to the operator. Monitoring grid frequency isan important component in WAMS, since electro-mechanicaloscillations or swings can be observed directly in the gridfrequency. Time-stamped frequency measurements taken overa wide area tell how the power system is transitioningafter experiencing a disturbance. The Frequency MeasurementDevice (FMD) [1] makes use of two computers: MSP430micro-controller [2] for frequency measurement and a generalpurpose computer running a RTAI patched GNU/Linuxoperating system time-stamping the measurement. This device,as a whole, although accurate, has several hardware andsoftware components reducing reliability. The system isdifficult to maintain, bulky, and costly. A need was feltto develop a portable, compact, rugged, and a reliableplatform for frequency measurement without compromisingon performance and accuracy.

Therefore, a new FMD is implemented using a single ARM-based embedded computer Raspberry Pi—complemented bya square-wave generator circuit. The operating system usedon Raspberry Pi is Raspbian with its kernel replacedwith Linux patched with a real-time framework calledXenomai. Raspberry Pi harbours all the necessary hardwarerequired for measurement of frequency; time-stamping;and communication with the external server. The server-side tasks of post-processing the frequency and locationinformation remain unchanged making the replacement ofthe previous FMD [1] easier. The use of free software,the NTP, and Raspberry Pi makes the device inexpensive,portable, compact, and elegant. The deployed system utilises

a square-wave generator circuit similar to the previousFMD, while eliminating completely the MSP430, the serialcommunication interface, and the general purpose computerrunning an RTAI/Linux real-time operating system. The timesynchronisation is done using Network Time Protocol [3].The time synchronisation accuracy using NTP is found to beadequate [1] for studying oscillations like generator swingsand track frequency variations in the grid.

II. DESCRIPTION OF THE RASPBERRY PI BASED WIDEAREA FREQUENCY MEASUREMENT DEVICE

The new wide area frequency measurement deviceconsists of the following hardware components: a square-wave generator circuit; and a NTP synchronised client-sidecomputer viz. Raspberry Pi. Hardware components in thisFMD are described next.

A. Square-Wave Generator Circuit

The square-wave generator circuit consists of a step-downtransformer, an RC filter, a zero crossing detector (ZCD) andconverter circuit. The 230 V AC supply is stepped down to12 V passed through an RC filter to the ZCD circuit, whichcomprises of an OPAMP and a diode. The negative half-cycle of the square-wave is clipped and an output at 3.3 Vis generated, which is fed directly to the general purposeinput/output (GPIO) pin on Raspberry Pi. A program is writtento detect the rising edges on the GPIO pin. Figure 1 showsthe schematic.

230V AC Supply

230V Step Down

Transformer

RC

RC Filter Zero-Crossing

Detection and Converter Circuit

3.3V Square Wave

AC Supply Raspberry Pi

12V AC Supply

Fig. 1. Square-Wave Generator Circuit

B. Raspberry Pi

Raspberry Pi [4] is a low cost, credit-card sizedembedded computer from a registered educational charitybased in the UK—the Raspberry Pi Foundation. This978-1-4799-5141-3/14/$31.00 c© 2014 IEEE

Page 2: A Low-Cost Embedded Platform for Synchronised Wide · PDF fileA Low-Cost Embedded Platform for Synchronised Wide Area Frequency Measurement ... called Xenomai; 3)C programming

compact platform provides various other functionalities andinput/output features similar to a general purpose computer.HDMI port for connection to a monitor or TV, 2 USB portsfor connecting standard keyboard and mouse, an Ethernet portfor communication, etc. are provided. Figure 2 shows a pictureof Raspberry Pi.

GPIO Pins

POWER HDMI

USB PORTS

ETHERNET

Fig. 2. Raspberry Pi

Raspberry Pi contains the following hardware components:

• System on Chip (SoC): The Raspberry Pi SoC is aBroadcom BCM2835. This contains an ARM1176JZFS(ARM11) operating at 700 MHz by default. Floatingpoint support is available. The manual [5] gives the detailsof the various peripherals on the chip;

• General Purpose Input/Output: There are 54 GPIO linessplit into two banks. The manual [5] gives various detailsabout GPIO lines. In the current work, only one GPIOpin is used for the rising edge detection;

• Schematics for the Raspberry Pi Models: The schematicof the models of Raspberry Pi, along with the PCB layoutdetails are available for download [4] to the interesteduser or hardware developer;

• Power: The device is powered by a 5 V micro-USBsupply. The maximum current that can be sinked-in is1 A. A good quality charger with a 5 V, 1 A rating isrecommended;

• USB interfaces on Raspberry Pi: Standard USB deviceslike keyboard and mouse can be easily connected toRaspberry Pi.

III. FREQUENCY MEASUREMENT USING RASPBERRY PI

The hardware of special interest on Raspberry Pi isthe System on Chip, the Broadcom BCM2835, and thegeneral purpose input/output. These have been taken intoaccount when designing the framework suitable for frequencymeasurement.

A. Frequency Measurement

The target is to measure the power frequency as accuratelyas possible. Figure 1 shows the schematic of the supplementaryhardware employing a zero-crossing detector and convertercircuit, which generates a power frequency equivalent square-wave. The positive half of square-wave is fed as an inputto one of the GPIO pins on Raspberry Pi. A C-program iswritten to detect the rising edge at the GPIO pin. The timeat every rising edge is noted and the time difference betweentwo consecutive rising edges when inverted gives the value ofthe frequency. Figure 3 shows the schematic. Two softwareroutines are involved in frequency measurement:

1) a hard real-time task to note the system time at everyrising edge;

2) a non-real-time task to calculate frequency.

3.3 V

0 V

3.3 V

0 V

t1 t2

T = (t2-t1)

Frequency = 1/T

-ve cycleis clipped

Fig. 3. Detection and Recording of Time Interval Between the Rising Edges

B. Issues in Frequency Measurement

There are a couple of issues to be addressed at priorityduring frequency measurement, namely false triggering due tonoise and latency.

1) False triggering: An RC circuit at the input stage is usedas shown in Figure 1 to avoid zero-crossing detection errorsdue to noise.

2) Latency: As explained previously, the rising edges ofthe square wave are detected to calculate frequency. The timeelapsed between the detection of the rising edge and noting thesystem time is critical and must be acceptable. In the currentcontext, we call this as latency. To guarantee minimum latency,the task of rising edge detection must be efficiently executedin hard real-time. Each rising edge is treated as an interruptfor noting system time. Although, an interrupt vector modulehas NOT been implemented in BCM2835 [5], a round-aboutbut a very effective way of detecting the rising edges on aGPIO pin is used, in which case each rising edge becomessynonymous to an interrupt. The system time immediatelyafter detection of the rising edge is noted as precisely aspossible. Context switches are avoided considering the hardreal-time programming caveats. This is ensured by a proper

Page 3: A Low-Cost Embedded Platform for Synchronised Wide · PDF fileA Low-Cost Embedded Platform for Synchronised Wide Area Frequency Measurement ... called Xenomai; 3)C programming

choice of software and data exchange mechanism influencingthe accuracy of frequency measurement.

IV. SOFTWARE USED IN RASPBERRY PI BASEDFREQUENCY MEASUREMENT DEVICE

Software used in the new FMD is required to meethard real-time constraints since the latency, describedpreviously, must be minimum within acceptable limits. Amicro-second accuracy is desired when detecting the risingedges. Unacceptable latency in frequency measurement willcause false interpretation of electro-mechanical oscillations.Focusing on guaranteed latency, high performance, efficiency,and low program-size, the chosen software components areenumerated below. It must be noted that all tools used areeither free [6] or open source [7] software. This choiceof software makes the whole system cheaper, reliable,and updated with long term community support. Followingsoftware components are used:

1) a Debian based operating system called Raspbian;2) a framework for hard real-time support called Xenomai;3) C programming language.

Each software component makes the overall system a versatileacquisition system.

A. Raspbian Operating System

Raspbian [8] is an operating system based on DebianWheezy arm-hard-float (armhf) with compilation settingsadjusted to produce optimised hard float code to run onthe Raspberry Pi hardware. This improves performancefor applications that heavily use floating point arithmeticoperations. The operating system contains basic programsand utilities with large number of pre-compiled softwarepackages. This facilitates rapid program development in auser-friendly environment after installation on Raspberry Pi.Raspbian kernel resembles the standard Linux kernel and doesnot guarantee hard real-time capabilities. Such capabilities areobtained with the Raspbian kernel replaced by a Linux kernelpatched with real-time support—Xenomai.

B. Xenomai

Xenomai [9] is a real-time development frameworkcooperating with the Linux kernel, in order to provide apervasive, interface-agnostic, hard real-time support to user-space applications, seamlessly integrated into the GNU/Linuxenvironment. The Real-Time Driver Model (RTDM) integratedinto Xenomai is used as the framework to implement thehighest priority routine, a kernel module, responsible fordetecting the rising edges ensuring minimum latency. Thefollowing are the reasons for selecting Xenomai:

1) known to work with Raspberry Pi;2) provides hard real-time support;3) provides all the necessary Application Programming

Interfaces (API) and constructs for developing kerneldevice drivers.

C. Real-Time Driver Model

The Real-Time Driver Model (RTDM) [10] is an approachto unify the interfaces for developing device drivers andassociated applications under real-time Linux.

APPLICATION

WRAPPER LIBRARY

REAL TIME DRIVER MODEL (RTDM)

HARDWARE

ABSTRACTION LAYER

HARDWARE DRIVER HARDWARE DRIVER

APPLICATION

Fig. 4. RTDM and Related Layers

Figure 4 shows the relation between RTDM to othersubsystem layers. The ‘Application’ is the routine time-stamping and streaming the measured frequency in non-real-time. The ‘Hardware driver’ is a kernel module in hard real-time responsible for detecting the rising edges and notingtime elapsed between the edges. The kernel module writestime difference between edges to a memory location and theapplication program reads from it. Data (time elapsed betweentwo rising edges) exchange between the hardware driver andapplication is done using a character device. It is to be notedthat kernel module is closer to the hardware, GPIO, runningas the highest priority task while the application program is ahigher level routine with lesser priority compared to the kernelmodule.

D. The Hardware-Software Interface

Figure 5 shows the hardware-software interface. Thepositive half of square-wave is fed at the GPIO pin and thetasks or routines executed are described next.

Sine wave

to

square wave

converter

circuit O

G

P

I

Raspberry Pi

ARM

(CPU)

Task 1

Task 2

(Real-Time)

(Non-Real-Time)

Fig. 5. Hardware-Software Interface

1) Hard Real-Time Kernel Module: Task 1: The hard real-time routine, task 1, is the hardware driver program mentionedin Figure 4. This program is a kernel module which accessesthe GPIO pin for edge detection. The system time in formof an unsigned integer is noted using the Xenomai APInanosecs_abs_t at every event. Here, the event is the detection

Page 4: A Low-Cost Embedded Platform for Synchronised Wide · PDF fileA Low-Cost Embedded Platform for Synchronised Wide Area Frequency Measurement ... called Xenomai; 3)C programming

of a rising edge on GPIO pin 17. A temporary variable keepstrack of the edge number and is toggled on every risingedge. At every event, the system time is noted. The old timevalue is subtracted from the new time value to give the timeelapsed between the two rising edges. The time differenceis immediately written to a memory location. The characterdevice created by task 1 is then available for reading to thenon-real-time application program—task 2.

Task 1

Start

A

ifInterrupt

Note the system time tnew or told

Note the rising edge and toggle variables

Calculate the time difference (tnew-told)

Write value to memory

Wait

A

yes

no

Fig. 6. Flowchart of Hard Real-Time Kernel Module

2) Non-Real-Time Application Program: Task 2: The non-real-time or the user-space program is also the applicationprogram mentioned in Figure 4. The task-2 reads and invertsthe value, the time difference, from the memory locationtypecasting the unsigned integer to a float to obtain frequency.The value of frequency is written to a character string whichhas a specific format: year; month; day; hour; minutes;seconds; milli-seconds; and frequency. The string is writtento a Linux socket as data. The socket program creates packetsand uses the UDP protocol to send data/information to thedesired destined location, which is the server at IIT Bombay.

Task 2

Start

A

ifmemoryis non-zero

Read memory

Calculate frequency

Form a character string

Write to socket

Write zeroto memory

Wait

A

yes

no

Fig. 7. Flowchart of Non-Real-Time Application Program

E. Network Time Protocol

NTP with the application to FMD [1] is used as a meansof achieving and maintaining time synchronisation betweenthe various frequency measurement units over the networkspread throughout the country. Apparently, Raspberry Pi doesnot have an on-board real time clock (RTC). Therefore, thesystem time must be set to the correct value at boot time toensure proper time stamping of the measurement. It also meansthat the system time on Raspberry Pi must be correct after areboot or a contingency, for example, when the unit suffers anetwork outage. However, this is not seen as a grave problem.The process of synchronising the on-board time correctly hasbeen automated on the current system by starting a daemon,a routine running in the background, after the boot/starting-upprocess is over. The daemon keeps updating the system timeregularly by using the designated NTP server—ntp.iitb.ac.in.An option is available wherein one can interface an externalreal time clock with Raspberry Pi to locally keep and retrievetime without connecting to a network.

Page 5: A Low-Cost Embedded Platform for Synchronised Wide · PDF fileA Low-Cost Embedded Platform for Synchronised Wide Area Frequency Measurement ... called Xenomai; 3)C programming

F. Server-Side Tasks

The server side tasks [1] are over viewed here forconsistency. The central server is located at IIT Bombay. Thetime-stamped frequency from the client units is received bythis server. The data is stored in a database and analysedfor any kind of disturbances in the grid. Following tasks arecarried out on the server side:

1) decode the data packets to extract frequency and locationinformation;

2) store the data into the database;3) arrange the data according to the time-stamp and

location;4) make the data available to the web server for visual

display of the data on a web browser.The new FMD is fully compatible with no modificationsrequired to the server-side tasks.

V. TESTS CONDUCTED ON RASPBERRY PI

A couple of preliminary tests were performed on RaspberryPi before deployment to ensure continuous, accurate, andreliable operation.

• Loop-Back test: A good measure of latency or timeelapsed between the invocation of the task processingthe interrupt after its detection is the loop-back test. Asquare wave, with a clipped negative half-cycle, is appliedas an input to a GPIO pin. As soon as the rising edgeis detected, another GPIO pin on the same device ismade high (3.3 V) for the duration of the input pulse.This generates a square wave at the latter GPIO pin withthe same period as the input wave. The resulting outputsquare wave is measured and compared to the inputwave on a digital oscilloscope. The phase/time differencebetween the input and output waveforms is a measureof latency. Figure 8 shows a latency of approximately5 µs. This is acceptable for frequency measurementand tracking electro-mechanical transients in the powersystem.

INPUT

OUTPUT

Fig. 8. Result of the Input-Output Loop-Back Test

• Reliability test: The device, Raspberry Pi, is an embeddedcomputer. The task of frequency measurement, time-stamping, communication with the central server takesplace continuously round-the-clock. The device is keptworking unmanned at the prevailing ambient conditionsin the power systems lab at IIT Bombay. The device isfound working continuously and satisfactorily.

VI. COMPARISON WITH THE FMD USING MSP430MICRO-CONTROLLER

After the preliminary tests, the FMD using Raspberry Pi(RPi) was put to operation at IIT Bombay to measure thefrequency local to Mumbai. This measurement was comparedwith the measurements coming from the other FMDs, usingMSP430 micro-controller, at Kanpur and Kharagpur. Figure 9shows the comparison.

49.931

49.932

49.933

49.934

49.935

49.936

49.937

1 1.5 2 2.5 3 3.5 4

Freq

uenc

y (H

z)

Time (s)

MumbaiKanpur

Kharagpur

@@

@@I

���

FMD employing MSP430

AAKFMD employing RPi

Fig. 9. Frequency Snapshot at Various Locations

There may be some difference in instantaneous frequency atdifferent locations due to swings, but the mean frequencyshould be almost the same at every location in quasi-steadystate. The slight difference in mean frequency (maximum0.003 Hz) evident in the Figure 9 is due to differences inprecision of measurement between FMDs. The differencecaused is because of dissimilar hardware and frequencycalculation approach. For example, the new FMD usingRaspberry Pi uses a 700 MHz clock while the old FMD usesMSP430 micro-controller with a 4000 MHz clock. Also, thefrequency calculation in the Raspberry Pi based FMD is doneby inverting the time difference between rising edges, whichis in the form of integer values. This causes third decimalchanges in the calculated frequency.

VII. RESULTS

On 12 March 2014, at 19:21:59 hrs., a generator trip atMundra, Gujarat, was captured with new FMD. Figure 10shows the variation in the grid frequency profile.

Page 6: A Low-Cost Embedded Platform for Synchronised Wide · PDF fileA Low-Cost Embedded Platform for Synchronised Wide Area Frequency Measurement ... called Xenomai; 3)C programming

49.55

49.6

49.65

49.7

49.75

49.8

49.85

49.9

49.95

50

0 5 10 15 20

Freq

uenc

y (H

z)

Time (s)

MumbaiKanpur

KharagpurSurathkal

�����

A generatortrip atMundra, Gujaratat 19:21:59 hrs.

Fig. 10. A Disturbance Captured Using Raspberry Pi Based FMD

VIII. CONCLUSION

A new synchronised FMD using an embedded computer,Raspberry Pi, is implemented. The frequency measurement isdone correctly and accurately benchmarked with the FMDs[1] using MSP430. The advantages of the new FMD are:

1) it is inexpensive;2) it is easy to maintain with lesser hardware and software

components;3) portable, robust, and high performance.The new FMD has proven useful since the frequency

measurement, time-stamping, communication is completelyhandled by a single, compact, embedded computer. In future,it is intended to check the capability of this device andconfiguration to realise more complex systems like a PhasorMeasurement Unit (PMU).

ACKNOWLEDGMENT

The software used during FMD implementation are eitherfree or open source. The C-program routines, task-1 and task-2, heavily rely on Xenomai and Linux. Raspberry Pi runson a Linux kernel, which also is a community supportedsoftware. Using such software alternatives facilitates rapidprogram development leading to significant time saving.Raspberry Pi foundation has managed to come-up with aninexpensive, high performance and a low-cost computer.The authors acknowledge and thank the communities fordeveloping and making available such advanced software andlow-cost hardware. The authors also thank the team, whichincludes Rathin Dholakia, Kunal Salunkhe, and Mukesh Dasfor their support in carrying out experiments for testing thenew frequency measurement device.

REFERENCES

[1] K. Salunkhe and A. M. Kulkarni, “A wide area synchronized frequencymeasurement system using network time protocol,” in National PowerSystems Conference, 2010.

[2] Texas Instruments website. Getting started with MSP430 from texasinstruments. [Online]. Available: http://www.ti.com/

[3] D. L. Mills, “Internet time synchronization: Network time protocol,”IEEE Transactions on Communications, October 1991.

[4] Raspberry Pi website. Getting started with raspberry pi. [Online].Available: http://www.raspberrypi.org

[5] BCM2835 ARM Peripherals, Broadcom Corporation, Broadcom EuropeLtd. 406 Science Park Milton Road Cambridge CB4 0WW, 2012.

[6] The Free Software Foundation Website. What is free software?[Online]. Available: https://gnu.org/philosophy/free-sw.html

[7] The Open Source Website. The open source definition. [Online].Available: http://opensource.org/definition

[8] About raspbian. [Online]. Available: http://www.raspbian.org/[9] Xenomai website. Xenomai start page. [Online]. Available:

http://www.xenomai.org/index.php/Included_documentation_summary[10] J. Kiszka, “The real-time driver model and first applications,” University

of Hannover, Germany, Tech. Rep., 2009.