Home

Measuring mains power consumption with the STM32x and STPM01

image

Contents

1. Schematic diagram Figure 2 Hardware N GON z AZZ 081 229 ZM EM ALZ zH ININ gt lt 1 014 3001 994 lt lt lt lt a RAG wool 1854 doz doz 1 958 90 290 192 099 NSHO HNU ISOW 2ids stad VSSA 4 _OSIN OS LHO LWILL SLO ELHVSN NOS Z1dS ELad EL 1 s te NIME LLLDIO ELUVSN LVEINS ZOZI SSN ZidS Zled 0898 5 z b 1 7908 2021 018 O 684 _ JL OLY suey ihano WL 5 ISUN 4 8019 2 08 101 984 2 13899 65 gt as LWEINS LOZI Sad 15 8 985 2 oaar aaea a
2. 4 2 2 8 iaLr sivd Wee Zull di 21 1002 9080 28050 104 dA i 28 060 dINVI LLNV ELOd LVOMS SLLIVELWd 67 MOLLE BPA 5 HLINU JAAS NXL NYO SLY LLYYSN ZLYd SALF A 9 VHO HALLACINGESNXE NVO SLO LLUVSI L i moyo SSA 010d SHO IWLLXY LLHVSN OLWd uss PPPA 0902 15 ZH NULXL LLHYSN 6Yd ONAS 6 595 dOW nay 89d OOW LHO INILAO LLYYSN Yd 2 ONAS a 0992 29 ZHO ENLL ZNI OQY ISON LIdS 2Yd b a pel 954 LHO EWLL ONI DOV OSIMELIdS 9Vd 5 25 45 pe os pLNI Odv rod PNI OGVAIO 2LHVSN SSN LdS pWd 95 eLN oaweod 0595 Zinroawiedd 2 1 b 4 1 1 S DOW SLO ZLHVSN d DIM 0Vd 3 rer ely lt 990 do 650 880 i 20 99 26 K sais zn 1010 22 050 A 28 050 EAE 5 o gt 0091 400 5 199 999 969
3. 2799 Application note Measuring mains power consumption with the STM32x and STPMO1 Introduction This document describes a software and hardware solution concerning the STM32x microcontroller and the power meter for measuring mains power consumption and also provides hardware and firmware guidelines to interface the with the STM32x microcontroller Figure 1 shows the block diagram of the solution The system described in this document is the first brick to build a complex system for distributed load management Figure 1 Block diagram Neutral Current Transformer AMO00076v1 November 2008 Rev 1 1 14 www st com Contents AN2799 Contents 1 2 ______ 2 1 STM32F103xx microcontroller 4 2 1 1 5 2 2 Hardware description 5 3 Functional description 7 4 Firmware description 7 4 1 Power meter object description 7 4 1 1 gt ex 9 4 1 2 eee se omelet dee ee Sua eee eee 9 4 1 3 Construction 10 4 1 4 DOCTOR
4. 99 gt Isu Ovir 13539 lt lt Sulit oe 4 4 1 9 1 _ ANIT 8 00A gt gt SWL OVLP OVS LAE AMO00077v1 6 14 2799 3 4 1 Functional description Functional description The STPMO1 host interface is a single bidirectional data line SPI with a 32 MHz maximum read speed and 100 kHz maximum write speed Due to these requirements the STM32 microcontroller is used in the following way Inthe reading phase the MISO and SCLK pins are configured in alternate functions and used by the SPI2 peripheral The maximum reading speed is 18 MHz by an APB speed equal to 36 MHz configuring the SPI baud rate with APB 2 Inthe writing phase the MISO and SCLK pins are configured as GPIOs and the SPI operation is emulated by firmware controlling the speed operations to not exceed the 100 kHz writing speed limit The MCO pin is configured to provide the HSE clock Firmware description The firmware for the management of the STPM01 energy meter has been developed using an object oriented programming OOP approach even if standard ANSI C programming language has been used Power meter object description The power meter object is defined and implemented in the PowerMeterObj c PowerMeterObj h and PowerMeterTypes h files The power meter is represented by a structure containing t
5. erases 11 4 2 Hardware abstraction 11 4 2 1 PIAL MUINCUON Ss creek weedy tee aes 11 4 3 11 4 3 1 Application interface functions 12 5 CONCIUSION 42605566444 12 6 REVISION NISIOLY sic oe ccc ete oe 13 2 14 2799 File organization File organization The following table presents the firmware modules Table 1 Firmware modules PowerMeterHal h Definitions of power meter hardware abstraction layer types and function PowerMeterHalTypes h prototypes PowerMeterObj h PowerMeterTypes h Definitions of power meter abstract objects and types PowerMeterHal c Power meter hardware abstraction layer and abstract object PowerMeterObj c implementation Meterlayer h Definitions of application interface types and function prototypes Meter c eee Application interface and hardware abstraction layer implementation ExampleApp c Library usage example Hardware The solution is based on the STM32F103xx in the LQFP64 package with 128 kB of Flash and 20 kB of SRAM for demonstration purposes but it can be easily ported on the smaller STM32F101xx microcontroller family based on the same AR
6. 3 2X specification Less than 0 1 error Precision voltage reference 1 23 V and 30 ppm C max Hardware description The hardware used in managing the 5 1 by the STM32x microcontroller is described in this section Figure 2 shows a reference schematic to interface the STM32x microcontroller with the The STPMO1 bidirectional data line is connected to the SPI MISO of the STM32 This is because the speeds for the data read and data write operations of the STPMO0O1 SPI interface are much too different 32 MHz for the read operation and 100 kHz for the write operation In fact during the write operation the serial communication is emulated by software to have very slow communication on the STPMO1 data line and during the read operation the STM32 SPI peripheral is used to reach the maximum speed possible Since the maximum speed of the STM32 SPI is 18 MHz it doesn t matter which SPI peripheral is used have the maximum read bit rate In this application the SPI2 is used The STPMO1 clock is provided by the PA8 pin configured as the alternate function The AC current is provided to the a current transformer connected to the current channel 1 For more details about analog parts related to the please refer to the STPMO1 datasheet The solution has been validated using the SmartPlug board For further details please refer to the SmartPlug hardware user manual 5 14 2799
7. M Cortex M3 CPU as well The device used to measure the phase AC current is the STPMO1 with a current transformer 3 14 Hardware 2 1 4 14 AN2799 STM32F103xx microcontroller The following list is a brief description of the features of the STM32F103xx microcontroller Please refer to the STM32F103xx datasheet for a more detailed description of the device Core ARM 32 bit Cortex M3 CPU 72 MHz 90 DMIPS with 1 25 DMIPS MHz Single cycle multiplication and hardware division Memory 32 10 128 Kbytes of Flash memory 6 10 20 Kbytes of SRAM Clock reset and supply management 2 0 to 3 6 V application supply I Os POR PDR and programmable voltage detector PVD 4 10 16 MHz quartz oscillator Internal 8 MHz factory trimmed RC Internal 40 kHz RC PLL for CPU clock 32 kHz oscillator for RTC with calibration Low power Sleep stop and standby modes VBAT supply for RTC and backup registers 2 12 bit 1 us A D converters 16 channel Conversion range 0 to 3 6 V Dual sample and hold capability Temperature sensor DMA 7 DMA controller Peripherals supported timers ADC SPls 2 USARTs Debug mode Serial wire debug SWD JTAG interfaces Up to 80 fast I O ports 26 36 51 80 I Os all mappable on 16 external interrupt vectors all 5 V tolerant except for analog inputs Up to 7 timers Upto three 16
8. MeterType ErrStatus OnSpiRxIrq typedef struct PowerMeter PowerMeterType Forward declaration for circular typedefs struct PowerMeter POWER_METER_OBJ 4 2799 4 1 1 Firmware description Attributes The object attributes are described as follows m_Voltage private variable containing the last read voltage in mV m_Current private variable containing the last read current in mA m_Energy private variable containing the last read energy in mW Registers public structured variables containing the STPMO1 registers DAP active energy reactive energy DSP apparent energy DFP type1 energy DEV RMS values of measured voltage and current DMV instantaneous values of measured voltage and current CFL lower part of the configuration register higher part of the configuration register Signals public structured variables containing the signals descriptor used to interface STM32 with 565 this signal enables the SPI operation when low PM_SYN When SCS is low this signal selects the read or write operation When both SCS and SYN signals are high the results of the input or output data are transferred to the transmission latches _5 SPI MISO signal This signal is used as the 5 data signal The direction of this signal depends on the SY
9. N signal SPI clock signal Each signal descriptor contains the STM32 port and pin number For further details about registers and the microcontroller interface please refer to the STPMO1 datasheet Methods The object methods are implemented by means of pointers to functions which are described as follows Create this function initializes all power meter object elements properties and methods Destroy not used Implemented to have a general object implementation Init this function initializes the power meter object properties and the power meter signals putting them in the idle state Reset this function executes the reset sequence to perform the remote reset operation of the STPMO1 Figure 4 SetSignals this function initializes the signals attribute of the power meter object and configures the GPIOs related to the signals GetSignals this function retrieves the signals attribute of the power meter object SetCfgRegMode this function sets the STPMO1 configuration register as shadow latches or OTP In current AN firmware the 5 is configured to use the shadow latches for the configuration for testing reasons 9 14 Firmware description AN2799 10 14 WriteConfigBit this function writes a configuration bit of the STPMO0O1 configuration register formatting an 8 bit command word as the following 1 bit data 6 bits configuration bits 1 bit don t car
10. ST products with provisions different from the statements and or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever any liability of ST ST and the ST logo are trademarks or registered trademarks of ST in various countries Information in this document supersedes and replaces all information previously supplied The ST logo is a registered trademark of STMicroelectronics All other names are the property of their respective owners 2008 STMicroelectronics All rights reserved STMicroelectronics group of companies Australia Belgium Brazil Canada China Czech Republic Finland France Germany Hong Kong India Israel Italy Japan Malaysia Malta Morocco Singapore Spain Sweden Switzerland United Kingdom United States of America www st com 14 14 ky
11. bit timers each with up to 4 IC OC PWM or pulse counter 16 bit 6 channel advanced control timer up to 6 channels for PWM output dead time generation and emergency stop 2watchdog timers independent and window SysTick timer a 24 bit down counter Up to 9 communication interfaces Up to 21 interfaces SMBus PMBus 2799 2 2 Hardware Upto 3 USARTs ISO 7816 interface LIN IrDA capability modem control Upto 2 SPls 18 Mbit s interface 2 0B Active USB 2 0 full speed interface Packages are ECOPACK RoHS compliant STPMO1 The is a programmable single phase energy metering IC which is designed for effective measurement of active reactive and apparent energy in a power line system using a Rogowski coil a current transformer and shunt sensors The solution presented in this document is based on a current transformer sensor The following list is a brief description of the main features of the STPM0O1 For more details please refer to the device datasheet Active reactive apparent energies RMS values Ripple free active energy pulsed output Live and neutral monitoring for tamper detection Easy and fast digital calibration in only one point over the whole current range OTP for calibration and configuration Integrated linear for digital and analog supply Selectable RC or crystal oscillator Supports 50 60 Hz IEC62052 11 IEC6205
12. e The configuration word is sent to the STPMO1 by the SPI interface WriteConfigRegs this function writes the entire CFL configuration registers of the STPMO1 ReadRegisters this function reads the registers from the STPMO1 and assigns the read values to the power meter object registers attribute The number of read registers depends on the RegloReadNum passed parameter ReadMeasure this function reads the RMS voltage and current registers from the calculates the real RMS values by multiplying the values of each register by the calibration factors and assigns these values to the m_Voltage and m_Current attributes of the power meter object GetVoltage this function retrieves the last read voltage value in mV GetCurrent this function retrieves the last read current value in mA GetEnergy this function retrieves the last read energy value in mW OnSpiRxlrq SPI interrupt event Not used in this implementation The SPI interrupt is managed externally by the power meter object implementation Figure 4 Reset sequence SCS SYN SCLNLC SDATD AMO00079v1 Construction The power meter object is constructed by the NewPowerMeterObj function implemented externally by the object itself This function allocates the memory for the object assigns the create method and calls it to assign the rest of the object properties 2799 4 1 4 4 2 4 2 1 4 3 Fir
13. he properties and the method of the Power Meter Object as illustrated in Figure 3 Figure 3 Power meter object struct PowerMeter PM_RegistersType Registers 1 Signals struct Signal PowerMeter PM_SignalsType PM_SCS PM _SignalType 1 struct PM_SYN PM_SignalType PowerMeter PM_SignalType PM_SDA PM_SignalType Port PortType PM_SCLK PM_SignalType PinType 00078 1 7 14 Firmware description AN2799 8 14 POWER_METER_OBJ define POWER_METER_OBJ PM_u32 m_Voltage 132 m Current PM_u32 m_Energy PM_RegistersType Registers PM_SignalsType Signals PM_ErrStatus Create PowerMeterType PM_ErrStatus Destroy PowerMeterType PM_ErrStatus Init PowerMeterType PM_ErrStatus Reset PowerMeterType ErrStatus SetSignals PowerMeterType PM SignalsType pSignals PM SignalsType GetSignals PowerMeterType PM _ ErrStatus SetCfgRegsMode PowerMeterType PM CfgRegsModeType CfgRegsMode PM_ErrStatus WriteConfigBit PowerMeterType PM_u8 uBitAddress PM_u8 uBitValue PM_ErrStatus WriteConfigRegs PowerMeterType PM_u32 uCFL_ Value PM_u32 uCFH_Value ErrStatus ReadRegisters PowerMeterType PM_u8 RegsToReadNum ErrStatus ReadMeasure PowerMeterType MeasureType 132 GetVoltage PowerMeterType 132 GetCurrent PowerMeterType 132 GetEnergy Power
14. mware description Deletion The power meter object is deleted by the DeletePowerMeterObj function implemented externally by the object itself This function first calls the deletion method to free dynamically allocated variables during object creation in this case does nothing then frees the allocated memory for the power meter object Hardware abstraction layer The HAL is implemented using the following files PowerMeterHal c PowerMeterHal h PowerMeterHalTypes h This module is useful to abstract the power meter object implementation from the STM32 standard library HAL functions The hardware abstraction layer functions are described as follows PM_ConfigSignal this function configures pin according to the passed signal descriptor and configuration type PM_ReceiveRegOnSpi this function receives the STPMO1 internal register from the SPI interface PM_OnSpiRxlirq This function implements the interrupt service routine of the SPI interface It is called when the FIFO of the SPI peripherals contains 1 byte or more and assigns the received value to a shared register variable SendClkToGetData this function is used to provide the SPI clock to the to receive data ConfigPin pin configuration function Application interface The application interface is implemented using the following files Meter c MeterHal c MeterLayer h This layer is useful to abstract the applicatio
15. n from the specific board used In fact the functions implemented in the described modules allow the hardware configuration of the specific board used The firmware described in this document has been validated using the SmartPlug board that includes two STPMO1 meters enumerated as PM_METER_TYPE_CONSUMPTION and PM_METER_TYPE_DISPERSION 11 14 Conclusion 4 3 1 12 14 AN2799 Application interface functions The application interface functions are described as follows PM_HwMetersCommoninit this function configures the SPI peripheral including the interrupt controller the STM32 pin to provide the clock to both 5 1 GPIO as input useful to select two different operational modes Normal Mode typical operational mode Calibration Mode used to calibrate the STPMO1 devices by an external tool In this mode the STM82 provides only the clock to the STPM0O1 devices These configurations common to both STPMO1 devices M_HwMeterSignalslnit this function initializes the signals specific for an 5 In detail the STM32 GPIO is used as the SCS for the specific device The specific device is selected an enumerator as already stated ActivateMeter this function includes all the operations to be done using the power meter object for the initialization All the initialization operations have been included in a single initialization procedure I
16. nit establishing a power meter object and the 5 device identifier as parameters Conclusion Summarizing this document explains how to interface the energy meter device to the STM32x microcontroller including an easy to use firmware library The firmware library also includes the file ExampleApp c which shows how to use the library itself The user application has to perform the standard STM32 configuration and simply call the NewPowerObj for each STPMO1 device to allocate the object call the Init to perform the power meters related initializations and configurations call the ReadMeasure method to get the data from STPMO1 device and call GetVoltage and or GetCurrent to get the last measurement data 2799 6 Revision history Revision history Table 2 Document revision history foe neve se 27 Nov 2008 Initial release 13 14 2799 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics NV and its subsidiaries ST reserve the right to make changes corrections modifications or improvements to this document and the products and services described herein at any time without notice All ST products are sold pursuant to ST s terms and conditions of sale Purchasers are solely responsible for the choice selection and use of the ST products and services described herein and ST assumes no liability whatsoever relating
17. to the choice selection or use of the ST products and services described herein No license express or implied by estoppel or otherwise to any intellectual property rights is granted under this document If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION OR INFRINGEMENT OF ANY PATENT COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT UNLESS EXPRESSLY APPROVED IN WRITING BY AN AUTHORIZED ST REPRESENTATIVE ST PRODUCTS ARE NOT RECOMMENDED AUTHORIZED OR WARRANTED FOR USE IN MILITARY AIR CRAFT SPACE LIFE SAVING OR LIFE SUSTAINING APPLICATIONS NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION MAY RESULT IN PERSONAL INJURY DEATH OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE ST PRODUCTS WHICH ARE NOT SPECIFIED AS AUTOMOTIVE GRADE MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK Resale of

Download Pdf Manuals

image

Related Search

Related Contents

  ISOL-VAPOR - COMPAÑIA QUÍMICA ICH de MANTENIMIENTO sl  Manual de Instrucciones  Samsung 마우스  Edital Concorrencia - 3-2012 - Governo do Estado do Rio de Janeiro  K5904118-00 User manual MFCD-1219 ES.fm  4 Logística, Señorita JEANNETTE MARITZA SIFUENTES ESPINAL  Worldwide Lighting W33353FG16-CL Instructions / Assembly  Manual - Velleman    

Copyright © All rights reserved.
Failed to retrieve file