TOP Contributors

  1. MIKROE (2751 codes)
  2. Alcides Ramos (372 codes)
  3. Shawon Shahryiar (307 codes)
  4. jm_palomino (118 codes)
  5. Bugz Bensce (90 codes)
  6. S P (73 codes)
  7. dany (71 codes)
  8. MikroBUS.NET Team (35 codes)
  9. NART SCHINACKOW (34 codes)
  10. Armstrong Subero (27 codes)

Most Downloaded

  1. Timer Calculator (139059 times)
  2. FAT32 Library (71589 times)
  3. Network Ethernet Library (56988 times)
  4. USB Device Library (47330 times)
  5. Network WiFi Library (43006 times)
  6. FT800 Library (42297 times)
  7. GSM click (29777 times)
  8. mikroSDK (27874 times)
  9. PID Library (26858 times)
  10. microSD click (26129 times)
Libstock prefers package manager

Package Manager

We strongly encourage users to use Package manager for sharing their code on Libstock website, because it boosts your efficiency and leaves the end user with no room for error. [more info]

< Back
mikroSDK Library

PWR Meter click

Rating:

5

Author: MIKROE

Last Updated: 2018-09-27

Package Version: 1.0.0.0

mikroSDK Library: 1.0.0.0

Category: Measurements

Downloaded: 4988 times

Not followed.

License: MIT license  

PWR Meter click is a power measurement Click board, capable of measuring voltage and current through the load, connected to either AC or DC power source.

No Abuse Reported

Do you want to subscribe in order to receive notifications regarding "PWR Meter click" changes.

Do you want to unsubscribe in order to stop receiving notifications regarding "PWR Meter click" changes.

Do you want to report abuse regarding "PWR Meter click".

  • mikroSDK Library 2.0.0.0
  • Comments (0)
DOWNLOAD LINK RELATED COMPILER CONTAINS
mikroBasic PRO for ARM
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroBasic PRO for AVR
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroBasic PRO for dsPIC30/33 & PIC24
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroBasic PRO for FT90x
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroBasic PRO for PIC
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroBasic PRO for PIC32
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroC PRO for ARM
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroC PRO for AVR
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroC PRO for dsPIC30/33 & PIC24
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroC PRO for FT90x
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroC PRO for PIC
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroC PRO for PIC32
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroPascal PRO for ARM
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroPascal PRO for AVR
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroPascal PRO for dsPIC30/33 & PIC24
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroPascal PRO for FT90x
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroPascal PRO for PIC
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc
mikroPascal PRO for PIC32
  • lib
  • src
  • exa
  • hlp
  • hex
  • sch
  • pcb
  • doc

mikroSDK Library Blog

PWR Meter click

PWR Meter click

Native view of the PWR Meter click board.

View full image
PWR Meter click

PWR Meter click

Front and back view of the PWR Meter click board.

View full image

Library Description

Library performs the communication with the device via uart interface by sending commands and checking response from the device to the host. Commands perform writting to the registers, reading from the registers (data can be 8bit, 16bit, or 32bit), calibration, writting to the EEPROM and reading from the EEPROM. By using functions for reading user can read measurements that include voltage RMS, current RMS, power data (active, reactive, apparent) and many other things. For more details check documentation.

Key functions:

  • T_PWRMETER_RETVAL pwrmeter_readRegBytes( uint16_t regAddr, uint8_t nBytes, uint8_t *dataOut ) - Function reads data bytes from registers.
  • T_PWRMETER_RETVAL pwrmeter_writeRegWORD( uint16_t registerAddr, uint16_t dataIn ) - Function writes 16-bit data to the register.
  • T_PWRMETER_RETVAL pwrmeter_sendCommand( uint8_t commandByte ) - Function sends and performs a determined command.

Example description

The application is composed of three sections :

  • System Initialization - Initializes peripherals and pins.
  • Application Initialization - Initializes UART interface, puts output of regulator in active state and configures gain channel and uart baud rate.
  • Application Task - (code snippet) - Reads voltage, current and power measurements from data registers, converts this values to determined units and all results on uart terminal. Repeats operation every second.
void applicationTask()
{
 responseByte = pwrmeter_readRegWORD( _PWRMETER_VOLT_RMS_REG, &voltageRMS );
 checkResponse();
 responseByte = pwrmeter_readRegDWORD( _PWRMETER_CURR_RMS_REG, ¤tRMS );
 checkResponse();
 responseByte = pwrmeter_readRegDWORD( _PWRMETER_ACTIVE_PWR_REG, &activePower );
 checkResponse();
 responseByte = pwrmeter_readRegDWORD( _PWRMETER_REACTIVE_PWR_REG, &reactivePower );
 checkResponse();
 responseByte = pwrmeter_readRegDWORD( _PWRMETER_APPARENT_PWR_REG, &apparentPower );
 checkResponse();
 responseByte = pwrmeter_readRegSigned( _PWRMETER_PWR_FACTOR_REG, _PWRMETER_16BIT_DATA, &powerFactor );
 checkResponse();

 measData[ 0 ] = (float)voltageRMS / 100;
 measData[ 1 ] = (float)currentRMS / 1000;
 measData[ 2 ] = (float)activePower / 100000;
 measData[ 3 ] = (float)reactivePower / 100000;
 measData[ 4 ] = (float)apparentPower / 100000;
 measData[ 5 ] = (float)powerFactor / 32767;

 responseByte = pwrmeter_getStatus( &statusByte );
 checkResponse();

 if ((statusByte & _PWRMETER_DCMODE_MASK) != 0)
 {
 mikrobus_logWrite( "DC mode", _LOG_LINE );
 }
 else
 {
 mikrobus_logWrite( "AC mode", _LOG_LINE );
 }

 FloatToStr( measData[ 0 ], text );
 floatConv();
 mikrobus_logWrite( "RMS voltage: ", _LOG_TEXT );
 if (((statusByte & _PWRMETER_DCMODE_MASK) != 0) && ((statusByte & _PWRMETER_DCVOLT_SIGN_MASK) == 0))
 {
 mikrobus_logWrite( "-", _LOG_TEXT );
 }
 mikrobus_logWrite( text, _LOG_TEXT );
 mikrobus_logWrite( "[V]", _LOG_LINE );

 FloatToStr( measData[ 1 ], text );
 floatConv();
 mikrobus_logWrite( "RMS current: ", _LOG_TEXT );
 if (((statusByte & _PWRMETER_DCMODE_MASK) != 0) && ((statusByte & _PWRMETER_DCCURR_SIGN_MASK) == 0))
 {
 mikrobus_logWrite( "-", _LOG_TEXT );
 }
 mikrobus_logWrite( text, _LOG_TEXT );
 mikrobus_logWrite( "[mA]", _LOG_LINE );

 FloatToStr( measData[ 2 ], text );
 floatConv();
 mikrobus_logWrite( "Active power: ", _LOG_TEXT );
 if ((statusByte & _PWRMETER_PA_SIGN_MASK) == 0)
 {
 mikrobus_logWrite( "-", _LOG_TEXT );
 }
 mikrobus_logWrite( text, _LOG_TEXT );
 mikrobus_logWrite( "[W]", _LOG_LINE );

 FloatToStr( measData[ 3 ], text );
 floatConv();
 mikrobus_logWrite( "Reactive power: ", _LOG_TEXT );
 if ((statusByte & _PWRMETER_PR_SIGN_MASK) == 0)
 {
 mikrobus_logWrite( "-", _LOG_TEXT );
 }
 mikrobus_logWrite( text, _LOG_TEXT );
 mikrobus_logWrite( "[VAr]", _LOG_LINE );

 FloatToStr( measData[ 4 ], text );
 floatConv();
 mikrobus_logWrite( "Apparent power: ", _LOG_TEXT );
 mikrobus_logWrite( text, _LOG_TEXT );
 mikrobus_logWrite( "[VA]", _LOG_LINE );

 FloatToStr( measData[ 5 ], text );
 floatConv();
 mikrobus_logWrite( "Power factor: ", _LOG_TEXT );
 mikrobus_logWrite( text, _LOG_LINE );
 mikrobus_logWrite( "", _LOG_LINE );

 Delay_ms( 1000 );
}

Additional Functions :

  • void checkResponse() - Checks response from the device to the host and logs message if error occurred.
  • void floatConv() - Makes the float values be rounded to two decimal places.


Other mikroE Libraries used in the example:

  • Conversions
  • UART

Additional notes and information

Depending on the development board you are using, you may need USB UART clickUSB UART 2 click or RS232 click to connect to your PC, for development systems with no UART to USB interface available on the board. The terminal available in all MikroElektronika compilers, or any other terminal application of your choice, can be used to read the message.

ALSO FROM THIS AUTHOR

Zero-Cross Click

0

Zero-Cross Click is a compact add-on board that has the ability to detect the change from positive to negative or negative to a positive level of a sinusoidal waveform. This board features circuitry that provides Zero Crossing Detection (ZCD). Whenever the sine wave crosses the ground potential, the output shifts from HIGH logic to LOW or vice-versa.

[Learn More]

Air quality 3 Click

0

Air quality 3 Click is the air quality measurement device, which is able to output both equivalent CO2 levels and total volatile organic compounds (TVOC) concentration in the indoor environment.

[Learn More]

9DOF 2 Click

5

9DOF 2 Click carries the ICM-20948, the world’s lowest power 9-axis MotionTracking IC that is idealy suited for smartphones, tablets, Wearable Sensors and IoT applications. The ICM-20948 is a multi-chip module (MCM) consisting of two dies integrated into a single package.

[Learn More]