<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ca">
	<id>https://energia.canfugarolas.org/index.php?action=history&amp;feed=atom&amp;title=TrifasicEthernetEthercard</id>
	<title>TrifasicEthernetEthercard - Historial de revisió</title>
	<link rel="self" type="application/atom+xml" href="https://energia.canfugarolas.org/index.php?action=history&amp;feed=atom&amp;title=TrifasicEthernetEthercard"/>
	<link rel="alternate" type="text/html" href="https://energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;action=history"/>
	<updated>2026-10-24T03:55:39Z</updated>
	<subtitle>Historial de revisió per a aquesta pàgina del wiki</subtitle>
	<generator>MediaWiki 1.40.0</generator>
	<entry>
		<id>https://energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;diff=63&amp;oldid=prev</id>
		<title>Enric a 20:13, 27 oct 2015</title>
		<link rel="alternate" type="text/html" href="https://energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;diff=63&amp;oldid=prev"/>
		<updated>2015-10-27T20:13:51Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;//energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;amp;diff=63&amp;amp;oldid=61&quot;&gt;Mostra els canvis&lt;/a&gt;</summary>
		<author><name>Enric</name></author>
	</entry>
	<entry>
		<id>https://energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;diff=61&amp;oldid=prev</id>
		<title>Gerard a 08:43, 27 oct 2015</title>
		<link rel="alternate" type="text/html" href="https://energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;diff=61&amp;oldid=prev"/>
		<updated>2015-10-27T08:43:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;a href=&quot;//energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;amp;diff=61&amp;amp;oldid=40&quot;&gt;Mostra els canvis&lt;/a&gt;</summary>
		<author><name>Gerard</name></author>
	</entry>
	<entry>
		<id>https://energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;diff=40&amp;oldid=prev</id>
		<title>Enric: Es crea la pàgina amb «  #include &lt;UIPEthernet.h&gt; // Used for Ethernet   #define FILTERSETTLETIME 5000                                                   //  Time (ms) to allow the filters to...».</title>
		<link rel="alternate" type="text/html" href="https://energia.canfugarolas.org/index.php?title=TrifasicEthernetEthercard&amp;diff=40&amp;oldid=prev"/>
		<updated>2015-10-20T17:34:04Z</updated>

		<summary type="html">&lt;p&gt;Es crea la pàgina amb «  #include &amp;lt;UIPEthernet.h&amp;gt; // Used for Ethernet   #define FILTERSETTLETIME 5000                                                   //  Time (ms) to allow the filters to...».&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Pàgina nova&lt;/b&gt;&lt;/p&gt;&lt;div&gt;  #include &amp;lt;UIPEthernet.h&amp;gt; // Used for Ethernet&lt;br /&gt;
  #define FILTERSETTLETIME 5000                                                   //  Time (ms) to allow the filters to settle before sending data&lt;br /&gt;
  #define SERIALPRINT								// include print statement for commissioning - comment this line to exclude&lt;br /&gt;
  #define PHASE2 8								//  Number of samples delay for L2&lt;br /&gt;
  #define PHASE3 17								//  Number  of samples delay for L3, also size of array&lt;br /&gt;
  #define RF69_COMPAT 0                                                           // set to 1 to use RFM69CW &lt;br /&gt;
  const int UNO = 0;								// Set to 0 if you are not using the UNO bootloader &lt;br /&gt;
  // **** ETHERNET SETTING ****&lt;br /&gt;
  byte mac[] = { 0x54, 0x34, 0x41, 0x30, 0x30, 0x90 };                                      &lt;br /&gt;
  IPAddress ip(192, 168,1,190);                        &lt;br /&gt;
  EthernetServer server(80);&lt;br /&gt;
  int inPinV = 6;&lt;br /&gt;
  int inPinI1 = 1;&lt;br /&gt;
  int inPinI2 = 4;&lt;br /&gt;
  int inPinI3 = 7;&lt;br /&gt;
  //Calibration coefficients - see http://openenergymonitor.org/emon/modules/emontx/firmware/calibration%20&lt;br /&gt;
  //These need to be set in order to obtain accurate results&lt;br /&gt;
  double Vcal = 157.8;							// Calibration - constant for voltage input - for ideal power voltage adapter &lt;br /&gt;
  double Ical1 = 60.6;							// Calibration constant for current transformer 1&lt;br /&gt;
  double Ical2 = 60.6;							// Calibration constant for current transformer 2&lt;br /&gt;
  double Ical3 = 60.6;							// Calibration constant for current transformer 3&lt;br /&gt;
  double Phasecal1 = 1.0;						// Calibration constant for phase shift L1&lt;br /&gt;
  double Phasecal2 = 1.6;						// Calibration constant for phase shift L2&lt;br /&gt;
  double Phasecal3 = 1.0;						// Calibration constant for phase shift L3&lt;br /&gt;
  //--------------------------------------------------------------------------------------&lt;br /&gt;
  // Variable declaration for filters, phase shift, voltages, currents &amp;amp; powers&lt;br /&gt;
  //--------------------------------------------------------------------------------------&lt;br /&gt;
  int lastSampleV,sampleV;						//sample_ holds the raw analog read value, lastSample_ holds the last sample&lt;br /&gt;
  int lastSampleI1,sampleI1;&lt;br /&gt;
  int lastSampleI2,sampleI2;&lt;br /&gt;
  int lastSampleI3,sampleI3;&lt;br /&gt;
  double lastFilteredV,filteredV;					//Filtered_ is the raw analog value minus the DC offset&lt;br /&gt;
  double lastFilteredI1, filteredI1;&lt;br /&gt;
  double lastFilteredI2, filteredI2;&lt;br /&gt;
  double lastFilteredI3, filteredI3;&lt;br /&gt;
  double phaseShiftedV1;							//Holds the calibrated delayed &amp;amp; phase shifted voltage.&lt;br /&gt;
  double phaseShiftedV2;&lt;br /&gt;
  double phaseShiftedV3;&lt;br /&gt;
  double sqV,sumV,sqI1,sumI1,sqI2,sumI2,sqI3,sumI3;&lt;br /&gt;
  double instP1,sumP1,instP2,sumP2,instP3,sumP3;	//sq = squared, sum = Sum, inst = instantaneous&lt;br /&gt;
  int startV;										//Instantaneous voltage at start of sample window.&lt;br /&gt;
  double realPower1,								// The final data&lt;br /&gt;
         apparentPower1,&lt;br /&gt;
         powerFactor1,&lt;br /&gt;
         Irms1,&lt;br /&gt;
  	   realPower2,&lt;br /&gt;
         apparentPower2,&lt;br /&gt;
         powerFactor2,&lt;br /&gt;
         Irms2,&lt;br /&gt;
  	   realPower3,&lt;br /&gt;
         apparentPower3,&lt;br /&gt;
         powerFactor3,&lt;br /&gt;
         Irms3,&lt;br /&gt;
         Vrms;	   &lt;br /&gt;
  typedef struct { int power1, power2, power3, Vrms; } PayloadTX;		// neat way of packaging data for RF comms&lt;br /&gt;
  																	// (Include all the variables that are desired,&lt;br /&gt;
  																	// ensure the same struct is used to receive)&lt;br /&gt;
  PayloadTX emontx;													// create an instance&lt;br /&gt;
  const int LEDpin = 9;												// On-board emonTx LED &lt;br /&gt;
  boolean settled = false;&lt;br /&gt;
  void setup() {&lt;br /&gt;
    Serial.begin(9600);&lt;br /&gt;
    // start the Ethernet connection and the server:&lt;br /&gt;
    Ethernet.begin(mac, ip);&lt;br /&gt;
    server.begin();&lt;br /&gt;
    Serial.print(&amp;quot;IP Address: &amp;quot;);&lt;br /&gt;
    Serial.println(Ethernet.localIP());&lt;br /&gt;
    pinMode(LEDpin, OUTPUT);									// Setup indicator LED&lt;br /&gt;
    digitalWrite(LEDpin, HIGH);&lt;br /&gt;
  }&lt;br /&gt;
  void loop() {&lt;br /&gt;
    // listen for incoming clients&lt;br /&gt;
    EthernetClient client = server.available();&lt;br /&gt;
    if (client)&lt;br /&gt;
    {  &lt;br /&gt;
      Serial.println(&amp;quot;-&amp;gt; New Connection&amp;quot;);&lt;br /&gt;
      calcVI3Ph(11,2000);&lt;br /&gt;
      // Removing these print statements is recommended for normal use (if not required). Not used Gerard&lt;br /&gt;
  /*#ifdef SERIALPRINT&lt;br /&gt;
    Serial.print(&amp;quot;Voltage: &amp;quot;); Serial.println(Vrms);&lt;br /&gt;
    Serial.print(&amp;quot; Current 1: &amp;quot;); Serial.print(Irms1);&lt;br /&gt;
    Serial.print(&amp;quot; Power 1: &amp;quot;); Serial.print(realPower1);&lt;br /&gt;
    Serial.print(&amp;quot; VA 1: &amp;quot;); Serial.print(apparentPower1);&lt;br /&gt;
    Serial.print(&amp;quot; PF 1: &amp;quot;); Serial.println(powerFactor1);&lt;br /&gt;
    Serial.print(&amp;quot; Current 2: &amp;quot;); Serial.print(Irms2);&lt;br /&gt;
    Serial.print(&amp;quot; Power 2: &amp;quot;); Serial.print(realPower2);&lt;br /&gt;
    Serial.print(&amp;quot; VA 2: &amp;quot;); Serial.print(apparentPower2);&lt;br /&gt;
    Serial.print(&amp;quot; PF 2: &amp;quot;); Serial.println(powerFactor2);&lt;br /&gt;
    Serial.print(&amp;quot; Current 3: &amp;quot;); Serial.print(Irms3);&lt;br /&gt;
    Serial.print(&amp;quot; Power 3: &amp;quot;); Serial.print(realPower3);&lt;br /&gt;
    Serial.print(&amp;quot; VA 3: &amp;quot;); Serial.print(apparentPower3);&lt;br /&gt;
    Serial.print(&amp;quot; PF 3: &amp;quot;); Serial.println(powerFactor3);&lt;br /&gt;
    Serial.println(); delay(100);&lt;br /&gt;
  #endif */&lt;br /&gt;
      // an http request ends with a blank line&lt;br /&gt;
      boolean currentLineIsBlank = true;&lt;br /&gt;
      while (client.connected())&lt;br /&gt;
      {&lt;br /&gt;
        if (client.available())&lt;br /&gt;
        {&lt;br /&gt;
          char c = client.read();&lt;br /&gt;
          // if you&amp;#039;ve gotten to the end of the line (received a newline&lt;br /&gt;
          // character) and the line is blank, the http request has ended,&lt;br /&gt;
          // so you can send a reply&lt;br /&gt;
          if (c == &amp;#039;\n&amp;#039; &amp;amp;&amp;amp; currentLineIsBlank)&lt;br /&gt;
          {&lt;br /&gt;
                  client.print(Vrms);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(&amp;quot;L1 &amp;quot;);&lt;br /&gt;
                  client.print(Irms1);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(realPower1);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(apparentPower1);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(powerFactor1);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(&amp;quot;L2 &amp;quot;);&lt;br /&gt;
                  client.print(Irms2);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(realPower2);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(apparentPower2);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(powerFactor2);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(&amp;quot;L3 &amp;quot;);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(Irms3);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(realPower3);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(apparentPower3);&lt;br /&gt;
                  client.print(&amp;quot; &amp;quot;);&lt;br /&gt;
                  client.print(powerFactor3);&lt;br /&gt;
            break;&lt;br /&gt;
          }&lt;br /&gt;
          if (c == &amp;#039;\n&amp;#039;) {&lt;br /&gt;
            // you&amp;#039;re starting a new line&lt;br /&gt;
            currentLineIsBlank = true;&lt;br /&gt;
          }&lt;br /&gt;
          else if (c != &amp;#039;\r&amp;#039;)&lt;br /&gt;
          {&lt;br /&gt;
            // you&amp;#039;ve gotten a character on the current line&lt;br /&gt;
            currentLineIsBlank = false;&lt;br /&gt;
          }&lt;br /&gt;
        }&lt;br /&gt;
      }&lt;br /&gt;
      // give the web browser time to receive the data&lt;br /&gt;
      delay(10);&lt;br /&gt;
      // close the connection:&lt;br /&gt;
      client.stop();&lt;br /&gt;
      Serial.println(&amp;quot;   Disconnected\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  void calcVI3Ph(int cycles, int timeout)&lt;br /&gt;
  {&lt;br /&gt;
  	int SupplyVoltage = readVcc();&lt;br /&gt;
  	int crossCount = 0;										// Used to measure number of times threshold is crossed.&lt;br /&gt;
  	int numberOfSamples = 0;								// This is now incremented  &lt;br /&gt;
  	int numberOfPowerSamples = 0;							// Needed because 1 cycle of voltages needs to be stored before use&lt;br /&gt;
  	boolean lastVCross, checkVCross;						// Used to measure number of times threshold is crossed.&lt;br /&gt;
  	double storedV[PHASE3];									// Array to store &amp;gt;120 degrees of voltage samples&lt;br /&gt;
  	//-------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
  	// 1) Waits for the waveform to be close to &amp;#039;zero&amp;#039; (500 adc) part in sin curve.&lt;br /&gt;
  	//-------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
  	boolean st=false;							        // an indicator to exit the while loop&lt;br /&gt;
  	unsigned long start = millis();							// millis()-start makes sure it doesnt get stuck in the loop if there is an error.&lt;br /&gt;
  	while(st==false)								// Wait for first zero crossing...&lt;br /&gt;
  	{&lt;br /&gt;
  		startV = analogRead(inPinV);						// using the voltage waveform&lt;br /&gt;
  		if ((startV &amp;lt; 550) &amp;amp;&amp;amp; (startV &amp;gt; 440)) st=true;		                // check it&amp;#039;s within range&lt;br /&gt;
  		if ((millis()-start)&amp;gt;timeout) st = true;&lt;br /&gt;
  	}&lt;br /&gt;
  	//-------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
  	// 2) Main measurment loop&lt;br /&gt;
  	//------------------------------------------------------------------------------------------------------------------------- &lt;br /&gt;
  	start = millis(); &lt;br /&gt;
  	while ((crossCount &amp;lt; cycles * 2) &amp;amp;&amp;amp; ((millis()-start)&amp;lt;timeout)) &lt;br /&gt;
  	{&lt;br /&gt;
  		lastSampleV=sampleV;								// Used for digital high pass filter - offset removal&lt;br /&gt;
  		lastSampleI1=sampleI1;&lt;br /&gt;
  		lastSampleI2=sampleI2;&lt;br /&gt;
  		lastSampleI3=sampleI3;&lt;br /&gt;
  		lastFilteredV = filteredV;&lt;br /&gt;
  		lastFilteredI1 = filteredI1;  &lt;br /&gt;
  		lastFilteredI2 = filteredI2; &lt;br /&gt;
  		lastFilteredI3 = filteredI3;&lt;br /&gt;
  		//-----------------------------------------------------------------------------&lt;br /&gt;
  		// A) Read in raw voltage and current samples&lt;br /&gt;
  		//-----------------------------------------------------------------------------&lt;br /&gt;
  		sampleV = analogRead(inPinV);						// Read in raw voltage signal&lt;br /&gt;
  		sampleI1 = analogRead(inPinI1);						// Read in raw current signal&lt;br /&gt;
  		sampleI2 = analogRead(inPinI2);						// Read in raw current signal&lt;br /&gt;
  		sampleI3 = analogRead(inPinI3);						// Read in raw current signal&lt;br /&gt;
  		//-----------------------------------------------------------------------------&lt;br /&gt;
  		// B) Apply digital high pass filters to remove 2.5V DC offset (to centre wave on 0).&lt;br /&gt;
  		//-----------------------------------------------------------------------------&lt;br /&gt;
  		filteredV = 0.996*(lastFilteredV+sampleV-lastSampleV);&lt;br /&gt;
  		filteredI1 = 0.996*(lastFilteredI1+sampleI1-lastSampleI1);&lt;br /&gt;
  		filteredI2 = 0.996*(lastFilteredI2+sampleI2-lastSampleI2);&lt;br /&gt;
  		filteredI3 = 0.996*(lastFilteredI3+sampleI3-lastSampleI3);&lt;br /&gt;
  		storedV[numberOfSamples%PHASE3] = filteredV;		// store this voltage sample in circular buffer&lt;br /&gt;
  		if (crossCount &amp;gt; 2)									// one complete cycle has been stored, so can use delayed &lt;br /&gt;
  		{													//    voltage samples to calculate instantaneous powers&lt;br /&gt;
  			//-----------------------------------------------------------------------------&lt;br /&gt;
  			// C) Root-mean-square method voltage&lt;br /&gt;
  			//-----------------------------------------------------------------------------  &lt;br /&gt;
  			sqV= filteredV * filteredV;					        //1) square voltage values&lt;br /&gt;
  			sumV += sqV;								        //2) sum&lt;br /&gt;
  			//-----------------------------------------------------------------------------&lt;br /&gt;
  			// D) Root-mean-square method current&lt;br /&gt;
  			//-----------------------------------------------------------------------------   &lt;br /&gt;
  			sqI1 = filteredI1 * filteredI1;				        //1) square current values&lt;br /&gt;
  			sumI1 += sqI1;								        //2) sum &lt;br /&gt;
  			sqI2 = filteredI2 * filteredI2;&lt;br /&gt;
  			sumI2 += sqI2;&lt;br /&gt;
  			sqI3 = filteredI3 * filteredI3;&lt;br /&gt;
  			sumI3 += sqI3;&lt;br /&gt;
  			//-----------------------------------------------------------------------------&lt;br /&gt;
  			// E) Phase calibration - for Phase 1: shifts V1 to correct transformer errors&lt;br /&gt;
  			//	for phases 2 &amp;amp; 3 delays V1 by 120 degrees &amp;amp; 240 degrees respectively &lt;br /&gt;
  			//	and shifts for fine adjustment and to correct transformer errors.&lt;br /&gt;
  			//-----------------------------------------------------------------------------&lt;br /&gt;
  			phaseShiftedV1 = lastFilteredV + Phasecal1 * (filteredV - lastFilteredV);&lt;br /&gt;
  			phaseShiftedV2 = storedV[(numberOfSamples-PHASE2-1)%PHASE3] &lt;br /&gt;
  				+ Phasecal2 * (storedV[(numberOfSamples-PHASE2)%PHASE3] &lt;br /&gt;
  							 - storedV[(numberOfSamples-PHASE2-1)%PHASE3]);&lt;br /&gt;
  			phaseShiftedV3 = storedV[(numberOfSamples+1)%PHASE3] &lt;br /&gt;
  				+ Phasecal3 * (storedV[(numberOfSamples+2)%PHASE3]&lt;br /&gt;
  							 - storedV[(numberOfSamples+1)%PHASE3]);&lt;br /&gt;
  			//-----------------------------------------------------------------------------&lt;br /&gt;
  			// F) Instantaneous power calc&lt;br /&gt;
  			//-----------------------------------------------------------------------------   &lt;br /&gt;
  			instP1 = phaseShiftedV1 * filteredI1;			//Instantaneous Power&lt;br /&gt;
  			sumP1 +=instP1;									//Sum  &lt;br /&gt;
  			instP2 = phaseShiftedV2 * filteredI2;&lt;br /&gt;
  			sumP2 +=instP2;&lt;br /&gt;
  			instP3 = phaseShiftedV3 * filteredI3;&lt;br /&gt;
  			sumP3 +=instP3;&lt;br /&gt;
  			numberOfPowerSamples++;							//Count number of times looped for Power averages.&lt;br /&gt;
  		}&lt;br /&gt;
  		//-----------------------------------------------------------------------------&lt;br /&gt;
  		// G)  Find the number of times the voltage has crossed the initial voltage&lt;br /&gt;
  		//    	- every 2 crosses we will have sampled 1 wavelength &lt;br /&gt;
  		//   	 - so this method allows us to sample an integer number of half wavelengths which increases accuracy&lt;br /&gt;
  		//-----------------------------------------------------------------------------       &lt;br /&gt;
  		lastVCross = checkVCross;                     &lt;br /&gt;
  		if (sampleV &amp;gt; startV) &lt;br /&gt;
  			checkVCross = true; &lt;br /&gt;
  		else &lt;br /&gt;
  			checkVCross = false;&lt;br /&gt;
  		if (numberOfSamples==1)&lt;br /&gt;
  			lastVCross = checkVCross;                  &lt;br /&gt;
  		if (lastVCross != checkVCross)&lt;br /&gt;
  			crossCount++;&lt;br /&gt;
  		numberOfSamples++;									//Count number of times looped.&lt;br /&gt;
  	}&lt;br /&gt;
  	//-------------------------------------------------------------------------------------------------------------------------&lt;br /&gt;
  	// 3) Post loop calculations&lt;br /&gt;
  	//------------------------------------------------------------------------------------------------------------------------- &lt;br /&gt;
  	//Calculation of the root of the mean of the voltage and current squared (rms)&lt;br /&gt;
  	//Calibration coefficients applied. &lt;br /&gt;
  	double V_Ratio = Vcal *((SupplyVoltage/1000.0) / 1023.0);&lt;br /&gt;
  	Vrms = V_Ratio * sqrt(sumV / numberOfPowerSamples); &lt;br /&gt;
  	double I_Ratio1 = Ical1 *((SupplyVoltage/1000.0) / 1023.0);&lt;br /&gt;
  	Irms1 = I_Ratio1 * sqrt(sumI1 / numberOfPowerSamples); &lt;br /&gt;
  	double I_Ratio2 = Ical2 *((SupplyVoltage/1000.0) / 1023.0);&lt;br /&gt;
  	Irms2 = I_Ratio2 * sqrt(sumI2 / numberOfPowerSamples); &lt;br /&gt;
  	double I_Ratio3 = Ical3 *((SupplyVoltage/1000.0) / 1023.0);&lt;br /&gt;
  	Irms3 = I_Ratio3 * sqrt(sumI3 / numberOfPowerSamples); &lt;br /&gt;
  	//Calculation power values&lt;br /&gt;
  	realPower1 = V_Ratio * I_Ratio1 * sumP1 / numberOfPowerSamples;&lt;br /&gt;
  	apparentPower1 = Vrms * Irms1;&lt;br /&gt;
  	powerFactor1 = realPower1 / apparentPower1;&lt;br /&gt;
  	realPower2 = V_Ratio * I_Ratio2 * sumP2 / numberOfPowerSamples;&lt;br /&gt;
  	apparentPower2 = Vrms * Irms2;&lt;br /&gt;
  	powerFactor2 = realPower2 / apparentPower2;&lt;br /&gt;
  	realPower3 = V_Ratio * I_Ratio3 * sumP3 / numberOfPowerSamples;&lt;br /&gt;
  	apparentPower3 = Vrms * Irms3;&lt;br /&gt;
  	powerFactor3 = realPower3 / apparentPower3;&lt;br /&gt;
  	//Reset accumulators&lt;br /&gt;
  	sumV = 0;&lt;br /&gt;
  	sumI1 = 0;&lt;br /&gt;
  	sumI2 = 0;&lt;br /&gt;
  	sumI3 = 0;&lt;br /&gt;
  	sumP1 = 0;&lt;br /&gt;
  	sumP2 = 0;&lt;br /&gt;
  	sumP3 = 0;&lt;br /&gt;
  	//--------------------------------------------------------------------------------------       &lt;br /&gt;
  // Include these statements for development/debugging only. Not used Gerard&lt;br /&gt;
  /*#ifdef DEBUGGING&lt;br /&gt;
  	Serial.print(&amp;quot;Total Samples: &amp;quot;); Serial.print(numberOfSamples);&lt;br /&gt;
  	Serial.print(&amp;quot; Power Samples: &amp;quot;); Serial.print(numberOfPowerSamples);&lt;br /&gt;
  	Serial.print(&amp;quot; Time: &amp;quot;); Serial.print(millis() - start);&lt;br /&gt;
  	Serial.print(&amp;quot; Crossings: &amp;quot;); Serial.println(crossCount);&lt;br /&gt;
  	for (int j=0; j&amp;lt;PHASE3; j++)&lt;br /&gt;
  	{&lt;br /&gt;
  		Serial.print(storedV[j]); Serial.print(&amp;quot; &amp;quot;);&lt;br /&gt;
  		Serial.println();&lt;br /&gt;
  	}&lt;br /&gt;
  #endif*/&lt;br /&gt;
  }&lt;br /&gt;
  //*********************************************************************************************************************&lt;br /&gt;
  long readVcc() &lt;br /&gt;
  {&lt;br /&gt;
    long result;&lt;br /&gt;
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);&lt;br /&gt;
    delay(2);&lt;br /&gt;
    ADCSRA |= _BV(ADSC);&lt;br /&gt;
    while (bit_is_set(ADCSRA,ADSC));&lt;br /&gt;
    result = ADCL;&lt;br /&gt;
    result |= ADCH&amp;lt;&amp;lt;8;&lt;br /&gt;
    result = 1126400L / result;&lt;br /&gt;
    return result;&lt;br /&gt;
  }&lt;/div&gt;</summary>
		<author><name>Enric</name></author>
	</entry>
</feed>