Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Amperemeter RTC Voltmeter
Energymeter.cpp
00001 /* 00002 Project S5 info 00003 Author : lemy2301 00004 */ 00005 00006 //#include "rtos.h" 00007 #include "RTC.h" 00008 00009 #include "Energymeter.h" 00010 #include "Voltmeter.h" 00011 #include "Amperemeter.h" 00012 00013 Amperemeter* amperemeterIn; 00014 Amperemeter* amperemeterOut; 00015 Voltmeter* voltmeter; 00016 00017 float accumulatedEnergy; 00018 float powerIn; 00019 float powerOut; 00020 00021 void collectData() 00022 { 00023 float ampIn = amperemeterIn->getCurrent(); 00024 float ampOut = amperemeterOut->getCurrent(); 00025 float voltage = voltmeter->getVoltage(); 00026 00027 float puissanceDiff = (ampIn-ampOut)*voltage; 00028 00029 accumulatedEnergy += puissanceDiff; 00030 powerIn = voltage*ampIn; 00031 powerOut = voltage*ampOut; 00032 00033 if(accumulatedEnergy < 0) 00034 { 00035 accumulatedEnergy = 0; 00036 } 00037 } 00038 00039 Energymeter::Energymeter(PinName ampIn, PinName ampOut, PinName volt) 00040 { 00041 00042 accumulatedEnergy = 0.0; 00043 powerIn = 0.0; 00044 powerOut = 0.0; 00045 00046 amperemeterIn = new Amperemeter(ampIn); 00047 amperemeterOut = new Amperemeter(ampOut); 00048 00049 //Offset capture at 0A 00050 amperemeterIn->setOffset(2.2972); 00051 amperemeterOut->setOffset(2.3125); 00052 00053 voltmeter = new Voltmeter(volt); 00054 00055 RTC::attach(&collectData, RTC::Second); 00056 } 00057 00058 float Energymeter::getEnergy() 00059 { 00060 return accumulatedEnergy; 00061 } 00062 00063 float Energymeter::getPowerIn() 00064 { 00065 return powerIn; 00066 } 00067 00068 float Energymeter::getPowerOut() 00069 { 00070 return powerOut; 00071 } 00072
Generated on Fri Jul 15 2022 20:37:21 by
1.7.2