Current transducer. For the electronic measurement of currents: DC, AC, pulsed..., with galvanic separation between the primary circuit and the secondary circuit.

Revision:
4:5002bb8e907b
Parent:
3:6bc9b8543f13
--- 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;
 }