/* Emon.cpp - Library for openenergymonitor Created by Trystan Lea, Ap การแปล - /* Emon.cpp - Library for openenergymonitor Created by Trystan Lea, Ap ไทย วิธีการพูด

/* Emon.cpp - Library for openenerg

/*
Emon.cpp - Library for openenergymonitor
Created by Trystan Lea, April 27 2010
GNU GPL
modified to use up to 12 bits ADC resolution (ex. Arduino Due)
by boredman@boredomprojects.net 26.12.2013
Low Pass filter for offset removal replaces HP filter 1/1/2015 - RW
*/

//#include "WProgram.h" un-comment for use on older versions of Arduino IDE
#include "EmonLib.h"

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif


//--------------------------------------------------------------------------------------
// Sets the pins to be used for voltage and current sensors
//--------------------------------------------------------------------------------------
void EnergyMonitor::voltage(unsigned int _inPinV, double _VCAL, double _PHASECAL)
{
inPinV = _inPinV;
VCAL = _VCAL;
PHASECAL = _PHASECAL;
offsetV = ADC_COUNTS>>1;
}

void EnergyMonitor::current(unsigned int _inPinI, double _ICAL)
{
inPinI = _inPinI;
ICAL = _ICAL;
offsetI = ADC_COUNTS>>1;
}

//--------------------------------------------------------------------------------------
// Sets the pins to be used for voltage and current sensors based on emontx pin map
//--------------------------------------------------------------------------------------
void EnergyMonitor::voltageTX(double _VCAL, double _PHASECAL)
{
inPinV = 2;
VCAL = _VCAL;
PHASECAL = _PHASECAL;
offsetV = ADC_COUNTS>>1;
}

void EnergyMonitor::currentTX(unsigned int _channel, double _ICAL)
{
if (_channel == 1) inPinI = 3;
if (_channel == 2) inPinI = 0;
if (_channel == 3) inPinI = 1;
ICAL = _ICAL;
offsetI = ADC_COUNTS>>1;
}

//--------------------------------------------------------------------------------------
// emon_calc procedure
// Calculates realPower,apparentPower,powerFactor,Vrms,Irms,kWh increment
// From a sample window of the mains AC voltage and current.
// The Sample window length is defined by the number of half wavelengths or crossings we choose to measure.
//--------------------------------------------------------------------------------------
void EnergyMonitor::calcVI(unsigned int crossings, unsigned int timeout)
{
#if defined emonTxV3
int SupplyVoltage=3300;
#else
int SupplyVoltage = readVcc();
#endif

unsigned int crossCount = 0; //Used to measure number of times threshold is crossed.
unsigned int numberOfSamples = 0; //This is now incremented

//-------------------------------------------------------------------------------------------------------------------------
// 1) Waits for the waveform to be close to 'zero' (mid-scale adc) part in sin curve.
//-------------------------------------------------------------------------------------------------------------------------
boolean st=false; //an indicator to exit the while loop

unsigned long start = millis(); //millis()-start makes sure it doesnt get stuck in the loop if there is an error.

while(st==false) //the while loop...
{
startV = analogRead(inPinV); //using the voltage waveform
if ((startV < (ADC_COUNTS*0.55)) && (startV > (ADC_COUNTS*0.45))) st=true; //check its within range
if ((millis()-start)>timeout) st = true;
}

//-------------------------------------------------------------------------------------------------------------------------
// 2) Main measurement loop
//-------------------------------------------------------------------------------------------------------------------------
start = millis();

while ((crossCount < crossings) && ((millis()-start) startV) checkVCross = true;
else checkVCross = false;
if (numberOfSamples==1) lastVCross = checkVCross;

if (lastVCross != checkVCross) crossCount++;
}

//-------------------------------------------------------------------------------------------------------------------------
// 3) Post loop calculations
//-------------------------------------------------------------------------------------------------------------------------
//Calculation of the root of the mean of the voltage and current squared (rms)
//Calibration coefficients applied.

double V_RATIO = VCAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
Vrms = V_RATIO * sqrt(sumV / numberOfSamples);

double I_RATIO = ICAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
Irms = I_RATIO * sqrt(sumI / numberOfSamples);

//Calculation power values
realPower = V_RATIO * I_RATIO * sumP / numberOfSamples;
apparentPower = Vrms * Irms;
powerFactor=realPower / apparentPower;

//Reset accumulators
sumV = 0;
sumI = 0;
sumP = 0;
//--------------------------------------------------------------------------------------
}

//--------------------------------------------------------------------------------------
double EnergyMonitor::calcIrms(unsigned int Number_of_Samples)
{

#if defined emonTxV3
int SupplyVoltage=3300;
#else
int SupplyVoltage = readVcc();
#endif


for (unsigned int n = 0; n < Number_of_Samples; n++)
{
sampleI = analogRead(inPinI);

// Digital low pass filter extracts the 2.5 V or 1.65 V dc offset,
// then subtract this - signal is now centered on 0 counts.
offsetI = (offsetI + (sampleI-offsetI)/1024);
filteredI = sampleI - offsetI;

// Root-mean-square method current
// 1) square current values
sqI = filteredI * filteredI;
// 2) sum
sumI += sqI;
}

double I_RATIO = ICAL *((SupplyVoltage/1000.0) / (ADC_COUNTS));
Irms = I_RATIO * sqrt(sumI / Number_of_Samples);

//Reset accumulators
sumI = 0;
//--------------------------------------------------------------------------------------

return Irms;
}

void EnergyMonitor::serialprint()
{
Serial.print(realPower);
Serial.print(' ');
Serial.print(apparentPower);
Serial.print(' ');
Serial.print(Vrms);
Serial.print(' ');
Serial.print(Irms);
Serial.print(' ');
Serial.print(powerFactor);
Serial.println(' ');
delay(100);
}
0/5000
จาก: -
เป็น: -
ผลลัพธ์ (ไทย) 1: [สำเนา]
คัดลอก!
/* Emon.cpp - ไลบรารีสำหรับ openenergymonitor สร้าง โดย Trystan Lea, 27 2553 เมษายน GNU GPL ปรับเปลี่ยนการใช้ค่าความละเอียด 12 บิต ADC (เช่นครบกำหนดสืบ) โดย boredman@boredomprojects.net 26.12.2013 1/1/2015 - RW ตัวกรองผ่านต่ำตัวกรองสำหรับกำจัดตรงข้ามแทน HP*/#include สหประชาชาติข้อคิดเห็น "WProgram.h" สำหรับใช้บน IDE สืบรุ่นเก่า#include "EmonLib.h"#if defined(ARDUINO) & & สืบ > = 100#include "Arduino.h"#else#include "WProgram.h"#endif//--------------------------------------------------------------------------------------ชุดหมุดที่ใช้สำหรับแรงดันไฟฟ้าและเซ็นเซอร์ปัจจุบัน//--------------------------------------------------------------------------------------ยกเลิก EnergyMonitor::voltage (int รับรอง _inPinV, _VCAL คู่ คู่ _PHASECAL){ inPinV = _inPinV VCAL = _VCAL PHASECAL = _PHASECAL offsetV = ADC_COUNTS >> 1}ยกเลิก EnergyMonitor::current (int รับรอง _inPinI, _ICAL คู่){ inPinI = _inPinI ICAL = _ICAL offsetI = ADC_COUNTS >> 1}//--------------------------------------------------------------------------------------กำหนดหมุดที่ใช้สำหรับแรงดันไฟฟ้าและเซ็นเซอร์ปัจจุบันตามแผนที่ pin emontx//--------------------------------------------------------------------------------------ยกเลิก EnergyMonitor::voltageTX (_VCAL, _PHASECAL คู่คู่){ inPinV = 2 VCAL = _VCAL PHASECAL = _PHASECAL offsetV = ADC_COUNTS >> 1}ยกเลิก EnergyMonitor::currentTX (int รับรอง _channel, _ICAL คู่){ ถ้า (_channel == 1) inPinI = 3 ถ้า (_channel == 2) inPinI = 0 ถ้า (_channel == 3) inPinI = 1 ICAL = _ICAL offsetI = ADC_COUNTS >> 1}//--------------------------------------------------------------------------------------กระบวนการ emon_calcคำนวณ realPower, apparentPower, powerFactor, Vrms, Irms ไม่เพิ่มจากหน้าต่างตัวอย่างแรงดันไฟ AC และปัจจุบันความยาวของหน้าต่างตัวอย่างจะถูกกำหนด โดยจำนวนครึ่งความยาวคลื่นหรือหละหลวมที่เราต้องวัด//--------------------------------------------------------------------------------------ยกเลิก EnergyMonitor::calcVI (หละหลวมรับรอง int, int ไม่หมด){ emonTxV3 #if กำหนด int SupplyVoltage = 3300 #else int SupplyVoltage = readVcc() #endif รับรอง int crossCount = 0 ใช้ในการวัดเลขจะข้ามขีดจำกัดของเวลา รับรอง int numberOfSamples = 0 ซึ่งตอนนี้เพิ่มขึ้น //------------------------------------------------------------------------------------------------------------------------- 1) รอรูปคลื่นที่จะใกล้กับ 'ศูนย์' (ระดับกลาง adc) ส่วนในบาปโค้ง //------------------------------------------------------------------------------------------------------------------------- บูลีนเซนต์ =เท็จ ตัวบ่งชี้เพื่อจบการทำงานในลูป รับรองเริ่มยาว = millis() (millis)-เริ่มต้นให้แน่ใจว่าไม่ได้ติดอยู่ในลูปถ้ามีข้อผิดพลาด //the while(st==false) ในขณะที่วน... { startV = analogRead(inPinV) ใช้รูปคลื่นแรงดันไฟฟ้า ถ้า ((startV < (ADC_COUNTS * เพิ่ม)) & & (startV > (ADC_COUNTS * 0.45))) เซนต์ =จริง ตรวจสอบอยู่ภายในช่วง ถ้า ((millis()-start)>timeout) เซนต์ =จริง } //------------------------------------------------------------------------------------------------------------------------- 2 วนวัดหลัก //------------------------------------------------------------------------------------------------------------------------- เริ่มต้น = millis() ในขณะที่ ((crossCount < crossings) & & ((millis()-start) { numberOfSamples ++ นับจำนวนครั้ง looped lastFilteredV = filteredV ใช้สำหรับค่าตอบแทนล่าช้า/ระยะ //----------------------------------------------------------------------------- A) อ่านแรงดิบและตัวอย่างในปัจจุบัน //----------------------------------------------------------------------------- sampleV = analogRead(inPinV) อ่านสัญญาณแรงดิบ sampleI = analogRead(inPinI) อ่านในปัจจุบันสัญญาณดิบ //----------------------------------------------------------------------------- ขใช้ตัวกรองต่ำผ่านดิจิทัลเพื่อแยก 2.5 V หรือ 1.65 V dc ออฟเซ็ต ลบนี้ - สัญญาณเป็นศูนย์กลางในการตรวจนับที่ 0 ตอนนี้ //----------------------------------------------------------------------------- offsetV = offsetV + ((sampleV-offsetV)/1024); filteredV = sampleV - offsetV offsetI = offsetI + ((sampleI-offsetI)/1024); filteredI = sampleI - offsetI //----------------------------------------------------------------------------- แรงดันไฟฟ้าวิธี C) รากค่าเฉลี่ยสแควร์ //----------------------------------------------------------------------------- sqV = filteredV * filteredV 1 ค่าแรงดันไฟฟ้าตาราง sumV += sqV 2 ผลรวม //----------------------------------------------------------------------------- D) ปัจจุบันวิธีรากค่าเฉลี่ยสแควร์ //----------------------------------------------------------------------------- sqI = filteredI * filteredI 1) ค่าปัจจุบันเหลี่ยม มิดะ+= sqI 2 ผลรวม //----------------------------------------------------------------------------- เทียบระยะ E) //----------------------------------------------------------------------------- phaseShiftedV = lastFilteredV + PHASECAL * (filteredV - lastFilteredV); //----------------------------------------------------------------------------- F) คำนวณกำลังไฟฟ้า //----------------------------------------------------------------------------- instP = phaseShiftedV * filteredI ไฟฟ้ากำลัง sumP += instP ผลรวม //----------------------------------------------------------------------------- G) จำนวนครั้งที่แรงดันไฟฟ้าได้ข้ามแรงดันเริ่มต้นค้นหา -ตัดทุก 2 เราจะมีความความยาวคลื่น 1 -ดังนั้นวิธีการนี้ทำให้เราตัวอย่างหมายเลขของครึ่งความยาวคลื่นซึ่งช่วยเพิ่มความถูกต้อง //----------------------------------------------------------------------------- lastVCross = checkVCross ถ้า (sampleV > startV) checkVCross = true checkVCross อื่น =เท็จ ถ้า (numberOfSamples == 1) lastVCross = checkVCross ถ้า (lastVCross ! = checkVCross) crossCount ++ } //------------------------------------------------------------------------------------------------------------------------- 3) คำนวณลูปลง //------------------------------------------------------------------------------------------------------------------------- คำนวณรากของค่าเฉลี่ยของแรงดันไฟฟ้าและกำลังสองปัจจุบัน (rms) เทียบสัมประสิทธิ์ที่ใช้ คู่ V_RATIO = VCAL *((SupplyVoltage/1000.0) / (ADC_COUNTS)); Vrms = V_RATIO * sqrt(sumV / numberOfSamples) คู่ I_RATIO = ICAL *((SupplyVoltage/1000.0) / (ADC_COUNTS)); Irms = I_RATIO * sqrt(sumI / numberOfSamples) คำนวณค่าไฟฟ้า realPower = V_RATIO * I_RATIO * sumP / numberOfSamples apparentPower = Vrms * Irms powerFactor = realPower / apparentPower Accumulators ใหม่ sumV = 0 มิดะ = 0 sumP = 0//-------------------------------------------------------------------------------------- }//--------------------------------------------------------------------------------------คู่ EnergyMonitor::calcIrms (รับรอง int Number_of_Samples){ emonTxV3 #if กำหนด int SupplyVoltage = 3300 #else int SupplyVoltage = readVcc() #endif สำหรับ (int รับรอง n = 0; n < Number_of_Samples; n ++) { sampleI = analogRead(inPinI) ตัวกรองต่ำผ่านดิจิทัลสารสกัดจาก 2.5 V หรือ 1.65 V dc ออฟเซ็ต ลบนี้ - สัญญาณเป็นศูนย์กลางในการตรวจนับที่ 0 ตอนนี้ offsetI = (offsetI + (sampleI-offsetI) / 1024); filteredI = sampleI - offsetI ปัจจุบันรากค่าเฉลี่ยกำลังสองวิธี 1) ค่าปัจจุบันเหลี่ยม sqI = filteredI * filteredI 2 ผลรวม มิดะ+= sqI } คู่ I_RATIO = ICAL *((SupplyVoltage/1000.0) / (ADC_COUNTS)); Irms = I_RATIO * sqrt(sumI / Number_of_Samples) Accumulators ใหม่ มิดะ = 0//-------------------------------------------------------------------------------------- กลับ Irms}ยกเลิก EnergyMonitor::serialprint(){ Serial.print(realPower) Serial.print(' ') Serial.print(apparentPower) Serial.print(' ') Serial.print(Vrms) Serial.print(' ') Serial.print(Irms) Serial.print(' ') Serial.print(powerFactor) Serial.println(' ') delay(100) }
การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 2:[สำเนา]
คัดลอก!
/ *
Emon.cpp - ห้องสมุดสำหรับ openenergymonitor
สร้างโดย Trystan ทุ่งหญ้า 27 เมษายน 2010
GNU GPL
ปรับเปลี่ยนการใช้งานได้ถึง 12 บิตความละเอียด ADC (ex. เนื่องจาก Arduino)
โดย boredman@boredomprojects.net 2013/12/26
กรองความถี่ต่ำสำหรับการกำจัดชดเชยแทน HP กรอง 2015/01/01 - RW
* / // # include "WProgram.h" ยกเลิกการแสดงความคิดเห็นสำหรับใช้ในรุ่นเก่าของ Arduino IDE #include "EmonLib.h" # ถ้ากำหนด (ARDUINO) && ARDUINO> = 100 # รวมถึง "Arduino.h" # อื่น#include ตั้งหมุดที่จะใช้สำหรับแรงดันไฟฟ้าและเซ็นเซอร์ปัจจุบัน// ------------------------------------- ------------------------------------------------- โมฆะ EnergyMonitor :: แรงดันไฟฟ้า (นิรนาม int _inPinV, _VCAL คู่ _PHASECAL คู่) { inPinV = _inPinV; VCAL = _VCAL; PHASECAL = _PHASECAL; offsetV = ADC_COUNTS >> 1; } เป็นโมฆะ EnergyMonitor :: ปัจจุบัน (นิรนาม int _inPinI, _ICAL คู่) { inPinI = _inPinI; ICAL = _ICAL; offsetI = ตั้งหมุดที่จะใช้สำหรับแรงดันไฟฟ้าและเซ็นเซอร์ในปัจจุบันขึ้นอยู่กับแผนที่ขา emontx // -------------------------------- -------------------------------------------------- ---- โมฆะ EnergyMonitor :: voltageTX (_VCAL คู่ _PHASECAL คู่) { inPinV = 2; VCAL = _VCAL; PHASECAL = _PHASECAL; offsetV = ADC_COUNTS >> 1; } เป็นโมฆะ EnergyMonitor :: currentTX (นิรนาม _channel int, _ICAL คู่) { ถ้า (_channel == 1) inPinI = 3; ถ้า (_channel == 2) inPinI = 0; ถ้า (_channel == 3) inPinI = 1; ICAL = _ICAL; offsetI = ขั้นตอน emon_calc // คำนวณ realPower, apparentPower, powerFactor, Vrms, Irms, กิโลวัตต์ชั่วโมงเพิ่มขึ้น// จากหน้าต่างตัวอย่างของแรงดันไฟ AC และปัจจุบัน. // ระยะเวลาในหน้าต่างตัวอย่างจะถูกกำหนดโดยจำนวนของความยาวคลื่นครึ่งหนึ่งหรือข้ามเราเลือกที่จะ วัด. // ---------------------------------------------- ---------------------------------------- โมฆะ EnergyMonitor :: calcVI (ข้าม int ไม่ได้ลงนาม หมดเวลาที่ไม่ได้ลงชื่อ int) { # ถ้ากำหนด emonTxV3 int SupplyVoltage = 3300; # อื่นint SupplyVoltage = readVcc (); #endif int ไม่ได้ลงนาม crossCount = 0; // ใช้ในการวัดจำนวนครั้งเกณฑ์ข้าม. int ไม่ได้ลงนาม numberOfSamples = 0; // นี่คือตอนนี้ 1) รอสำหรับรูปแบบของคลื่นจะใกล้เคียงกับ 'ศูนย์' (ADC ขนาดกลาง) มีส่วนร่วมในความบาป เซนต์ = false; // ตัวบ่งชี้ที่จะออกจากวงในขณะที่ไม่ได้ลงนามเริ่มต้นนาน MILLIS = (); // MILLIS () - เริ่มต้นที่จะทำให้แน่ใจว่ามันไม่ได้รับการติดอยู่ในวงถ้ามีข้อผิดพลาด. ในขณะที่ (เซนต์ == เท็จ) // ห่วงในขณะที่ ... { StarTV = analogRead (inPinV); // การใช้สัญญาณแรงดันถ้า ((StarTV <(ADC_COUNTS * 0.55)) && (StarTV> (ADC_COUNTS * 0.45))) เซนต์ = true; // ตรวจสอบภายในช่วงถ้า ((MILLIS () - เริ่มต้น)> หมดเวลา) เซนต์ = 2) การวัดหลัก = MILLIS (); ในขณะที่ ((crossCount <ข้าม) && ((MILLIS () - เริ่มต้น)





















































































{
numberOfSamples ++; // ตัวเลขจำนวนครั้งคล้อง.
lastFilteredV = filteredV; // ใช้สำหรับการชดเชยความล่าช้า / เฟส// ---------------------------------------- ------------------------------------- //) อ่านแรงดันไฟฟ้าดิบและตัวอย่างปัจจุบัน// -------------------------------------------------- --------------------------- sampleV = analogRead (inPinV); // อ่านในสัญญาณแรงดันไฟฟ้าดิบsampleI = analogRead (inPinI); // อ่านสัญญาณในปัจจุบันดิบ// ----------------------------------------- ------------------------------------ // B) ใช้กรองความถี่ต่ำผ่านดิจิตอลเพื่อดึง 2.5 V หรือ 1.65 V DC ชดเชย// แล้วลบนี้ -. สัญญาณเป็นศูนย์กลางในขณะนี้กับ 0 นับ// ---------------------------- ------------------------------------------------- offsetV = offsetV + ((sampleV-offsetV) / 1024); filteredV = sampleV - offsetV; offsetI = offsetI + ((sampleI-offsetI) / 1024); filteredI = sampleI - offsetI; // --------- -------------------------------------------------- ------------------ // C) รากเฉลี่ยตารางแรงดันวิธี// ------------------- -------------------------------------------------- -------- SQV = filteredV * filteredV; // 1) ตารางค่าแรงดันไฟฟ้าsumV + = SQV; // 2) ผลรวม// ------------------------------------------- ---------------------------------- // D) รากเฉลี่ยตารางวิธีปัจจุบัน// --- -------------------------------------------------- ------------------------ SQI = filteredI * filteredI; // 1) ตารางค่าปัจจุบันSUMI + = SQI; // 2) ผลรวม// ------------------------------------------- ---------------------------------- // E) เฟส = lastFilteredV + PHASECAL * (filteredV - lastFilteredV); // ------------------------------------- ---------------------------------------- // F) คำนวณพลังงานทันที// - -------------------------------------------------- -------------------------- instP = phaseShiftedV * filteredI; // ทันทีพลังงานบ่อ + = instP; // ซำ// --------------------------------------------- -------------------------------- // G) หาจำนวนครั้งที่แรงดันไฟฟ้าได้ข้ามแรงดันเริ่มต้น// - ทุก 2 ไม้กางเขนเราจะได้ชิม 1 ความยาวคลื่น// - ดังนั้นวิธีการนี้ช่วยให้เราสามารถลิ้มลองจำนวนเต็มของความยาวคลื่นครึ่งซึ่งจะเป็นการเพิ่มความถูกต้อง// ------------------- -------------------------------------------------- -------- lastVCross = checkVCross; ถ้า (sampleV> StarTV) checkVCross = true; อื่น checkVCross = false; ถ้า (numberOfSamples == 1) lastVCross = checkVCross; ถ้า (! lastVCross = checkVCross) 3) วงโพสต์ ของรากของค่าเฉลี่ยของแรงดันและกระแสกำลังสอง (RMS) . // ค่าสัมประสิทธิ์การสอบเทียบใช้คู่ V_RATIO = VCAL * ((SupplyVoltage / 1000.0) / (ADC_COUNTS)); Vrms = V_RATIO * sqrt (sumV / numberOfSamples) คู่ I_RATIO = ICAL * ((SupplyVoltage / 1000.0) / (ADC_COUNTS)); Irms = I_RATIO * sqrt (SUMI / numberOfSamples); // การคำนวณค่าพลังงานrealPower = V_RATIO * * * * * * * * I_RATIO บ่อ / numberOfSamples; apparentPower = Vrms * Irms; powerFactor = realPower / apparentPower; // แอคคิวรีเซ็ตsumV = 0; SUMI = 0; บ่อ = EnergyMonitor :: calcIrms (Number_of_Samples int ไม่ได้ลงนาม) { # ถ้ากำหนด emonTxV3 int SupplyVoltage = 3300; # อื่นint SupplyVoltage = readVcc (); #endif สำหรับ (int ไม่ได้ลงนาม n = 0; n <Number_of_Samples; n ++) { sampleI = analogRead (inPinI ); // กรองผ่านต่ำดิจิตอลสารสกัดจาก 2.5 V หรือ 1.65 V DC ชดเชย// แล้วลบนี้ - สัญญาณเป็นศูนย์กลางในขณะนี้กับ 0 นับ. offsetI = (offsetI + (sampleI-offsetI) / 1024); filteredI = sampleI - offsetI; // รากเฉลี่ยตารางวิธีปัจจุบัน// 1) ตารางค่าปัจจุบันSQI = filteredI * filteredI; // 2) ผลรวมSUMI + = SQI; } คู่ I_RATIO = ICAL * ((SupplyVoltage / 1000.0) / (ADC_COUNTS) ); Irms = I_RATIO * sqrt (SUMI / Number_of_Samples); // รีเซ็ตสะสมSUMI = 0; // --------------------------- -------------------------------------------------- --------- ผลตอบแทน Irms; } เป็นโมฆะ EnergyMonitor :: serialprint () { Serial.print (realPower); Serial.print (''); Serial.print (apparentPower); Serial.print ('') ; Serial.print (Vrms); Serial.print (''); Serial.print (Irms); Serial.print (''); Serial.print (powerFactor); Serial.println (''); ล่าช้า (100) ; }































































































































การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 3:[สำเนา]
คัดลอก!
/ *
emon.cpp - ห้องสมุด openenergymonitor
สร้างโดย trystan Lea , 27 เมษายน 2553

แก้ไขให้ใช้ GNU GPL ถึง 12 บิตความละเอียด ADC ( เช่น Arduino เนื่องจาก )

โดย boredman@boredomprojects.net 26.12.2013 ต่ำผ่านตัวกรองเพื่อชดเชยการแทนที่ HP กรอง 1 / 1 / 2015 - RW
/

/ / #รวม wprogram . H " a ความคิดเห็นสำหรับใช้กับรุ่นเก่าของ Arduino IDE
#รวมถึง " emonlib . H "

#ถ้ากำหนด ( Arduino ) && Arduino > = 100
#รวมถึง " Arduino . H "
#อีก
#รวมถึง " wprogram . H "
#จบถ้า


/ / --------------------------------------------------------------------------------------
/ / ชุดหมุดจะใช้แรงดันและกระแสเซ็นเซอร์
/ /
-------------------------------------------------------------------------------------- เป็นโมฆะ energymonitor แรงดัน ( : : _inpinv / int ,คู่ _vcal คู่ _phasecal )
{
inpinv = = _vcal vcal _inpinv ;
;
phasecal = _phasecal ;
offsetv = adc_counts > > 1 ;
}

เป็นโมฆะ energymonitor : : ปัจจุบัน ( int / _inpini คู่ _ical )
{
inpini = = _ical iCal _inpini ;
;
offseti = adc_counts > > 1 ;
}

/ /
--------------------------------------------------------------------------------------/ / ชุดหมุดจะใช้แรงดันและกระแสเซ็นเซอร์ตามแผนที่ Pin emontx
/ /
-------------------------------------------------------------------------------------- เป็นโมฆะ energymonitor : : voltagetx ( คู่ _vcal คู่ _phasecal )
{
inpinv = 2 ;
vcal = = _phasecal phasecal _vcal ;
;
offsetv = adc_counts > > 1 ;
}

โมฆะ energymonitor : : currenttx ( int / _channel คู่ _ical )
{
ถ้า ( _channel = = 1 ) inpini = 3 ;
( ถ้า _channel = = 2 ) inpini = 0 ;
( ถ้า _channel = = 3 ) inpini = 1 ;
= _ical iCal ;
offseti = adc_counts > > 1 ;
}

/ / --------------------------------------------------------------------------------------
/ /
/ / คำนวณ emon_calc ขั้นตอน realpower apparentpower , เพาเวอร์แฟกเตอร์ vrms irms , , , ,
/ / ( เพิ่มจากตัวอย่างหน้าต่างของไฟ AC แรงดันและกระแส
/ / หน้าต่างตัวอย่างความยาวจะถูกกำหนดโดยจำนวนของครึ่งความยาวคลื่น หรือ วกเราเลือกวัด
/ /
-------------------------------------------------------------------------------------- เป็นโมฆะ energymonitor : : calcvi ( int / int ข้าม / , timeout )
{

#ถ้ากำหนด emontxv3 int supplyvoltage = 3300 ;
#อีก

# int supplyvoltage = readvcc() ; จบถ้า

crosscount / int = 0 ; / / ใช้ในการวัดจำนวนครั้งของข้าม .
/ int numberofsamples = 0 ; / / ตอนนี้สั่ง

/ / -------------------------------------------------------------------------------------------------------------------------
/ / 1 ) รอให้สัญญาณที่ได้ใกล้ชิดกับ ' ศูนย์ ' ( มิดสเกล ADC ) ส่วนในบาป
โค้ง/ / -------------------------------------------------------------------------------------------------------------------------
บูลีนเซนต์ = false ; / / ตัวบ่งชี้ที่จะออกในขณะที่วง

ไม่ได้ลงนามยาวเริ่ม = millis() ; / / millis() - เริ่มต้นให้แน่ใจว่ามันไม่ได้รับติดอยู่ในลูปหากมีข้อผิดพลาด .

ขณะที่ ( เซนต์ = = เท็จ ) / / ในขณะที่วง {

. . . . . . . สตาร์ = analogread ( inpinv ) ; / / ใช้รูปคลื่นแรงดัน
ถ้า ( ( สตาร์ < ( adc_counts * 0.55 ) && ( สตาร์ > ( adc_counts * 0.45 เซนต์จริง = ) ) ) ) ) ) ) ; / / ตรวจสอบภายในช่วง
ถ้า ( ( millis() - เริ่มต้น ) > หมดเวลา ) เซนต์ = true ;
}

/ / -------------------------------------------------------------------------------------------------------------------------
/ /
2 ) ห่วงวัดหลัก/ / -------------------------------------------------------------------------------------------------------------------------
เริ่มต้น = millis() ;

ตอน ( ( crosscount < ข้าม ) && ( ( millis() - เริ่มต้น ) < หมดเวลา )
{
numberofsamples ; / / นับจำนวนครั้งที่ looped .
lastfilteredv = filteredv ; / / ใช้สำหรับหน่วงเวลา / ขั้นตอนการชดเชย

/ / -----------------------------------------------------------------------------
/ / ) อ่านในแรงดันไฟฟ้าดิบและปัจจุบันตัวอย่าง

/ / ----------------------------------------------------------------------------- samplev = analogread ( inpinv ) ; / / อ่านดิบแรงดันสัญญาณ
samplei = analogread ( inpini ) ; / / อ่าน

ปัจจุบันสัญญาณดิบ/ / -----------------------------------------------------------------------------
/ / B ) ใช้ตัวกรองต่ำผ่านดิจิตอลสกัด 2.5 V หรือ 1.65 V DC offset
/ / แล้วลบ - สัญญาณขณะนี้ศูนย์กลางอยู่ที่ 0 นับ -----------------------------------------------------------------------------

/ / offsetv = offsetv ( ( samplev offsetv ) / 1024 ) ;
-
filteredv = samplev offsetv ;offseti = offseti ( ( samplei offseti ) / 1024 ) ;
filteredi = samplei - offseti ;

/ / -----------------------------------------------------------------------------
/ / C ) Root Mean Square วิธีแรงดัน
/ /
----------------------------------------------------------------------------- ราคาถูก = filteredv * filteredv ; / / 1 ) ตารางแรงดันค่า
sumv = ราคาถูก ; / / 2 ) ผลรวม

/ / -----------------------------------------------------------------------------
/ / D ) รากหมายความว่าสี่เหลี่ยมจัตุรัสวิธีปัจจุบัน

/ / ----------------------------------------------------------------------------- sqi = filteredi * filteredi ; / / 1 ) ตารางปัจจุบันค่า
sqi สุมิ = ; / / 2 ) ผลรวม

/ / -----------------------------------------------------------------------------
/ /
( E ) การสอบเทียบ/ / -----------------------------------------------------------------------------
phaseshiftedv = lastfilteredv phasecal * ( filteredv - lastfilteredv ) ;

/ / -----------------------------------------------------------------------------
/ / F )
/ / ----------------------------------------------------------------------------- ทันทีพลัง Calc
instp = phaseshiftedv * filteredi ;/ / " พลัง
บ่อ = ผลรวม instp ; / /

/ / -----------------------------------------------------------------------------
/ / G ) หาจำนวนครั้งแรงดันไฟฟ้าข้ามแรงดันเริ่มต้น
/ / - ทุก 2 คู่ผสม เราจะมีตัวอย่าง 1 ความยาวคลื่น
/ / - ดังนั้น วิธีนี้ช่วยให้เราสามารถใช้เลขจำนวนเต็มครึ่งความยาวคลื่นซึ่งช่วยเพิ่มความถูกต้อง
/ / -----------------------------------------------------------------------------
lastvcross = checkvcross ;
( ถ้า samplev > สตาร์ ) checkvcross = true ;
อีก checkvcross = false ;
( ถ้า numberofsamples = = 1 ) lastvcross = checkvcross ;

ถ้า ( lastvcross ! = checkvcross ) crosscount
}

;/ / -------------------------------------------------------------------------------------------------------------------------
/ / 3 ) การคำนวณวงโพสต์

/ / / / ------------------------------------------------------------------------------------------------------------------------- คำนวณรากของค่าเฉลี่ยของแรงดันและกระแสยกกำลังสอง ( RMS )
/ / การสอบเทียบค่าใช้

คู่ v_ratio = vcal * ( ( supplyvoltage / 1000.0 ) / ( adc_counts ) ) ;
vrms = v_ratio * SQRT ( sumv / numberofsamples ) ;

คู่ i_ratio = iCal * ( ( supplyvoltage / 1000.0 ) / ( adc_counts ) ) ;
irms = i_ratio * SQRT ( ซูมิ / numberofsamples

/ ) การคำนวณค่าพลังงาน /
realpower = v_ratio * i_ratio * บ่อ / numberofsamples ;
apparentpower = vrms * irms ;
เพาเวอร์แฟคเตอร์ = realpower / apparentpower

;/ / ตั้งค่าการสะสม
sumv = 0 ;
สุมิ = 0 ;
บ่อ = 0 ;
/ / --------------------------------------------------------------------------------------
}

/ / --------------------------------------------------------------------------------------
คู่ energymonitor : : calcirms ( int / number_of_samples )
{

#ถ้ากำหนด emontxv3
Int supplyvoltage = 3300 ;
#อีก
supplyvoltage int = readvcc() ;
#จบถ้า


( / INT N = 0 ; n < number_of_samples ; n )
{
samplei = analogread ( inpini ) ;

/ / ตัวกรองต่ำผ่านดิจิตอลแยก 2.5 V หรือ 1.65 V DC offset
/ / แล้วลบ - สัญญาณตอนนี้อยู่ 0
offseti นับ = ( offseti ( samplei offseti ) / 1024 ) ;
filteredi = samplei - offseti ;

/ / รากหมายความว่าสี่เหลี่ยมจัตุรัสวิธีปัจจุบัน
/ /
1 ) ตารางปัจจุบันค่าsqi = filteredi * filteredi ;
/ / 2 ) ผลรวม
สุมิ = sqi ;
}

คู่ i_ratio = iCal * ( ( supplyvoltage / 1000.0 ) / ( adc_counts ) ) ;
irms = i_ratio * SQRT ( ซูมิ / number_of_samples ) ;

/ / ตั้งค่าการสะสม

/ / สุมิ = 0 ; --------------------------------------------------------------------------------------

กลับมา irms ;
}

เป็นโมฆะ energymonitor : : serialprint()
{
ต่อเนื่อง พิมพ์ ( realpower ) ;
อนุกรมพิมพ์ ( ' ' ) ;
ต่อเนื่อง พิมพ์ ( apparentpower ) ;
ต่อเนื่อง พิมพ์ ( ' ' ) ;
ต่อเนื่อง พิมพ์ ( vrms ) ;
ต่อเนื่อง พิมพ์ ( ' ' ) ;
ต่อเนื่อง พิมพ์ ( irms ) ;
ต่อเนื่อง พิมพ์ ( ' ' ) ;
( เพาเวอร์แฟคเตอร์ ) พิมพ์ต่อเนื่อง ;
ต่อเนื่อง println ( ' ' ) ;
ล่าช้า ( 100 ) ;
}
การแปล กรุณารอสักครู่..
 
ภาษาอื่น ๆ
การสนับสนุนเครื่องมือแปลภาษา: กรีก, กันนาดา, กาลิเชียน, คลิงออน, คอร์สิกา, คาซัค, คาตาลัน, คินยารวันดา, คีร์กิซ, คุชราต, จอร์เจีย, จีน, จีนดั้งเดิม, ชวา, ชิเชวา, ซามัว, ซีบัวโน, ซุนดา, ซูลู, ญี่ปุ่น, ดัตช์, ตรวจหาภาษา, ตุรกี, ทมิฬ, ทาจิก, ทาทาร์, นอร์เวย์, บอสเนีย, บัลแกเรีย, บาสก์, ปัญจาป, ฝรั่งเศส, พาชตู, ฟริเชียน, ฟินแลนด์, ฟิลิปปินส์, ภาษาอินโดนีเซี, มองโกเลีย, มัลทีส, มาซีโดเนีย, มาราฐี, มาลากาซี, มาลายาลัม, มาเลย์, ม้ง, ยิดดิช, ยูเครน, รัสเซีย, ละติน, ลักเซมเบิร์ก, ลัตเวีย, ลาว, ลิทัวเนีย, สวาฮิลี, สวีเดน, สิงหล, สินธี, สเปน, สโลวัก, สโลวีเนีย, อังกฤษ, อัมฮาริก, อาร์เซอร์ไบจัน, อาร์เมเนีย, อาหรับ, อิกโบ, อิตาลี, อุยกูร์, อุสเบกิสถาน, อูรดู, ฮังการี, ฮัวซา, ฮาวาย, ฮินดี, ฮีบรู, เกลิกสกอต, เกาหลี, เขมร, เคิร์ด, เช็ก, เซอร์เบียน, เซโซโท, เดนมาร์ก, เตลูกู, เติร์กเมน, เนปาล, เบงกอล, เบลารุส, เปอร์เซีย, เมารี, เมียนมา (พม่า), เยอรมัน, เวลส์, เวียดนาม, เอสเปอแรนโต, เอสโทเนีย, เฮติครีโอล, แอฟริกา, แอลเบเนีย, โคซา, โครเอเชีย, โชนา, โซมาลี, โปรตุเกส, โปแลนด์, โยรูบา, โรมาเนีย, โอเดีย (โอริยา), ไทย, ไอซ์แลนด์, ไอร์แลนด์, การแปลภาษา.

Copyright ©2024 I Love Translation. All reserved.

E-mail: