/* 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
*/

//#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(int _inPinV, double _VCAL, double _PHASECAL)
{
inPinV = _inPinV;
VCAL = _VCAL;
PHASECAL = _PHASECAL;
}

void EnergyMonitor::current(int _inPinI, double _ICAL)
{
inPinI = _inPinI;
ICAL = _ICAL;
}

//--------------------------------------------------------------------------------------
// 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;
}

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

//--------------------------------------------------------------------------------------
// 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(int crossings, int timeout)
{
#if defined emonTxV3
int SUPPLYVOLTAGE=3300;
#else
int SUPPLYVOLTAGE = readVcc();
#endif

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

//-------------------------------------------------------------------------------------------------------------------------
// 1) Waits for the waveform to be close to 'zero' (500 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/2+50)) && (startV > (ADC_COUNTS/2-50))) st=true; //check its within range
if ((millis()-start)>timeout) st = true;
}

//-------------------------------------------------------------------------------------------------------------------------
// 2) Main measurment 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 coeficients 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(int NUMBER_OF_SAMPLES)
{

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


for (int n = 0; n < NUMBER_OF_SAMPLES; n++)
{
lastSampleI = sampleI;
sampleI = analogRead(inPinI);
lastFilteredI = filteredI;
filteredI = 0.996*(lastFilteredI+sampleI-lastSampleI);

// 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);
}

//thanks to http://hacking.majenko.co.uk/making-accurate-adc-readings-on-arduino
//and Jรฉrรดme who alerted us to http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/

long EnergyMonitor::readVcc() {
long result;

//not used on emonTx V3 - as Vcc is always 3.3V - eliminates bandgap error and need for calibration http://harizanov.com/2013/09/thoughts-on-avr-adc-accuracy/

#if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || defined (__AVR_ATmega328P__)
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_AT90USB1286__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
ADCSRB &= ~_BV(MUX5); // Without this the function always returns -1 on the ATmega2560 http://openenergymonitor.org/emon/node/2253#comment-11432
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2)
0/5000
จาก: -
เป็น: -
ผลลัพธ์ (ไทย) 1: [สำเนา]
คัดลอก!
/* Emon.cpp - ไลบรารีสำหรับ openenergymonitor สร้าง โดย Trystan Lea, 27 2553 เมษายน GNU GPL ปรับเปลี่ยนการใช้ค่าความละเอียด 12 บิต ADC (เช่นครบกำหนดสืบ) โดย boredman@boredomprojects.net 26.12.2013*/#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}ยกเลิก EnergyMonitor::current (int _inPinI, _ICAL คู่){ inPinI = _inPinI ICAL = _ICAL}//--------------------------------------------------------------------------------------กำหนดหมุดที่ใช้สำหรับแรงดันไฟฟ้าและเซ็นเซอร์ปัจจุบันตามแผนที่ pin emontx//--------------------------------------------------------------------------------------ยกเลิก EnergyMonitor::voltageTX (_VCAL, _PHASECAL คู่คู่){ inPinV = 2 VCAL = _VCAL PHASECAL = _PHASECAL}ยกเลิก EnergyMonitor::currentTX (int _channel, _ICAL คู่){ ถ้า (_channel == 1) inPinI = 3 ถ้า (_channel == 2) inPinI = 0 ถ้า (_channel == 3) inPinI = 1 ICAL = _ICAL}//--------------------------------------------------------------------------------------กระบวนการ 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) รอรูปคลื่นที่จะใกล้กับ 'ศูนย์' (500 adc) ส่วนในโค้งความบาป //------------------------------------------------------------------------------------------------------------------------- บูลีนเซนต์ =เท็จ ตัวบ่งชี้เพื่อจบการทำงานในลูป รับรองเริ่มยาว = millis() (millis)-เริ่มต้นให้แน่ใจว่าไม่ได้ติดอยู่ในลูปถ้ามีข้อผิดพลาด //the while(st==false) ในขณะที่วน... { startV = analogRead(inPinV) ใช้รูปคลื่นแรงดันไฟฟ้า ถ้า ((startV < (ADC_COUNTS/2 + 50)) & & (startV > (ADC_COUNTS/2-50))) เซนต์ =จริง ตรวจสอบอยู่ภายในช่วง ถ้า ((millis()-start)>timeout) เซนต์ =จริง } //------------------------------------------------------------------------------------------------------------------------- 2 วน measurment หลัก //------------------------------------------------------------------------------------------------------------------------- เริ่มต้น = millis() ในขณะที่ ((crossCount < crossings) & & ((millis()-start) { numberOfSamples ++ นับจำนวนครั้ง looped lastSampleV = sampleV ใช้สำหรับตัวกรองผ่านสูงดิจิตอล lastSampleI = sampleI ใช้สำหรับตัวกรองผ่านสูงดิจิตอล lastFilteredV = filteredV ใช้สำหรับลบตรงข้าม lastFilteredI = filteredI ใช้สำหรับลบตรงข้าม //----------------------------------------------------------------------------- A) อ่านแรงดิบและตัวอย่างในปัจจุบัน //----------------------------------------------------------------------------- sampleV = analogRead(inPinV) อ่านสัญญาณแรงดิบ sampleI = analogRead(inPinI) อ่านในปัจจุบันสัญญาณดิบ //----------------------------------------------------------------------------- ขใช้ตัวกรองผ่านสูงดิจิตอลออฟเซ็ต DC เอา 2.5V (แปลก 0V) //----------------------------------------------------------------------------- filteredV = 0.996*(lastFilteredV+(sampleV-lastSampleV)) filteredI = 0.996*(lastFilteredI+(sampleI-lastSampleI)) //----------------------------------------------------------------------------- แรงดันไฟฟ้าวิธี 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) ใช้ coeficients เทียบ คู่ 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 ++) { lastSampleI = sampleI sampleI = analogRead(inPinI) lastFilteredI = filteredI filteredI = 0.996*(lastFilteredI+sampleI-lastSampleI) ปัจจุบันรากค่าเฉลี่ยกำลังสองวิธี 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) }ขอบคุณ http://hacking.majenko.co.uk/making-accurate-adc-readings-on-arduinoและ Jรฉrรดme ที่แจ้งเตือนเรา http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/{EnergyMonitor::readVcc() ยาว ผลยาว ไม่ใช้ emonTx V3 - เป็น Vcc เป็น 3.3 v - กำจัด bandgap ข้อผิดพลาดและจำเป็นสำหรับการปรับเทียบ http://harizanov.com/2013/09/thoughts-on-avr-adc-accuracy/ #if defined(__AVR_ATmega168__) || defined(__AVR_ATmega328__) || กำหนด (__AVR_ATmega328P__) ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) #elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_AT90USB1286__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1) ADCSRB & = ~ _BV(MUX5) โดยนี้ ฟังก์ชันจะส่งกลับ -1 บน ATmega2560 http://openenergymonitor.org/emon/node/2253#comment-11432 กำหนด #elif (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0) กำหนด #elif (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) ADMUX = _BV(MUX3) | _BV(MUX2)
การแปล กรุณารอสักครู่..
ผลลัพธ์ (ไทย) 2:[สำเนา]
คัดลอก!
/ *
Emon.cpp - ห้องสมุดสำหรับ openenergymonitor
สร้างโดย Trystan ทุ่งหญ้า 27 เมษายน 2010
GNU GPL
ปรับเปลี่ยนการใช้งานได้ถึง 12 บิตความละเอียด ADC (ex. เนื่องจาก Arduino)
โดย boredman@boredomprojects.net 2013/12/26
* / // # รวม " WProgram.h "ยกเลิกการแสดงความคิดเห็นสำหรับใช้ในรุ่นเก่าของ Arduino IDE #include "EmonLib.h" # ถ้ากำหนด (ARDUINO) && ARDUINO> = 100 # include "Arduino.h" # อื่น#include ตั้งหมุดที่จะใช้สำหรับแรงดันไฟฟ้าและเซ็นเซอร์ปัจจุบัน// ------------------------------------- ------------------------------------------------- โมฆะ EnergyMonitor :: แรงดันไฟฟ้า (int _inPinV, _VCAL คู่ _PHASECAL คู่) { inPinV = _inPinV; VCAL = _VCAL; PHASECAL = _PHASECAL; } เป็นโมฆะ EnergyMonitor :: ปัจจุบัน (int _inPinI, _ICAL คู่) { inPinI = _inPinI; ICAL = _ICAL; } // ------------------------------------------------ -------------------------------------- // ชุดขาที่จะใช้สำหรับแรงดันและกระแส เซ็นเซอร์บนพื้นฐานของ emontx พิแผนที่// ------------------------------------------ -------------------------------------------- โมฆะ EnergyMonitor :: voltageTX ( _VCAL สองครั้งสองครั้ง _PHASECAL) { inPinV = 2; VCAL = _VCAL; PHASECAL = _PHASECAL; } เป็นโมฆะ EnergyMonitor :: currentTX (int _channel, _ICAL คู่) { ถ้า (_channel == 1) inPinI = 3; ถ้า (_channel == 2 ) inPinI = 0; ถ้า (_channel == 3) inPinI = 1; ICAL = _ICAL; } // --------------------------- -------------------------------------------------- --------- // ขั้นตอน emon_calc // คำนวณ realPower, apparentPower, powerFactor, Vrms, Irms เพิ่มขึ้นหน่วย// จากหน้าต่างตัวอย่างของแรงดันไฟ AC และปัจจุบัน. // ระยะเวลาในหน้าต่างตัวอย่างที่กำหนดไว้ จากจำนวนความยาวคลื่นครึ่งหนึ่งหรือข้ามเราเลือกที่จะวัด. // ----------------------------------- -------------------------------------------------- - เป็นโมฆะ EnergyMonitor :: calcVI (int ข้ามหมดเวลา int) { # ถ้ากำหนด emonTxV3 int SUPPLYVOLTAGE = 3300; # อื่นint SUPPLYVOLTAGE = readVcc (); #endif crossCount int = 0; // ใช้ในการวัดจำนวนครั้งเกณฑ์ข้าม. numberOfSamples int = 0; // นี่คือตอนนี้ 1) รอสำหรับรูปแบบของคลื่นจะใกล้เคียงกับ 'ศูนย์' (500 ADC) มีส่วนร่วมในความบาป เซนต์ = false; // ตัวบ่งชี้ที่จะออกจากวงในขณะที่ไม่ได้ลงนามเริ่มต้นนาน MILLIS = (); // MILLIS () - เริ่มต้นที่จะทำให้แน่ใจว่ามันไม่ได้รับการติดอยู่ในวงถ้ามีข้อผิดพลาด. ในขณะที่ (เซนต์ == เท็จ) // ห่วงในขณะที่ ... { StarTV = analogRead (inPinV); // การใช้สัญญาณแรงดันถ้า ((StarTV <(ADC_COUNTS / 2 + 50)) && (StarTV> (ADC_COUNTS / 2-50))) เซนต์ = true; // ตรวจสอบภายในช่วงถ้า ((MILLIS () - เริ่มต้น)> หมดเวลา) เซนต์ = 2) การวัดหลัก = MILLIS (); ในขณะที่ ((crossCount <ข้าม) && ((MILLIS () - เริ่มต้น)




















































































{
numberOfSamples ++; // ตัวเลขจำนวนครั้งคล้อง. lastSampleV = sampleV; // ใช้สำหรับการผ่านสูงดิจิตอลกรองlastSampleI = sampleI; // ใช้สำหรับการกรองผ่านสูงดิจิตอลlastFilteredV = filteredV; // ใช้สำหรับการกำจัดชดเชยlastFilteredI = filteredI; // ใช้สำหรับการกำจัดชดเชย// ------------------------------------------ ----------------------------------- //) อ่านแรงดันไฟฟ้าดิบและตัวอย่างปัจจุบัน// - -------------------------------------------------- ------------------------- sampleV = analogRead (inPinV); // อ่านในสัญญาณแรงดันไฟฟ้าดิบsampleI = analogRead (inPinI); // อ่านสัญญาณในปัจจุบันดิบ// ----------------------------------------- ------------------------------------ // B) ใช้กรองผ่านสูงดิจิตอลเพื่อลบ 2.5V DC ชดเชย (ศูนย์รวมอยู่ที่ 0V). // ----------------------------------------- ------------------------------------ filteredV = 0.996 * (lastFilteredV + (sampleV-lastSampleV)); filteredI = 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) // coeficients สอบเทียบใช้. คู่ 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 (int NUMBER_OF_SAMPLES) { # ถ้ากำหนด emonTxV3 int SUPPLYVOLTAGE = 3300; # อื่นint SUPPLYVOLTAGE = readVcc (); #endif สำหรับ (int n = 0; n <NUMBER_OF_SAMPLES; n ++) { lastSampleI = sampleI; sampleI = analogRead (inPinI); lastFilteredI = filteredI; filteredI = 0.996 * (lastFilteredI + sampleI-lastSampleI); // รากเฉลี่ยตารางวิธีปัจจุบัน// 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 (''); อนุกรม .print (powerFactor); Serial.println (''); ล่าช้า (100); } // ขอบคุณที่ http://hacking.majenko.co.uk/making-accurate-adc-readings-on-arduino // และ J รฉ R รดฉันที่แจ้งเตือนให้เราสามารถ http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ EnergyMonitor ยาว :: readVcc () { ผลยาว; // ไม่ได้นำมาใช้ใน emonTx V3 - เป็น Vcc 3.3V อยู่เสมอ - ช่วยขจัดข้อผิดพลาด bandgap และความจำเป็นในการสอบเทียบ http://harizanov.com/2013/09/thoughts-on-avr-adc-accuracy/ # ถ้ากำหนด (__ AVR_ATmega168__) || กำหนด (__ AVR_ATmega328__) | | กำหนด (__AVR_ATmega328P__) ADMUX = _BV (REFS0) | _BV (MUX3) | _BV (MUX2) | _BV (MUX1); #elif กำหนด (__ AVR_ATmega32U4__) || กำหนด (__ AVR_ATmega1280__) || กำหนด (__ AVR_ATmega2560__) || กำหนด (__ AVR_AT90USB1286__ ) ADMUX = _BV (REFS0) | _BV (MUX4) | _BV (MUX3) | _BV (MUX2) | _BV (MUX1); ADCSRB & = ~ _BV (MUX5); // โดยไม่ต้องฟังก์ชั่นนี้เสมอกลับ -1 เมื่อ ATmega2560 http://openenergymonitor.org/emon/node/2253#comment-11432 #elif กำหนด (__AVR_ATtiny24__) || กำหนด (__ AVR_ATtiny44__) || กำหนด (__ AVR_ATtiny84__) ADMUX = _BV (MUX5) | _BV (MUX0); #elif กำหนด (__AVR_ATtiny25__) || กำหนด (__ AVR_ATtiny45__) || กำหนด (__ AVR_ATtiny85__) ADMUX = _BV (MUX3) | _BV (MUX2)

















































































































































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

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

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

#ถ้ากำหนด ( Arduino ) && Arduino > = 100

#รวมถึง " Arduino . H "

#อีก

#รวมถึง " wprogram .H "

#จบถ้า --------------------------------------------------------------------------------------


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

energymonitor โมฆะ : : ปัจจุบัน ( int _inpini คู่ _ical )
{
inpini = = _ical iCal _inpini ;
;
}

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

เป็นโมฆะ energymonitor : : currenttx ( int _channel คู่ _ical

) { ถ้า ( _channel = = 1 ) inpini = 3 ;
( ถ้า _channel = = 2 ) inpini = 0 ;
ถ้า ( _channel = = 3 ) inpini = 1 ;
= _ical iCal ;
}

/ / --------------------------------------------------------------------------------------

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

;#อีก
supplyvoltage int = readvcc() ;


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

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

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

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

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

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

ตอน ( ( crosscount < ข้าม ) && ( ( millis() - เริ่มต้น ) < หมดเวลา )
{
numberofsamples ; / / นับจำนวนครั้งที่ looped

lastsamplev = samplev ; / / ใช้ตัวกรองดิจิตอลผ่านสูง
lastsamplei = samplei ; / / ใช้ ดิจิตอลผ่านเครื่องกรองสูง

lastfilteredv = filteredv ; / / ใช้สำหรับชดเชยเอา
lastfilteredi = filteredi ; / / ใช้สำหรับชดเชยการ -----------------------------------------------------------------------------


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

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

/ / -----------------------------------------------------------------------------
/ / B ) ใช้ตัวกรองผ่านสูงดิจิตอลเพื่อลบ 2.5v DC offset ( กึ่งกลาง 0v )
/ /
filteredv โดย ----------------------------------------------------------------------------- = * ( lastfilteredv ( samplev lastsamplev ) ) ;
filteredi = 0เพลง * * * * ( lastfilteredi ( samplei lastsamplei ) ) ;

/ / -----------------------------------------------------------------------------
/ / 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 )
/ / การสอบเทียบ coeficients ประยุกต์

คู่ 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 ;
# int supplyvoltage = readvcc() อีก

; #จบถ้า


( INT N = 0 ; n < number_of_samples ; n )
{
lastsamplei = samplei ;
samplei = analogread ( inpini ) ;
lastfilteredi = filteredi ;
filteredi = โดย * * * * ( lastfilteredi samplei lastsamplei ) ;

/ / รากหมายความว่าสี่เหลี่ยมจัตุรัสวิธีปัจจุบัน
/ / 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 ) ;
}

/ / ขอบคุณที่ http : / / แฮ็ค majenko . โดยเว็บไซต์ดังกล่าว / ทำให้อ่าน ADC ที่ถูกต้องใน Arduino
/ / และ J R รดเดียวกับที่เตือนฉันเราที่ http : / / provideyourown . com / 2012 / ความลับของ Arduino โวลต์มิเตอร์วัดแรงดันแบตเตอรี่ /

ยาว energymonitor : : readvcc() {
ผลยาว ;

/ / ไม่ใช้ emontx V3 - เป็น VCC เสมอ 3- ลดความผิดพลาด bandgap 3V และความต้องการสำหรับการสอบเทียบ http : / / harizanov . com / 2012 / 09 / ความคิดเกี่ยวกับ AVR ADC ความถูกต้อง

#ถ้ากำหนด ( __avr_atmega168__ ) | | กำหนด ( __avr_atmega328__ ) | | กำหนด ( __avr_atmega328p__ )
admux = _bv ( refs0 ) | _bv ( mux3 ) | _bv ( mux2 ) | _bv ( mux1 ) ;
# elif กำหนด ( __avr_atmega32u4__ ) | | กำหนด ( __avr_atmega1280__ ) | | กำหนด ( __avr_atmega2560__ ) | ( __avr_at90usb1286__ )
| กําหนดadmux = _bv ( refs0 ) | _bv ( mux4 ) | _bv ( mux3 ) | _bv ( mux2 ) | _bv ( mux1 ) ;
adcsrb & = ~ _bv ( mux5 ) ; / / ถ้าฟังก์ชันส่งกลับ - 1 เสมอใน atmega2560 http : / / openenergymonitor . org / Emon โหนด / / #พื้นฐาน comment-11432
# elif กำหนด ( __avr_attiny24__ ) | | กำหนด ( __avr_attiny44__ ) | | กำหนด ( __avr_attiny84__ )
admux = _bv ( mux5 ) | _bv (
mux0 )# elif กำหนด ( __avr_attiny25__ ) | | กำหนด ( __avr_attiny45__ ) | | กำหนด ( __avr_attiny85__ )
admux = _bv ( mux3 ) | _bv ( mux2 )
การแปล กรุณารอสักครู่..
 
ภาษาอื่น ๆ
การสนับสนุนเครื่องมือแปลภาษา: กรีก, กันนาดา, กาลิเชียน, คลิงออน, คอร์สิกา, คาซัค, คาตาลัน, คินยารวันดา, คีร์กิซ, คุชราต, จอร์เจีย, จีน, จีนดั้งเดิม, ชวา, ชิเชวา, ซามัว, ซีบัวโน, ซุนดา, ซูลู, ญี่ปุ่น, ดัตช์, ตรวจหาภาษา, ตุรกี, ทมิฬ, ทาจิก, ทาทาร์, นอร์เวย์, บอสเนีย, บัลแกเรีย, บาสก์, ปัญจาป, ฝรั่งเศส, พาชตู, ฟริเชียน, ฟินแลนด์, ฟิลิปปินส์, ภาษาอินโดนีเซี, มองโกเลีย, มัลทีส, มาซีโดเนีย, มาราฐี, มาลากาซี, มาลายาลัม, มาเลย์, ม้ง, ยิดดิช, ยูเครน, รัสเซีย, ละติน, ลักเซมเบิร์ก, ลัตเวีย, ลาว, ลิทัวเนีย, สวาฮิลี, สวีเดน, สิงหล, สินธี, สเปน, สโลวัก, สโลวีเนีย, อังกฤษ, อัมฮาริก, อาร์เซอร์ไบจัน, อาร์เมเนีย, อาหรับ, อิกโบ, อิตาลี, อุยกูร์, อุสเบกิสถาน, อูรดู, ฮังการี, ฮัวซา, ฮาวาย, ฮินดี, ฮีบรู, เกลิกสกอต, เกาหลี, เขมร, เคิร์ด, เช็ก, เซอร์เบียน, เซโซโท, เดนมาร์ก, เตลูกู, เติร์กเมน, เนปาล, เบงกอล, เบลารุส, เปอร์เซีย, เมารี, เมียนมา (พม่า), เยอรมัน, เวลส์, เวียดนาม, เอสเปอแรนโต, เอสโทเนีย, เฮติครีโอล, แอฟริกา, แอลเบเนีย, โคซา, โครเอเชีย, โชนา, โซมาลี, โปรตุเกส, โปแลนด์, โยรูบา, โรมาเนีย, โอเดีย (โอริยา), ไทย, ไอซ์แลนด์, ไอร์แลนด์, การแปลภาษา.

Copyright ©2025 I Love Translation. All reserved.

E-mail: