Diff: LEM_HAIS.h
- Revision:
- 4:5002bb8e907b
- Parent:
- 3:6bc9b8543f13
diff -r 6bc9b8543f13 -r 5002bb8e907b LEM_HAIS.h
--- a/LEM_HAIS.h Tue Oct 10 13:54:12 2017 +0000
+++ b/LEM_HAIS.h Tue Oct 10 14:56:04 2017 +0000
@@ -28,11 +28,7 @@
#include "LEM_HAIS.h"
-#define VOLTAGE_DIVIDER 2.0
-#define ADC_VREF 3.3
-#define LEM_HAIS_IPM 150.0
-
-LEM_HAIS myCurrentTransducer ( p20, LEM_HAIS_IPM, VOLTAGE_DIVIDER, ADC_VREF );
+LEM_HAIS myCurrentTransducer ( p20 );
Serial pc ( USBTX, USBRX );
Ticker newReading;
@@ -42,22 +38,20 @@
AnalogIn myINPUT ( p20 );
-
-LEM_HAIS::Vector_LEM_HAIS_voltage_t myVoltages;
-float myVoltageOffset = 0;
-float myVref_measured = 0;
+LEM_HAIS::LEM_HAIS_parameters_t myParameters;
+LEM_HAIS::LEM_HAIS_voltage_t myVoltages;
void readDATA ( void )
{
- LEM_HAIS::Vector_LEM_HAIS_current_t myCurrent;
+ LEM_HAIS::LEM_HAIS_current_t myCurrent;
myled2 = 1;
myVoltages = myCurrentTransducer.LEM_HAIS_GetVoltage ();
- myCurrent = myCurrentTransducer.LEM_HAIS_CalculateCurrent ( myVoltages, myVref_measured, LEM_HAIS::FILTER_DISABLED );
+ myCurrent = myCurrentTransducer.LEM_HAIS_CalculateCurrent ( myVoltages, myParameters, LEM_HAIS::FILTER_DISABLED );
- pc.printf( "Vout: %0.5f V IP: %0.5f A\r\n", myVoltages.OUTPUT_Voltage[500], myCurrent.Current );
+ pc.printf( "IP: %0.5f A\r\n", myCurrent.Current );
myled2 = 0;
}
@@ -67,6 +61,12 @@
{
uint32_t i = 0;
+ // CONFIGURATION. The parameters of the system
+ // myParameters.lem_hais_reference_voltage = 2.5; // ( uncomment ) Mandatory if calibration is NOT used!
+ myParameters.voltage_divider = 2.0; // Resistor ( both with the same value ) divider at the Sensor ( LEM-HAIS ) Vout
+ myParameters.adc_reference_voltage = 3.3; // ADC microcontroller ~ 3.3V
+ myParameters.lem_hais_ipm = 150.0; // HAIS 150-P
+
pc.baud ( 115200 );
@@ -74,22 +74,22 @@
// It reads the Vref from the device.
myled1 = 1;
for ( i = 0; i < 10; i++ ) {
- myVref_measured += myVref.read();
+ myParameters.lem_hais_reference_voltage += myVref.read();
wait ( 0.25 );
}
- myVref_measured /= 10.0;
- myVref_measured *= ADC_VREF;
+ myParameters.lem_hais_reference_voltage /= 10.0;
+ myParameters.lem_hais_reference_voltage *= myParameters.adc_reference_voltage;
// It reads OUPUT from the device. NOTE: This MUST be done at 0A current!!!
- myVoltageOffset = myCurrentTransducer.LEM_HAIS_SetAutoOffset ( myVref_measured );
+ myParameters.lem_hais_offset_voltage = myCurrentTransducer.LEM_HAIS_SetAutoOffset ( myParameters );
myled1 = 0;
- pc.printf( "Vref: %0.5f V Voff: %0.5f V\r\n", myVref_measured, myVoltageOffset );
+ pc.printf( "Vref: %0.5f V Voff: %0.5f V\r\n", myParameters.lem_hais_reference_voltage, myParameters.lem_hais_offset_voltage );
// CALIBRATION ends here
- newReading.attach( &readDATA, 1.5 ); // the address of the function to be attached ( readDATA ) and the interval ( 0.5s )
+ newReading.attach( &readDATA, 1.5 ); // the address of the function to be attached ( readDATA ) and the interval ( 1.5s )
// Let the callbacks take care of everything
@@ -118,23 +118,33 @@
-#ifndef VECTOR_STRUCT_H
-#define VECTOR_STRUCT_H
+#ifndef LEM_HAIS_DATA_STRUCT_H
+#define LEM_HAIS_DATA_STRUCT_H
typedef struct {
float Current;
- } Vector_LEM_HAIS_current_t;
+ } LEM_HAIS_current_t;
typedef struct {
float OUTPUT_Voltage[SAMPLE_DATA];
- } Vector_LEM_HAIS_voltage_t;
+ } LEM_HAIS_voltage_t;
+
+ typedef struct {
+ float lem_hais_offset_voltage;
+ float lem_hais_reference_voltage;
+ float voltage_divider;
+ float adc_reference_voltage;
+ float lem_hais_ipm;
+ } LEM_HAIS_parameters_t;
#endif
+
+
/** Create an LEM_HAIS object connected to the specified pins.
*
* @param OUTPUT Vout from the device
*/
- LEM_HAIS ( PinName OUTPUT, float myIPM, float myVoltageDivider = 1.0, float myADC_Vref = 3.3 );
+ LEM_HAIS ( PinName OUTPUT );
/** Delete LEM_HAIS object.
*/
@@ -142,25 +152,20 @@
/** It gets the voltage.
*/
- Vector_LEM_HAIS_voltage_t LEM_HAIS_GetVoltage ( void );
+ LEM_HAIS_voltage_t LEM_HAIS_GetVoltage ( void );
/** It calculates the offset automatically ( at 0A current ).
*/
- float LEM_HAIS_SetAutoOffset ( float Device_Vref = 2.5 );
+ float LEM_HAIS_SetAutoOffset ( LEM_HAIS_parameters_t myParameters );
/** It calculates the current.
*/
- Vector_LEM_HAIS_current_t LEM_HAIS_CalculateCurrent ( Vector_LEM_HAIS_voltage_t myVoltages, float Device_Vref = 2.5, LEM_HAIS_filter_status_t myFilter = FILTER_DISABLED );
+ LEM_HAIS_current_t LEM_HAIS_CalculateCurrent ( LEM_HAIS_voltage_t myVoltages, LEM_HAIS_parameters_t myParameters, LEM_HAIS_filter_status_t myFilter = FILTER_DISABLED );
private:
AnalogIn _OUTPUT;
-
- float _LEM_HAIS_V_OFFSET;
- float _VOLTAGE_DIVIDER;
- float _ADC_VREF;
- float _LEM_HAIS_IPM;
};
#endif