Skip to content

Commit

Permalink
Merge pull request #10 from akkoyun/04.00.10
Browse files Browse the repository at this point in the history
04.00.10 - Bucket function updated. Get and set functions combined.
  • Loading branch information
akkoyun authored Feb 11, 2022
2 parents ba693e8 + 58d762b commit 2ce4e46
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 57 deletions.
20 changes: 15 additions & 5 deletions src/Config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#ifndef __MAX78630_CONFIG__
#define __MAX78630_CONFIG__

// Define Arduino Library
#ifndef __Arduino__
#include <Arduino.h>
#endif

// Define Registers
#ifndef __MAX78630_DEFINATION__
#include <Defination.h>
#endif

// Define Serial Port
#define Energy_Serial Serial2
#define Energy_Serial_Baud 38400
Expand All @@ -15,11 +25,11 @@
// Limit Definations
#define _V_Scale 667
#define _C_Scale 7
#define _V_RMS_Min 220
#define _V_RMS_Max 250
#define _Fq_Min 48
#define _Fq_Max 51
#define _Temp_Min 20
#define _V_RMS_Min 192
#define _V_RMS_Max 253
#define _Fq_Min 47
#define _Fq_Max 52
#define _Temp_Min 10
#define _Temp_Max 40
#define _C_Max 5
#define _V_Max_Imb 0.06
Expand Down
1 change: 0 additions & 1 deletion src/Defination.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct Limits {
bool Frequency_Over_Limit;
};


// --------------------------------------------------------------------------------------------------------------------------
// Master Packets
// --------------------------------------------------------------------------------------------------------------------------
Expand Down
76 changes: 38 additions & 38 deletions src/MAX78630.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

// Register Address Definations
Register COMMAND {0x00, 0x00, 0, true}; // Selects modes, functions, or options
Register FW_VERSION {0x00, 0x03, 0, false}; // Hardware and firmware version
Register CONFIG {0x00, 0x06, 0, true}; // Selects input configuration

// Calibration Registers
Expand Down Expand Up @@ -117,7 +116,7 @@ bool MAX78630::Begin(void) {
IScale(_C_Scale);

// Bucket Set Command
Set_Bucket();
Bucket(true, _BUCKET_HIGH, _BUCKET_LOW);

// Set Limit Parameters
Set_Limit(1, _Temp_Max);
Expand Down Expand Up @@ -199,6 +198,21 @@ uint32_t MAX78630::Get_System_Stat(void) {
// End Function
return(_Result);

}
uint32_t MAX78630::Get_Firmware(void) {

// Define Objects
Register FW_VERSION {0x00, 0x03, 0, false}; // Hardware and firmware version

// Declare Variable
uint32_t _Result = 0;

// Decide Command
_Result = _Register_Pointer_Read(FW_VERSION);

// End Function
return(_Result);

}

// Set Scale Registers
Expand Down Expand Up @@ -301,54 +315,40 @@ uint8_t MAX78630::Harmonic(uint32_t _Harmonic) {
return(_Result);

}

// Bucket Functions
bool MAX78630::Set_Bucket(void) {
uint64_t MAX78630::Bucket(bool _Set, uint32_t _Bucket_H, uint32_t _Bucket_L) {

// Define Objects
Register BUCKET_LOW {0x01, 0xD1, 0, true}; // Energy Bucket Size – Low word
Register BUCKET_HIGH {0x01, 0xD4, 0, true}; // Energy Bucket Size – High word

// Declare Variable
bool _Result_LOW = false;
bool _Result_HIGH = false;

// Set Command
_Result_LOW = _Register_Pointer_Set(BUCKET_LOW, _BUCKET_LOW);
_Result_HIGH = _Register_Pointer_Set(BUCKET_HIGH, _BUCKET_HIGH);

// End Function
return(_Result_LOW & _Result_HIGH);

}
uint32_t MAX78630::Get_Bucket_LOW(void) {
// Control for Set
if (_Set == true) {

// Define Objects
Register BUCKET_LOW {0x01, 0xD1, 0, true}; // Energy Bucket Size – Low word
// Declare Variable
bool _Result_LOW = false;
bool _Result_HIGH = false;

// Declare Variable
uint32_t _Result = 0;
// Set Command
_Result_LOW = _Register_Pointer_Set(BUCKET_LOW, _Bucket_L);
_Result_HIGH = _Register_Pointer_Set(BUCKET_HIGH, _Bucket_H);

// Decide Command
_Result = _Register_Pointer_Read(BUCKET_LOW);

// End Function
return(_Result);
// Handle Response
if (_Result_LOW & _Result_HIGH) return(0xFF);

} else {

}
uint32_t MAX78630::Get_Bucket_HIGH(void) {
// Declare Variable
uint32_t _Result_LOW = 0x00;
uint32_t _Result_HIGH = 0x00;

// Define Objects
Register BUCKET_HIGH {0x01, 0xD4, 0, true}; // Energy Bucket Size – High word
// Decide Command
_Result_LOW = _Register_Pointer_Read(BUCKET_LOW);
_Result_HIGH = _Register_Pointer_Read(BUCKET_HIGH);

// Declare Variable
uint32_t _Result = 0;
// Combine Function
uint64_t _Result = (((uint32_t)_Result_HIGH << 24) & ((uint32_t)_Result_LOW));

// Decide Command
_Result = _Register_Pointer_Read(BUCKET_HIGH);

// End Function
return(_Result);
}

}

Expand Down
17 changes: 4 additions & 13 deletions src/MAX78630.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,11 @@
#ifndef __MAX78630__
#define __MAX78630__

// Define Arduino Library
#ifndef __Arduino__
#include <Arduino.h>
#endif

// Define Library Structures
#ifndef __MAX78630_CONFIG__
#include <Config.h>
#endif

// Define Registers
#ifndef __MAX78630_DEFINATION__
#include <Defination.h>
#endif

class MAX78630 {

public:
Expand All @@ -36,12 +26,14 @@ class MAX78630 {
bool Set_Baud(uint32_t _Baud);
uint32_t Get_Device_Address(void);
uint32_t Get_System_Stat(void);
uint32_t Get_Firmware(void);

// Scale Functions
uint16_t VScale(uint32_t _VScale);
uint16_t IScale(uint32_t _VScale);
uint8_t Harmonic(uint32_t _Harmonic);

uint64_t Bucket(bool _Set, uint32_t _Bucket_L, uint32_t _Bucket_H);

// Bucket Functions
bool Set_Bucket(void);
uint32_t Get_Bucket_LOW(void);
Expand Down Expand Up @@ -72,7 +64,6 @@ class MAX78630 {

// Temperature Functions
float IC_Temperature(void);
float Firmware(void);

// Voltage Measurements
float Voltage_RMS(char Phase);
Expand Down Expand Up @@ -142,4 +133,4 @@ class MAX78630 {

extern MAX78630 Energy_Analayser;

#endif /* defined(__MAX78630__) */
#endif /* defined(__MAX78630__) */

0 comments on commit 2ce4e46

Please # to comment.