Current transducer. For the electronic measurement of currents: DC, AC, pulsed..., with galvanic separation between the primary circuit and the secondary circuit.
LEM_HAIS.h
- Committer:
- mcm
- Date:
- 2017-10-10
- Revision:
- 3:6bc9b8543f13
- Parent:
- 2:c865023c4b20
- Child:
- 4:5002bb8e907b
File content as of revision 3:6bc9b8543f13:
/** * @brief LEM_HAIS.h * @details Current transducer. For the electronic measurement of currents: * DC, AC, pulsed..., with galvanic separation between the primary * circuit and the secondary circuit. * Header file. * * * @return NA * * @author Manuel Caballero * @date 19/September/2017 * @version 19/September/2017 The ORIGIN * @pre NaN. * @warning NaN * @pre This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ). */ #ifndef LEM_HAIS_H #define LEM_HAIS_H #include "mbed.h" /** Example: #include "mbed.h" #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 ); Serial pc ( USBTX, USBRX ); Ticker newReading; DigitalOut myled1 ( LED1 ); DigitalOut myled2 ( LED2 ); AnalogIn myVref ( p19 ); AnalogIn myINPUT ( p20 ); LEM_HAIS::Vector_LEM_HAIS_voltage_t myVoltages; float myVoltageOffset = 0; float myVref_measured = 0; void readDATA ( void ) { LEM_HAIS::Vector_LEM_HAIS_current_t myCurrent; myled2 = 1; myVoltages = myCurrentTransducer.LEM_HAIS_GetVoltage (); myCurrent = myCurrentTransducer.LEM_HAIS_CalculateCurrent ( myVoltages, myVref_measured, LEM_HAIS::FILTER_DISABLED ); pc.printf( "Vout: %0.5f V IP: %0.5f A\r\n", myVoltages.OUTPUT_Voltage[500], myCurrent.Current ); myled2 = 0; } int main() { uint32_t i = 0; pc.baud ( 115200 ); // [ OPTIONAL ] CALIBRATION. It calculates the offset to calibrate the future measurements. // It reads the Vref from the device. myled1 = 1; for ( i = 0; i < 10; i++ ) { myVref_measured += myVref.read(); wait ( 0.25 ); } myVref_measured /= 10.0; myVref_measured *= ADC_VREF; // It reads OUPUT from the device. NOTE: This MUST be done at 0A current!!! myVoltageOffset = myCurrentTransducer.LEM_HAIS_SetAutoOffset ( myVref_measured ); myled1 = 0; pc.printf( "Vref: %0.5f V Voff: %0.5f V\r\n", myVref_measured, myVoltageOffset ); // CALIBRATION ends here newReading.attach( &readDATA, 1.5 ); // the address of the function to be attached ( readDATA ) and the interval ( 0.5s ) // Let the callbacks take care of everything while(1) { sleep(); } } */ /*! Library for the LEM_HAIS Current transducer. */ class LEM_HAIS { public: #define CALIBRATION_AVERAGE 10 // Change it if you wish to calculate the offset with less measurements #define SAMPLE_DATA 1000 // 1 sample every 1ms -> 1000 total samples in total ( = 1s ) typedef enum { FILTER_ENABLED = 1, FILTER_DISABLED = 0 } LEM_HAIS_filter_status_t; #ifndef VECTOR_STRUCT_H #define VECTOR_STRUCT_H typedef struct { float Current; } Vector_LEM_HAIS_current_t; typedef struct { float OUTPUT_Voltage[SAMPLE_DATA]; } Vector_LEM_HAIS_voltage_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 ); /** Delete LEM_HAIS object. */ ~LEM_HAIS(); /** It gets the voltage. */ Vector_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 ); /** 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 ); private: AnalogIn _OUTPUT; float _LEM_HAIS_V_OFFSET; float _VOLTAGE_DIVIDER; float _ADC_VREF; float _LEM_HAIS_IPM; }; #endif