Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:5002bb8e907b, committed 2017-10-10
- Comitter:
- mcm
- Date:
- Tue Oct 10 14:56:04 2017 +0000
- Parent:
- 3:6bc9b8543f13
- Commit message:
- A structure with several parameters were declared, these parameters will define the system. ; ; NOTE: All the test are performed using RMS theory. Sampling at 1ms for 1 second ( = 1000 samples ).; ; The library was tested and it works as expected.
Changed in this revision
| LEM_HAIS.cpp | Show annotated file Show diff for this revision Revisions of this file |
| LEM_HAIS.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/LEM_HAIS.cpp Tue Oct 10 13:54:12 2017 +0000
+++ b/LEM_HAIS.cpp Tue Oct 10 14:56:04 2017 +0000
@@ -18,17 +18,11 @@
#include "LEM_HAIS.h"
-
-LEM_HAIS::LEM_HAIS ( PinName OUTPUT, float myVoltageDivider, float myADC_Vref, float myIPM )
+LEM_HAIS::LEM_HAIS ( PinName OUTPUT )
: _OUTPUT ( OUTPUT )
{
- _LEM_HAIS_V_OFFSET = 0.0;
- _VOLTAGE_DIVIDER = myVoltageDivider;
- _ADC_VREF = myADC_Vref;
- _LEM_HAIS_IPM = myIPM;
}
-
LEM_HAIS::~LEM_HAIS()
{
}
@@ -52,14 +46,15 @@
* @date 19/September/2017
* @version 27/September/2017 RMS calculations included.
* 19/September/2017 The ORIGIN
- * @pre NaN.
+ * @pre If SAMPLE_DATA = 1000, this funcion will last for 1000 * 1ms
+ * = 1 second.
* @warning NaN.
*/
-LEM_HAIS::Vector_LEM_HAIS_voltage_t LEM_HAIS::LEM_HAIS_GetVoltage ( void )
+LEM_HAIS::LEM_HAIS_voltage_t LEM_HAIS::LEM_HAIS_GetVoltage ( void )
{
uint32_t i = 0;
- Vector_LEM_HAIS_voltage_t myAuxVoltage;
+ LEM_HAIS_voltage_t myAuxVoltage;
for ( i = 0; i < SAMPLE_DATA; i++ )
@@ -76,12 +71,13 @@
/**
- * @brief LEM_HAIS_CalculateCurrent ( Vector_LEM_HAIS_voltage_t , float , LEM_HAIS_filter_status_t )
+ * @brief LEM_HAIS_CalculateCurrent ( Vector_LEM_HAIS_voltage_t , LEM_HAIS_parameters_t , LEM_HAIS_filter_status_t )
*
* @details It calculates the actual current.
*
* @param[in] myVoltages: Both voltages, OUTPUT and Vref voltages.
- * @param[in] Device_Vref: Device voltage reference.
+ * @param[in] myParameters: Parameters are necessary to calculate the
+ * result.
* @param[in] myFilter: If a low pass filter is enabled/disabled.
*
* @param[out] NaN.
@@ -92,13 +88,15 @@
*
* @author Manuel Caballero
* @date 19/September/2017
- * @version 19/September/2017 The ORIGIN
+ * @version 10/October/2017 New parameters are sent to this function to
+ * process the data in the right way.
+ * 19/September/2017 The ORIGIN
* @pre LEM_HAIS_GetVoltage function MUST be called first.
* @warning NaN.
*/
-LEM_HAIS::Vector_LEM_HAIS_current_t LEM_HAIS::LEM_HAIS_CalculateCurrent ( Vector_LEM_HAIS_voltage_t myVoltages, float Device_Vref, LEM_HAIS_filter_status_t myFilter )
+LEM_HAIS::LEM_HAIS_current_t LEM_HAIS::LEM_HAIS_CalculateCurrent ( LEM_HAIS_voltage_t myVoltages, LEM_HAIS_parameters_t myParameters, LEM_HAIS_filter_status_t myFilter )
{
- Vector_LEM_HAIS_current_t myAuxCurrent;
+ LEM_HAIS_current_t myAuxCurrent;
float myAuxSQI = 0;
float myAuxVol = 0;
@@ -110,8 +108,8 @@
// Check if we want to use a low pass filter
if ( myFilter == FILTER_ENABLED )
- {
- myI_Previousfiltered = _VOLTAGE_DIVIDER * _ADC_VREF * myVoltages.OUTPUT_Voltage[0];
+ {
+ myI_Previousfiltered = myParameters.voltage_divider * myParameters.adc_reference_voltage * myVoltages.OUTPUT_Voltage[0];
i = 1;
}
else
@@ -120,8 +118,8 @@
// Calculate the RMS current
for ( ; i < SAMPLE_DATA; i++ )
- {
- myAuxVol = _VOLTAGE_DIVIDER * _ADC_VREF * myVoltages.OUTPUT_Voltage[i];
+ {
+ myAuxVol = myParameters.voltage_divider * myParameters.adc_reference_voltage * myVoltages.OUTPUT_Voltage[i];
if ( myFilter == FILTER_ENABLED )
{
@@ -129,10 +127,10 @@
myI_Previousfiltered = myI_filtered;
- myAuxSQI = ( 8.0 / 5.0 ) * ( ( myI_filtered + _LEM_HAIS_V_OFFSET ) - Device_Vref ) * _LEM_HAIS_IPM;
+ myAuxSQI = ( 8.0 / 5.0 ) * ( ( myI_filtered + myParameters.lem_hais_offset_voltage ) - myParameters.lem_hais_reference_voltage ) * myParameters.lem_hais_ipm;
}
- else
- myAuxSQI = ( 8.0 / 5.0 ) * ( ( myAuxVol + _LEM_HAIS_V_OFFSET ) - Device_Vref ) * _LEM_HAIS_IPM;
+ else
+ myAuxSQI = ( 8.0 / 5.0 ) * ( ( myAuxVol + myParameters.lem_hais_offset_voltage ) - myParameters.lem_hais_reference_voltage ) * myParameters.lem_hais_ipm;
myAuxSQI *= myAuxSQI;
@@ -159,11 +157,13 @@
/**
- * @brief LEM_HAIS_SetAutoOffset ( float , float )
+ * @brief LEM_HAIS_SetAutoOffset ( LEM_HAIS_parameters_t )
*
* @details It calculates the offset automatically ( at 0A current ).
*
- * @param[in] ADC_Vref: Voltage reference for the ADC.
+ * @param[in] myParameters: voltage_divider, adc_reference_voltage. These
+ * parameters are necessary to calculate the
+ * result.
*
* @param[out] NaN.
*
@@ -173,12 +173,15 @@
*
* @author Manuel Caballero
* @date 19/September/2017
- * @version 19/September/2017 The ORIGIN
- * @pre NaN.
+ * @version 10/October/2017 New parameters are sent to this function to
+ * process the data in the right way.
+ * 19/September/2017 The ORIGIN
+ * @pre If CALIBRATION_AVERAGE = 10, this function will last for
+ * 10 * 0.25 = 2.5 seconds.
* @warning This test has to be perfomed at 0A ( no current through
* the sensor at all ).
*/
-float LEM_HAIS::LEM_HAIS_SetAutoOffset ( float Device_Vref )
+float LEM_HAIS::LEM_HAIS_SetAutoOffset ( LEM_HAIS_parameters_t myParameters )
{
uint32_t i = 0;
float myVoltage = 0;
@@ -194,11 +197,9 @@
// Store the offset
- _LEM_HAIS_V_OFFSET = Device_Vref - ( _VOLTAGE_DIVIDER * myVoltage * _ADC_VREF );
-
- //_LEM_HAIS_V_OFFSET = Device_Vref - ( 2.0 * myVoltage * 3.3 );
-
+ myParameters.lem_hais_offset_voltage = myParameters.lem_hais_reference_voltage - ( myParameters.voltage_divider * myVoltage * myParameters.adc_reference_voltage );
- return _LEM_HAIS_V_OFFSET;
+
+ return myParameters.lem_hais_offset_voltage;
}
--- 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