Download PHzMon_Doc2

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Spectral density wikipedia , lookup

Pulse-width modulation wikipedia , lookup

Audio power wikipedia , lookup

Mathematics of radio engineering wikipedia , lookup

Power inverter wikipedia , lookup

Variable-frequency drive wikipedia , lookup

Power over Ethernet wikipedia , lookup

Islanding wikipedia , lookup

Alternating current wikipedia , lookup

Chirp spectrum wikipedia , lookup

Switched-mode power supply wikipedia , lookup

Mains electricity wikipedia , lookup

Stage monitor system wikipedia , lookup

Superheterodyne receiver wikipedia , lookup

Immunity-aware programming wikipedia , lookup

Heterodyne wikipedia , lookup

Utility frequency wikipedia , lookup

Transcript
Power Frequency Monitor Documentation
Entry # MT2227
Introduction
The Power Frequency Monitor (PFM) is a MicroChip dsPIC30F3012 micro controller based device used for high
resolution measurement of AC power frequency. The Power Frequency Monitor communicates easily with a
computer using a RS232 interface.
The Power Frequency Monitor is used to measure the frequency of the consumer power. The frequency range is
between 30 to 80 Hz. In the USA, the power frequency standard is 60 Hz. In many other regions in the world, the
power frequency standard is 50 Hz. Measuring this frequency accurately can provide an indicator of the relative
stability of the local region's power grid compared to that of other non-synchronous regions.
PC software is used to download the data from the Power Frequency Monitor at a desired interval. The data can
optionally be uploaded to a database and web server over the Internet to be displayed on a strip chart in a web
browser with the data from other Power Frequency Monitors as illustrated by Figure 3.
The MicroChip dsPIC30F3012 micro controller was selected for its integrated input capture peripheral, UART
(RS232), SPI (Serial Peripheral Interface), and integrated EEPROM features. The prototypes tested demonstrate
that this micro controller has great reliability and performance. The dsPIC30F3012 has also proven to be durable
enough to survive the abuse of my learning curve while I developed the prototypes!
System Description
Figure 1, below, is a block diagram of the Power Frequency Monitoring system. The system input is from any
standard electrical outlet. Different AC-AC transformers may be used depending on the local electricity outlets and
frequencies which vary depending on the country you are plugging into.
Figure 1 – System Block Diagram
The AC input is reduced to 9 VAC(rms) by small 120/9 V transformer. The 9 VAC from the transformer is
connected to a full wave bridge rectifier and a half wave rectifier. The full wave rectified output is regulated to 5
VDC, used to power the system components, and used as a reference voltage for generating the frequency square
wave.
The half wave rectifier output “pulses” are fed into an MCP6292 Operational Amplifier. The pulses are converted to
a square wave by using the Op Amp as a voltage comparator. When the pulse voltage is less than Vref (about 3
VDC), the Op Amp's output is 0 V. When the pulse voltage is greater than Vref, the Op Amp's output is 5 V. The
MCP6292 was selected because it provides a 10 MHz, high resolution, response. The Op Amp's output is
connected to the Input Capture pin on the micro controller. Photo 1, below, shows the conversion of the half-wave
rectifier signal to a square wave by the Op Amp.
1
Photo 1 – Half Wave to Square Wave Conversion
The core component of the Power Frequency Monitor is the MicroChip dsPIC30F3012 micro controller. The micro
controller uses an external 12.000 MHz clock crystal. The dsPIC30F3012 has an integrated Input Capture
peripheral that is configured to generate an interrupt on the leading edge of the square wave signal pulses on the
pin connected to the Op Amp's output.
The Input Capture peripheral counts the clock cycles between each leading edge and stores this data in a buffer.
The clock cycles are divided by a prescaler of 8 so as not to overflow the 16 bit counter in the frequency range
being measured. The following equations show that a prescaler of 8 provides a cycle count resolution allowing us
to measure the desired frequencies without overflow.
( 1sec / 60Hz ) * ( 12,000,000 cycles/sec ) / 8 = 25,000 cycles/Hz
( 1sec / 50Hz ) * ( 12,000,000 cycles/sec ) / 8 = 30,000 cycles/Hz
The interrupt service routine (ISR) copies the buffered data to a memory variable so it can be accessed
asynchronously by the program loop. The ISR then clears the buffer. The program loop determines what to do
with the frequency data based on programmed rules and commands received from the PC. The data is typically
transmitted to a PC via RS232 at the PC's request.
Optionally, the data can be stored in an external MicroChip 25xx1024 EEPROM for stand-alone data logging.
Since data stream is continuous, stand-alone logging needs a rule set to determine what data is worth storing.
Typically the data stored in the EEPROM is unusual samples like frequency spikes and dips. The EEPROM can be
also be used to accumulate periodic runtime statistics.
A PC communicates with the dsPIC30F3012 using RS232. The PC software polls the micro controller periodically
to get the frequency data. The data can easily be transmitted at speeds of 5 or more samples per second using
ASCII and a moderate baud rate of 57,600 bps. Each data packet contains a sequence number and the data. The
sequence number is used to determine if any packets were missed. Only a 3 wire connection is used and no
handshake is performed.
The PC software is relatively simple. The software polls the Power Frequency Monitor at timer intervals and
performs the frequency and deviation calculations on the data. It displays the data and can also upload the data to
a database over the Internet using a web service. Figure 2, below, shows a screen shot of the PC software polling
the micro controller every 200 ms and transmitting data to the database web server once per second.
2
Figure 2 – PC Software Screen Shot
Application
The Power Frequency Monitor is used to monitor the frequency of electric power grids. By distributing the monitors
over a wide regional or global area, the relative stability of the power grids can be observed and compared with
each other. The Power Frequency Monitor developed here is a very inexpensive and simple way to observe
frequency variations at various grid locations, for example, on either side of High Voltage DC transmission lines
between grids to observe how well the connection endpoints are synchronized. Improving synchronization between
grid nodes can decrease operating costs.
To make a relative comparison between grids of the two different frequencies, 50 Hz and 60 Hz, the following
percent deviation calculation is used:
100 * [ ( Measured Hz ) – ( Rated Hz ) ] / ( Rated Hz ) = Deviation %
For example, the chart shown in Figure 3, below, shows the Houston Texas frequency (Rated = 60 Hz) compared
to the North Island, New Zealand frequency (Rated = 50 Hz). The vertical deviation scaling is +/- 1.0%. The
equivalent 60 Hz frequency scale is on the left and the equivalent 50 Hz frequency scale is on the right side of the
chart.
3
Figure 3 – Power Grid Frequency and % Deviation Chart
The PC software controls the resolution of the data displayed in the chart. If the Power Frequency Monitor, or
“Meter”, is on a high speed Internet or LAN connection with the server; the frequency can be sampled at a higher
rate than meters with limited connectivity. The chart in Figure 3 shows Meter # 1 sampled at a rate of 1 sample per
second, Meters #20 and #90 sampled at a rate of 1 sample each 10 seconds.
The PC software is also responsible for performing the frequency and deviation calculations. When the data is
transmitted from the PC through the web service to the web server’s database, the database assigns a time stamp
to the data record. The web server is synchronized to a NIST time server. The actual original sample time will be
different depending on latency in communication over the Internet; but samples are all time stamped to the
standard NIST time at the time they are received; keeping the data lines on the chart relatively synchronized.
4
Construction
The Power Frequency Monitor is a relatively simple device to construct and program. Photo 2, below, shows the
component layout on a breadboard.
Photo 2 – Power Frequency Monitor Layout
Major components of the Power Frequency Monitor from left to right are:
RJ45 interface for a MicroChip ICD2 device programmer/debugger
Reset button
MicroChip dsPIC30F3012 micro controller
Activity Indicator LEDs
12.000 MHz HCMOS crystal oscillator
MicroChip 25LC1024 EEPROM
DS275 RS232 Transceiver
MicroChip MCP6292 Operational Amplifier
Single Diode Half-Wave Rectifier
LM7805 Voltage Regulator
470 µF Filter Capacitor
4 Diodes Full-Wave Bridge Rectifier
Figure 4, below, shows the electrical schematic for the Power Frequency Monitor.
All of the components are standard and readily available. The clock crystal is used to provide a stable reference
frequency of 12.000 MHz. The Power Frequency Monitor runs with the micro controller configured with a PLL
multiplier of 4 for a speed of 48 MHz. The dsPIC30F3012 has a built in 7.37 MHz oscillator. The external oscillator
is used in this project because its frequency is known to have a better resolution.
5
Micro Controller Software
The dsPIC30F3012 is easy to program using the MicroChip In Circuit Debugger (ICD2), free MPLAB development
software, and the MicroChip C30 compiler. The C30 source code for this project is included in the accompanying
PHzMon_30F3012.zip file.
The micro controller program consists of a single process loop with a high priority interrupt service routine (ISR) for
the Input Capture function and a low priority ISR for the UART. The process loop polls for commands received
from the PC via the UART and executes the commands.
For ease of troubleshooting and simplicity of operation; the PC commands to the micro controller are the single
ASCII characters “0” to “9”. For troubleshooting, the commands can be transmitted by a simple terminal program
(e.g. Hyper Terminal in Windows) and the response viewed in the terminal window. Packets are used to facilitate
parsing of the data by the PC. Each packet has fields delimited by “;”, starts with a “!<sequence #>”, and ends with
a “|”. The commands perform the functions listed in the table below. Except for the frequency data, most numbers
are transmitted in hexadecimal format.
Command
0 – Reset to Default
1 – Get Data
2 – PING
3 – Get Version
4 – Restore
5 – Save
Sample Response
!1;Saving Defaults ..Write WREN|
!2;..WEL Set -> WRITE|
!3;..System State Saved|
!4;..Wait for WIP|
EEPROM SR = 0
!5;..Write WRDI|
!6;DONE!|
!7;C;24998|
Description
Soft Reset of all values to default
Various diagnostic messages are
displayed, including the EEPROM
Status Register.
!8;PING;dsPIC3012;2|
!9;VER;2007.10.09;2|
!1;Reading EEPROM:|
MCU ID# 2
Packet ID# b
Samples = 1
Process Loop = 13e6a9
Data Count = 11c
!c;DONE!|
!d;Saving..Write WREN|
!e;..WEL Set -> WRITE|
!f;..System State Saved|
!10;..Wait for WIP|
EEPROM SR = 0
!11;..Write WRDI|
!12;DONE!|
PING, Processor, Project Serial #
Firmware Version, Project Serial #
Read the EEPROM and use the
values to update the fields. This is
performed on device RESET to
restore to the last saved state.
6 – [available]
7 – Diagnostic Mode 3
!7;C;24998|
8 – Diagnostic Mode 2
9 – Diagnostic Mode 1
!8;PING;dsPIC3012;2|
[bits]
Get Data; 25000 = 60 Hz
Save the state variables to EEPROM
Not used in this version
Transmit data every process loop
cycle
Transmit PING every process loop
Transmit 0xAAAA every process loop
for scope measurement.
The PC software was developed using Microsoft Visual Studio 2005 with C# and .NET Framework 2.0. The PC
software automatically transmits the commands in the table above, processes the response data, and transmits the
results to the database via a web service. The PC Software source code and compiled binaries for this project are
included in the accompanying PHzMon_Gateway.zip file.
The web service and database software was developed using Microsoft Visual Studio 2005 with ASP.NET 2.0 and
Microsoft SQL Server Express Edition. The live web chart display was developed using ASP.NET and the AJAX
6
library. The chart page runs on Microsoft Internet Information Services (IIS) web server and can be viewed in
current versions of contemporary web browsers that support AJAX (older browser versions and text versions do not
support AJAX). The web service, web page source code, and database file are included in the accompanying
PHzMon_Web.zip file. Although the web development techniques used in this project are relatively standard,
documentation and instructions for configuring a secure database web application server are beyond the scope of
this project.
7
Figure 4 – Power Frequency Monitor Schematic
8
Additional Photos
Throughout this document you may see variations in the photos. Multiple units were constructed, tested, and
recycled for this project resulting in photos of units with slight variations in components, resistor values, layout,
wiring, and fixes to mistakes made during development.
Photo 3 – Layout with Ground and Power Wires
Photo 4 – Layout with Completed Wiring
Note: ICD2 and EEPROM data, RS232, and power supply input, and additional ground wires are not connected in
the above photo.
9
Photo 5 – Economical Packaging
Mom’s favorite Tupperware worked best. Don’t tell my mom!
Photo 6 – Completed Unit with Accessories
From left to right, top to bottom: RJ45 connector, In-Circuit Debugger (ICD2), 120/9VAC Transformer, Power
Frequency Monitor, RS232 cable to PC (not shown).
Note: After the device is programmed, the ICD2 and connectors are no longer needed. The device is very power
efficient and can be operated with the cover on without over heating.
10