Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

04.02.00 - Current and other set functions updated. #17

Merged
merged 1 commit into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions examples/test/test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@

void setup() {

// Start Terminal
Serial.begin(115200);

// Start Analayser
Energy_Analayser.Begin();

}

void loop() {

Energy_Analayser.Control_Limits();
Serial.print("RMS Voltage : "); Serial.print(Energy_Analayser.Voltage_RMS('R')); Serial.println(" V");
Serial.print("RMS Current : "); Serial.print(Energy_Analayser.Current_RMS('R'), 3); Serial.println(" A");
Serial.print("Energy : "); Serial.print(Energy_Analayser.Active_Energy_Recieved('R'), 0); Serial.println(" Wh");
Serial.print("Reactive Energy: "); Serial.print(Energy_Analayser.ReActive_Energy_Recieved('R'), 0); Serial.println(" VARh");



Serial.print("Active Power : "); Serial.print(Energy_Analayser.Active_Power('R')); Serial.println(" W");
Serial.print("ReActive Power : "); Serial.print(Energy_Analayser.ReActive_Power('R')); Serial.println(" VAR");
Serial.print("Apparent Power : "); Serial.print(Energy_Analayser.Apparent_Power('R')); Serial.println(" VA");

Serial.print("Power Factor : "); Serial.print(Energy_Analayser.Power_Factor('R')); Serial.println(" ");

Serial.print("Frequency : "); Serial.print(Energy_Analayser.Frequency()); Serial.println(" Hz");

Serial.print(Energy_Analayser.Voltage_RMS('R'), 3);

delay(1000);
Serial.print("IC Temperature : "); Serial.print(Energy_Analayser.IC_Temperature()); Serial.println(" C");
Serial.println("------------------------------------------");

delay(60000);
}
26 changes: 13 additions & 13 deletions src/MAX78630.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ bool MAX78630::Begin(void) {
bool _Config_Reg_Bits[8] = {false, false, false, false, false, false, false, false};

// Set Configuration
_Config_Reg_Bits[7] = false; // 1= reset all energy accumulators. This bit automatically clears to zero when the reset completes.
_Config_Reg_Bits[6] = false; // 1= reset the minima and maxima registers for all monitored variables. This bit automatically clears to zero when the reset completes.
_Config_Reg_Bits[7] = true; // 1= reset all energy accumulators. This bit automatically clears to zero when the reset completes.
_Config_Reg_Bits[6] = true; // 1= reset the minima and maxima registers for all monitored variables. This bit automatically clears to zero when the reset completes.
_Config_Reg_Bits[5] = true; // Line Lock 1= lock to line cycle; 0= independent
_Config_Reg_Bits[4] = true; // Temperature Compensation. Should be set to “1” for proper operation.

Expand Down Expand Up @@ -123,8 +123,8 @@ bool MAX78630::Begin(void) {
Set_Limit(2, _Temp_Min);
Set_Limit(3, _Fq_Max);
Set_Limit(4, _Fq_Min);
Set_Limit(5, (_V_RMS_Max));
Set_Limit(6, (_V_RMS_Min));
Set_Limit(5, _V_RMS_Max);
Set_Limit(6, _V_RMS_Min);
Set_Limit(7, _C_Max);
Set_Limit(8, _PF_Min);
Set_Limit(9, _V_Max_Imb);
Expand Down Expand Up @@ -807,8 +807,8 @@ float MAX78630::Current_RMS(char Phase) {
float _Result = 0;

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 == 'S') _Result = _Register_Pointer_Read(IB_RMS); // Measure Phase S
if (Phase == 'T') _Result = _Register_Pointer_Read(IC_RMS); // Measure Phase T
if (Phase == 'A') _Result = _Register_Pointer_Read(IT_RMS); // Measure Phase Average

// End Function
Expand Down Expand Up @@ -1434,6 +1434,9 @@ double MAX78630::_Register_Pointer_Read(Register _Command) {
// Clear Serial Buffer
_Clear_Buffer();

// Command Send Delay
delay(5);

// Calculate CheckSum
uint8_t _Request_CheckSum = 0x100 - ((0xAA + 0x07 + 0xA3 + _Command.Low_Address + _Command.High_Address + 0xE3) % 256);

Expand Down Expand Up @@ -1483,18 +1486,15 @@ double MAX78630::_Register_Pointer_Read(Register _Command) {

// Calculate Response
if (_Command.Data_Type == 0) {


// Handle Response (int)
_Data_SUM = _Data_RAW;

} else {

// Handle Bits
for (uint8_t i = 0; i < 23; i++) {

if (bitRead(_Data_RAW, i) == true) _Data_SUM += pow(2, (i - _Command.Data_Type));

}
if (bitRead(_Data_RAW, 23) == true) _Data_SUM += -1 * pow(2, (23 - _Command.Data_Type));
for (uint8_t i = 0; i < 23; i++) if (bitRead(_Data_RAW, i) == true) _Data_SUM += pow(2, (i - _Command.Data_Type));
if (bitRead(_Data_RAW, 23) == true) _Data_SUM += (-1 * pow(2, (23 - _Command.Data_Type)));

}

Expand Down
2 changes: 1 addition & 1 deletion src/MAX78630_Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define Energy_Serial_Baud 38400

// Define Version
#define Version "04.00.11"
#define MAX78630_Version "04.00.11"

// Define Default Read Count
#define Read_Count 3
Expand Down