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 14:45:23 2012 +0000
Parent:
2:4805e84fa084
Child:
4:167cda567d4e
Commit message:
rework of documentation, 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 12:01:08 2012 +0000
+++ b/Pulses.lib	Thu Nov 08 14:45:23 2012 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/jocis/code/Pulses/#fc21262db17a
+http://mbed.org/users/jocis/code/Pulses/#36dd0d59fdc8
--- a/main.cpp	Thu Nov 08 12:01:08 2012 +0000
+++ b/main.cpp	Thu Nov 08 14:45:23 2012 +0000
@@ -2,6 +2,7 @@
 #include "Pulses.h"
 
 Serial pc(USBTX, USBRX); // tx, rx
+AnalogOut multimeter(p18);
 
 // Example for energy meter with SO interface.
 // SO output of energy meter is connected (over opto-coppler) to pin 8
@@ -22,12 +23,18 @@
         pulses.get ( &averagePower, &minPower, &maxPower, &sumEnergy );
         
         pc.printf ( "Power: %.3f (%.3f...%.3f) [kW]   Energy: %.3f [kWh]   SO-pulses=%d\r\n", 
-            averagePower, 
-            minPower, 
-            maxPower, 
+            averagePower,
+            minPower,
+            maxPower,
             sumEnergy,
             pulses.getCounter() );
+
+        // wait(6);   // Example 6 seconds; typical 1 minute (60 sec) sample time
         
-        wait(6);   // Example 6 seconds; typical 1 minute (60 sec) sample time
+        // Additional feature: Output of actual power as analog voltage (1V==1kW; max3.3kW). Connect a multimeter to pin 18 and GND
+        for ( int i=0; i<20; i++ ) {
+            multimeter = pulses.getAct() / 3.3f;   // Scale to 1V==1kW
+            wait(0.3);   // Example 6 seconds; typical 1 minute (60 sec) sample time
+        }
     }
 }