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.

Committer:
jocis
Date:
Wed Nov 07 18:48:55 2012 +0000
Revision:
0:010c6e517e18
Child:
1:0f8dd2deb61b
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jocis 0:010c6e517e18 1 #include "mbed.h"
jocis 0:010c6e517e18 2 #include "Pulses.h"
jocis 0:010c6e517e18 3
jocis 0:010c6e517e18 4 //DigitalOut myled(LED1);
jocis 0:010c6e517e18 5 Pulses pulses(p8, Pulses::FALL);
jocis 0:010c6e517e18 6 Serial pc(USBTX, USBRX); // tx, rx
jocis 0:010c6e517e18 7
jocis 0:010c6e517e18 8 int main() {
jocis 0:010c6e517e18 9 // choose on of the following unit scales
jocis 0:010c6e517e18 10 pulses.setFactor(1.0f); // Hz
jocis 0:010c6e517e18 11 pulses.setFactor(60.0f); // rpm
jocis 0:010c6e517e18 12 pulses.setFactor(3600.0f/2000.0f); // kWh; energy meter with SO interface - 2000 pulses per kWh
jocis 0:010c6e517e18 13
jocis 0:010c6e517e18 14 while(1) {
jocis 0:010c6e517e18 15 pc.printf ( "Pulses: counter=%d act=%.3f average=%.3f\r\n",
jocis 0:010c6e517e18 16 pulses.getCounter(),
jocis 0:010c6e517e18 17 pulses.getAct(),
jocis 0:010c6e517e18 18 pulses.getAverage() );
jocis 0:010c6e517e18 19
jocis 0:010c6e517e18 20 wait(3.14);
jocis 0:010c6e517e18 21 }
jocis 0:010c6e517e18 22 }