diff --git a/Documents/Temperature.md b/Documents/Temperature.md new file mode 100644 index 0000000..8bfe36f --- /dev/null +++ b/Documents/Temperature.md @@ -0,0 +1,11 @@ +# Çip Sıcaklığı Kalibrasyonu + +**MAX78630**, voltaj referans hatalarını (sıcaklık nedeni ile oluşabilecek) izlemek için ölçüm işlemcisi tarafından kullanılabilen ve **TEMPC** registeri ile kullanıcıya sunulan dahili bir çip sıcaklık sensörüne sahiptir. + +**COMMAND** registeri içerisinde yer alan **TC** bitinin ayarlanması (True: etkin), üretici yazılımının ölçülen çip sıcaklığına dayalı olarak daha hassas ayar yapmasına izin verir. $T = (T_g * T_0) + T_o$. Sıcaklık ofseti kullanıcı tarafından **T_OFFS** registeri yardımı ile kalibre edilebilir. Sıcaklık kazancı ise **T_GAIN** registeri yardımı ile kullanıcı tarafından kalibre edilebilir olduğu gibi aynı zamanda fabrika çıkışı olarak ayarlanmıştır. + +| Register | Açıklama | | +|----------|------------------------------------------|-------| +| T_OFFS | Çip sıcaklığı offset kalibrasyon değeri. | $T_o$ | +| T_GAIN | Çip sıcaklığı kazanç kalibrasyon değeri. | $T_g$ | + diff --git a/examples/test/test.ino b/examples/test/test.ino index eb00123..bb67ccd 100644 --- a/examples/test/test.ino +++ b/examples/test/test.ino @@ -53,10 +53,6 @@ void loop() { - VT100.setTextColor(VT_CYAN); VT100.setCursor(25, 30); Serial.print(Energy_Analayser.Phase_Compensation('R')); - VT100.setTextColor(VT_CYAN); VT100.setCursor(26, 30); Serial.print(Energy_Analayser.Phase_Compensation('S')); - VT100.setTextColor(VT_CYAN); VT100.setCursor(27, 30); Serial.print(Energy_Analayser.Phase_Compensation('T')); - /* diff --git a/src/MAX78630.cpp b/src/MAX78630.cpp index ae06d95..c61f2c6 100644 --- a/src/MAX78630.cpp +++ b/src/MAX78630.cpp @@ -217,6 +217,7 @@ Register DEVADDR {0x00, 0x4E, 0, true}; // High order address bits for I2C and Register BAUD {0x00, 0x51, 0, true}; // Baud rate for UART interface Register SYSSTAT {0x02, 0x43, 0, false}; // Bit 23 is a sticky register with status of any SPI Errors +// Begin Functions bool MAX78630::Begin(void) { // Start Serial Communication @@ -319,6 +320,35 @@ bool MAX78630::Begin(void) { } +// Set Scale Registers +bool MAX78630::Set_VScale(uint32_t _VScale) { + + // Set Register + _Register_Pointer_Set(VSCALE, _VScale); + + // End Function + return(true); + +} +bool MAX78630::Set_IScale(uint32_t _IScale) { + + // Set Register + _Register_Pointer_Set(IFSCALE, _IScale); + + // End Function + return(true); + +} +bool MAX78630::Set_Harmonic(uint32_t _Harmonic) { + + // Set Register + _Register_Pointer_Set(HARM, _Harmonic); + + // End Function + return(true); + +} + // Voltage Measurements float MAX78630::Voltage_RMS(char Phase) { @@ -328,6 +358,7 @@ float MAX78630::Voltage_RMS(char Phase) { if (Phase == 'R') _Result = _Register_Pointer_Read(VA_RMS); // Measure Phase R if (Phase == 'S') _Result = _Register_Pointer_Read(VB_RMS); // Measure Phase S if (Phase == 'T') _Result = _Register_Pointer_Read(VC_RMS); // Measure Phase T + if (Phase == 'A') _Result = _Register_Pointer_Read(VT_RMS); // Measure Phase Average // End Function return(_Result * _VScale); @@ -371,17 +402,6 @@ float MAX78630::Voltage_Harmonic(char Phase) { // End Function return(_Result * _VScale); -} -float MAX78630::Voltage_V_Target(void) { - - // Declare Variable - float _Result = 0; - - _Result = _Register_Pointer_Read(V_TARGET); // Measure Phase R - - // End Function - return(_Result * _VScale); - } float MAX78630::Voltage_RMS_Min(void) { @@ -426,6 +446,7 @@ float MAX78630::Current_RMS(char Phase) { if (Phase == 'R') _Result = _Register_Pointer_Read(IA_RMS); // Measure Phase R if (Phase == 'S') _Result = _Register_Pointer_Read(IA_RMS); // Measure Phase S if (Phase == 'T') _Result = _Register_Pointer_Read(IA_RMS); // Measure Phase T + if (Phase == 'A') _Result = _Register_Pointer_Read(IT_RMS); // Measure Phase Average // End Function return(_Result * _IScale); @@ -443,6 +464,19 @@ float MAX78630::Current_Instantaneous(char Phase) { // End Function return(_Result * _IScale); +} +float MAX78630::Current_Peak(char Phase) { + + // Declare Variable + float _Result = 0; + + if (Phase == 'R') _Result = _Register_Pointer_Read(IA_PEAK); // Measure Phase R + if (Phase == 'S') _Result = _Register_Pointer_Read(IB_PEAK); // Measure Phase S + if (Phase == 'T') _Result = _Register_Pointer_Read(IC_PEAK); // Measure Phase T + + // End Function + return(_Result * _IScale); + } float MAX78630::Current_Fundamental(char Phase) { @@ -470,64 +504,129 @@ float MAX78630::Current_Harmonic(char Phase) { return(_Result * _IScale); } -float MAX78630::Current_I_Target(void) { +float MAX78630::Current_RMS_Max(void) { // Declare Variable float _Result = 0; - _Result = _Register_Pointer_Read(I_TARGET); // Measure Phase R + _Result = _Register_Pointer_Read(IRMS_MAX); // Measure Phase R // End Function return(_Result * _IScale); } -float MAX78630::Current_RMS_Max(void) { + +// Power Measurements +float MAX78630::Active_Power(char Phase) { // Declare Variable float _Result = 0; - _Result = _Register_Pointer_Read(IRMS_MAX); // Measure Phase R + if (Phase == 'R') _Result = _Register_Pointer_Read(WATT_A); // Measure Phase R + if (Phase == 'S') _Result = _Register_Pointer_Read(WATT_B); // Measure Phase S + if (Phase == 'T') _Result = _Register_Pointer_Read(WATT_C); // Measure Phase T + if (Phase == 'A') _Result = _Register_Pointer_Read(WATT_T); // Measure Phase Average // End Function - return(_Result * _IScale); + return(_Result * _IScale * _VScale); + +} +float MAX78630::ReActive_Power(char Phase) { + // Declare Variable + float _Result = 0; + + if (Phase == 'R') _Result = _Register_Pointer_Read(VAR_A); // Measure Phase R + if (Phase == 'S') _Result = _Register_Pointer_Read(VAR_B); // Measure Phase S + if (Phase == 'T') _Result = _Register_Pointer_Read(VAR_C); // Measure Phase T + if (Phase == 'A') _Result = _Register_Pointer_Read(VAR_T); // Measure Phase Average + + // End Function + return(_Result * _IScale * _VScale); + } +float MAX78630::Apparent_Power(char Phase) { -/** - * @brief Read IC Temperature - * @version 01.00.00 - * @return float IC Temperature in Celcius - */ -float MAX78630::IC_Temperature(void) { + // Declare Variable + float _Result = 0; + + if (Phase == 'R') _Result = _Register_Pointer_Read(VA_A); // Measure Phase R + if (Phase == 'S') _Result = _Register_Pointer_Read(VA_B); // Measure Phase S + if (Phase == 'T') _Result = _Register_Pointer_Read(VA_C); // Measure Phase T + if (Phase == 'A') _Result = _Register_Pointer_Read(VA_T); // Measure Phase Average + + // End Function + return(_Result * _IScale * _VScale); + +} +float MAX78630::Fundamental_Power(char Phase) { // Declare Variable float _Result = 0; - // Get Data - _Result = _Register_Pointer_Read(TEMPC); + if (Phase == 'R') _Result = _Register_Pointer_Read(PFUND_A); // Measure Phase R + if (Phase == 'S') _Result = _Register_Pointer_Read(PFUND_B); // Measure Phase S + if (Phase == 'T') _Result = _Register_Pointer_Read(PFUND_C); // Measure Phase T + + // End Function + return(_Result * _IScale * _VScale); + +} +float MAX78630::Harmonic_Power(char Phase) { + + // Declare Variable + float _Result = 0; + if (Phase == 'R') _Result = _Register_Pointer_Read(PHARM_A); // Measure Phase R + if (Phase == 'S') _Result = _Register_Pointer_Read(PHARM_B); // Measure Phase S + if (Phase == 'T') _Result = _Register_Pointer_Read(PHARM_C); // Measure Phase T + + // End Function + return(_Result * _IScale * _VScale); + +} +float MAX78630::Power_Factor(char Phase) { + + // Declare Variable + float _Result = 0; + + if (Phase == 'R') _Result = _Register_Pointer_Read(PFA); // Measure Phase R + if (Phase == 'S') _Result = _Register_Pointer_Read(PFB); // Measure Phase S + if (Phase == 'T') _Result = _Register_Pointer_Read(PFC); // Measure Phase T + if (Phase == 'A') _Result = _Register_Pointer_Read(PF_T); // Measure Phase Average + // End Function return(_Result); } -float MAX78630::Phase_Compensation(char Phase) { +// Temperature Measurements +float MAX78630::IC_Temperature(void) { // Declare Variable float _Result = 0; - if (Phase == 'R') _Result = _Register_Pointer_Read(PHASECOMP1); // Measure Phase R - if (Phase == 'S') _Result = _Register_Pointer_Read(PHASECOMP2); // Measure Phase S - if (Phase == 'T') _Result = _Register_Pointer_Read(PHASECOMP3); // Measure Phase T - + // Get Data + _Result = _Register_Pointer_Read(TEMPC); + // End Function return(_Result); } +// Frequency Measurements +float MAX78630::Frequency(void) { + // Declare Variable + float _Result = 0; + // Get Data + _Result = _Register_Pointer_Read(FREQ); + // End Function + return(_Result); + +} @@ -535,74 +634,25 @@ float MAX78630::Phase_Compensation(char Phase) { -bool MAX78630::Set_VScale(uint32_t _VScale) { - // Header (0xAA) - // Total Sended Byte (0x0A) - // Pointer Selection Command (0xA3) - // Parameter 1 (0x44) - // Parameter 2 (0x01) - // Small Write Command (0xD3) - // Parameter 1 (0x) - // Parameter 2 (0x) - // Parameter 3 (0x) - // CheckSum (chk) - // Convert Parameters - char _Parameter1 = _VScale>>16; - char _Parameter2 = _VScale>>8; - char _Parameter3 = _VScale; - - // Clear Buffer - //ClearBuffer(); - - // Calculate CheckSum - uint8_t ChkS = 0x100 - ((0xAA + 0x0A + 0xA3 + 0x44 + 0x01 + 0xD3 + _Parameter1 + _Parameter2 + _Parameter3) % 256); // Calculate checksum - // Clear Serial Buffer - _Clear_Buffer(); - // Send Command - Energy_Serial.write(0xAA); - Energy_Serial.write(0x0A); - Energy_Serial.write(0xA3); - Energy_Serial.write(0x44); - Energy_Serial.write(0x01); - Energy_Serial.write(0xD3); - Energy_Serial.write(_Parameter3); - Energy_Serial.write(_Parameter2); - Energy_Serial.write(_Parameter1); - Energy_Serial.write(ChkS); - // Command Delay - delay(20); - // End Function - return(true); -} -bool MAX78630::Set_IScale(uint32_t _IScale) { - // Header (0xAA) - // Total Sended Byte (0x0A) - // Pointer Selection Command (0xA3) - // Parameter 1 (0x44) - // Parameter 2 (0x01) - // Small Write Command (0xD3) - // Parameter 1 (0x) - // Parameter 2 (0x) - // Parameter 3 (0x) - // CheckSum (chk) +bool MAX78630::_Register_Pointer_Set(Register _Command, uint32_t _Data) { - // Convert Parameters - char _Parameter1 = _IScale>>16; - char _Parameter2 = _IScale>>8; - char _Parameter3 = _IScale; - // Clear Buffer - //ClearBuffer(); - + _Clear_Buffer(); + + // Convert Parameters + char _Parameter1 = _Data; + char _Parameter2 = _Data>>8; + char _Parameter3 = _Data>>16; + // Calculate CheckSum - uint8_t ChkS = 0x100 - ((0xAA + 0x0A + 0xA3 + 0x41 + 0x01 + 0xD3 + _Parameter1 + _Parameter2 + _Parameter3) % 256); // Calculate checksum + uint8_t ChkS = 0x100 - ((0xAA + 0x0A + 0xA3 + _Command.Low_Address + _Command.High_Address + 0xD3 + _Parameter1 + _Parameter2 + _Parameter3) % 256); // Calculate checksum // Clear Serial Buffer _Clear_Buffer(); @@ -611,12 +661,12 @@ bool MAX78630::Set_IScale(uint32_t _IScale) { Energy_Serial.write(0xAA); Energy_Serial.write(0x0A); Energy_Serial.write(0xA3); - Energy_Serial.write(0x41); - Energy_Serial.write(0x01); + Energy_Serial.write(_Command.Low_Address); + Energy_Serial.write(_Command.High_Address); Energy_Serial.write(0xD3); - Energy_Serial.write(_Parameter3); - Energy_Serial.write(_Parameter2); Energy_Serial.write(_Parameter1); + Energy_Serial.write(_Parameter2); + Energy_Serial.write(_Parameter3); Energy_Serial.write(ChkS); // Command Delay @@ -624,13 +674,8 @@ bool MAX78630::Set_IScale(uint32_t _IScale) { // End Function return(true); -} -/** - * @brief Register pointer read function - * @param _Command Command type - * @return double Register data - */ +} double MAX78630::_Register_Pointer_Read(Register _Command) { /* @@ -726,17 +771,12 @@ double MAX78630::_Register_Pointer_Read(Register _Command) { return(_Data_SUM); } - -/** - * @brief Clear serial buffer - */ void MAX78630::_Clear_Buffer(void) { // Clear UART Buffer Energy_Serial.flush(); while(Energy_Serial.available() > 0) Energy_Serial.read(); delay(5); } - void MAX78630::VT100_Base(void) { VT100.setTextColor(VT_WHITE); @@ -821,15 +861,6 @@ void MAX78630::VT100_Base(void) { */ } - - - - - - - - - // Define Library Class MAX78630 Energy_Analayser; diff --git a/src/MAX78630.h b/src/MAX78630.h index dc50068..889e183 100644 --- a/src/MAX78630.h +++ b/src/MAX78630.h @@ -40,6 +40,10 @@ class MAX78630 { bool Begin(void); + bool Set_VScale(uint32_t _VScale); + bool Set_IScale(uint32_t _VScale); + bool Set_Harmonic(uint32_t _Harmonic); + float IC_Temperature(void); float Firmware(void); @@ -48,7 +52,6 @@ class MAX78630 { float Voltage_Instantaneous(char Phase); float Voltage_Fundamental(char Phase); float Voltage_Harmonic(char Phase); - float Voltage_V_Target(void); float Voltage_RMS_Min(void); float Voltage_RMS_Max(void); float Voltage_SAG_Limit(void); @@ -56,22 +59,32 @@ class MAX78630 { // Current Measurements float Current_RMS(char Phase); float Current_Instantaneous(char Phase); + float Current_Peak(char Phase); float Current_Fundamental(char Phase); float Current_Harmonic(char Phase); - float Current_I_Target(void); float Current_RMS_Max(void); - float Phase_Compensation(char Phase); + float Active_Power(char Phase); + float ReActive_Power(char Phase); + float Apparent_Power(char Phase); + float Fundamental_Power(char Phase); + float Harmonic_Power(char Phase); + float Power_Factor(char Phase); + + float Frequency(void); + + + + - bool Set_VScale(uint32_t _VScale); - bool Set_IScale(uint32_t _VScale); void VT100_Base(void); private: - double _Register_Pointer_Read(Register _Command); - void _Clear_Buffer(void); + double _Register_Pointer_Read(Register _Command); + void _Clear_Buffer(void); + bool _Register_Pointer_Set(Register _Command, uint32_t _Data); uint32_t _VScale = 0; uint32_t _IScale = 0;