Example for Lib Pulses. Measurement of power and energy with a energy meter which has a S0 interface

Dependencies:   Pulses mbed

Measurement of low frequencys based on timing between pulses. Example for using a energy meter with S0 interface.

Files at this revision

API Documentation at this revision

Comitter:
jocis
Date:
Thu Nov 08 12:01:08 2012 +0000
Parent:
1:0f8dd2deb61b
Child:
3:97db3807db8a
Commit message:
minor bug fixes

Changed in this revision

Pulses.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Pulses.lib	Thu Nov 08 07:25:51 2012 +0000
+++ b/Pulses.lib	Thu Nov 08 12:01:08 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/jocis/code/Pulses/#6eb686d7d16a
+http://mbed.org/users/jocis/code/Pulses/#fc21262db17a
--- a/main.cpp	Thu Nov 08 07:25:51 2012 +0000
+++ b/main.cpp	Thu Nov 08 12:01:08 2012 +0000
@@ -3,14 +3,14 @@
 
 Serial pc(USBTX, USBRX); // tx, rx
 
-// Example for energy meter with SO interface
+// Example for energy meter with SO interface.
 // SO output of energy meter is connected (over opto-coppler) to pin 8
 
 #define SO_PULSES 2000 // SO interface of energy meter with 2000 pulses per kWh
 Pulses pulses(p8, Pulses::FALL);
 
 int main() {
-    pulses.setFactor(3600.0f/SO_PULSES);   // Scale to kW; kWh
+    pulses.setFactor ( 3600.0f/SO_PULSES );   // Scale to kW; kWh
 
     float averagePower = 0;    // Average energy since last call of get()
     float minPower = 0;        // Min. energy since last call of get()
@@ -21,13 +21,13 @@
         
         pulses.get ( &averagePower, &minPower, &maxPower, &sumEnergy );
         
-        pc.printf ( "Power: %d (%.3f...%.3f) [kW]   Energy: %.3f [kWh]   SO-pulses=%d\r\n", 
+        pc.printf ( "Power: %.3f (%.3f...%.3f) [kW]   Energy: %.3f [kWh]   SO-pulses=%d\r\n", 
             averagePower, 
             minPower, 
             maxPower, 
             sumEnergy,
             pulses.getCounter() );
         
-        wait(6);   // Example 6 seconds; typical 1 minute (60 sec)
+        wait(6);   // Example 6 seconds; typical 1 minute (60 sec) sample time
     }
 }