May2013DocID18304Rev11/38AN3322ApplicationnoteWatt-hourmeterbasedontheSTM32F101microcontrollerByLudekHoloubekIntroductionThisdocumentdescribes,indetail,thehardwareandsoftwareimplementationofawatt-hourmeterusingtheSTM32F101microcontroller.
Thiscosteffectivewatt-hourmeterusesshuntwithanoperationalamplifierasacurrentsensor,anembedded12-bitADCforcurrentandvoltagemeasurement,GPIOforLCDmanagement,andalotofotherperipheralsforcommunication,tamperdetection,keyboard,andpowerdisconnection.
PowerfularchitectureoftheSTM32microcontrollerallowssamplingat1Msps.
ThehighsamplingratemakesitpossibletousemethodsforADCresolutionenhancement.
MainfeaturesMetrologicalparts–Microcontrollerandexternalopamponly–CompliantwithEN50470-1:2006ClassB,precisionbetterthan1%–Startingcurrent20mA,nominalcurrent5A,maximumcurrent100A–Readsthevoltageandthecurrentsignaluptothe21stharmonic–Shuntasacurrentsensor.
CTandRogowskicoilisoptionalAdditionalpartsincludedinreferencedesign–LCDdrivendirectlybymicrocontroller–Keyboarddrivendirectlybymicrocontroller–AnextraexternalEEPROMforuserdata–Bi-stablerelay,IRcommunication,serialcommunication–Backupbattery,completepowermeterpowermanagementwww.
st.
comContentsAN33222/38DocID18304Rev1Contents1Watt-hourmeterusingtheSTM3261.
1STM32ADCparameters61.
2RequirementsformeterinClassB6Definitionsofthepowermeterparameters(accordingtoEN50407-1:2006)71.
3STM32ADCdynamicmeasurementrange81.
3.
1Voltagemeasurement81.
3.
2Therearetwocurrentrangesinthemeter91.
4ErrorsourcesontheSTM32meter101.
5LinearityofSTM32ADCanditsINLreduction101.
6ThermalnoisepresentonSTM32meterplatform101.
7Crosstalkbetweensubsequentmultiplexedchannels111.
8PowerandenergymeasurementbySTM32embeddedADC131.
9ADCenhancementbyoversamplingtechnique151.
10Outputvalues16Somereferencevaluesandconstantsaredefined161.
10.
1RMSvoltage171.
10.
2RMScurrent-highgained181.
10.
3RMScurrent-lowgained191.
10.
4Power191.
10.
5Energy201.
10.
6Pulseoutput212Computationalissuesandcompensationalgorithms222.
1Non-coherentsamplingissues222.
2Timerevaluationforcoherentsamplingtriggering242.
3Timersettingconstraintsforcoherentsamplingtriggering252.
4Precisetimersettingforcoherentsampling262.
5Frequencymeasurement282.
6Filteringofinputsignalforproperzerocrossingdetection29DocID18304Rev13/38AN3322Contents2.
7Phaseshiftcorrection302.
7.
1PhaseshiftmeasuredfortheSTM32meter302.
7.
2Phaseshiftcorrection-errorevaluation302.
7.
3Phaseshiftcorrection-filterimplementation332.
8Calibrationprocedure332.
9Reactiveandapparentpowercomputation342.
10Analogpartschematic-part1352.
11Analogpartschematic-part2363References374Revisionhistory37ListoftablesAN33224/38DocID18304Rev1ListoftablesTable1.
STM32ADCparameterspecifications6Table2.
STM32ADCinputcharacteristicsspecifications12Table3.
Crosstalkbetweensubsequentmultiplexedchannels12Table4.
Precisionvs.
timersetting.
Simulatedonsignalu(t)=sin(2xpix50xt)24Table5.
Highspeedinternal(HSI)RCoscillator26Table6.
Errorofinstantpowercausedbyphaseshift31Table7.
Documentrevisionhistory37DocID18304Rev15/38AN3322ListoffiguresListoffiguresFigure1.
RequirementsforClassBpowermeterprecision,threeranges7Figure2.
Templateusedtocheckmeteraccuracy(uptoImax)8Figure3.
TypicalthermalnoisepresentonSTM32meterplatform.
HistogramshowsnoiseequivalenttowhiteGaussiannoise11Figure4.
Internalandexternalanaloginputpincapacitorsandresistors12Figure5.
CompleteblockdiagramofthealgorithmusedinSTM32powermeter13Figure6.
VoltagecircuitryofSTM32meter14Figure7.
CurrentcircuitryofSTM32meter15Figure8.
CurrentcircuitryofSTM32meter,opampsaturationmarkedbyredcircle16Figure9.
Voltagecircuitry-calibrationCUconstantcomputation18Figure10.
Currentcircuitry-calibrationCIconstantcomputation19Figure11.
Instantpower22Figure12.
ParasiticfrequencyFHindetail23Figure13.
ErrorofURMSvs.
thetimererrorintimerticks25Figure14.
ErrorofURMS25Figure15.
Finercalculationofzerocrossing28Figure16.
Voltagesignalcrossingzerovoltagelinetwice29Figure17.
Voltagesignalusedforcorrectzerocrossingafterproperfiltering.
29Figure18.
Zerocrossingforgreen-U,blue-ILG,red-IHG30Figure19.
ErrorofinstantpowerforPF=1andPF=0.
5.
32Figure20.
ErrorofinstantpowercausedbyphaseshiftforPF=1.
32Figure21.
ErrorofinstantpowercausedbyphaseshiftforPF=0.
533Figure22.
Analogpartschematic-part135Figure23.
Analogpartschematic-part236Watt-hourmeterusingtheSTM32AN33226/38DocID18304Rev11Watt-hourmeterusingtheSTM32Thefollowingsectionsdescribethenecessaryfeasibilitystudy,theoryandcomputationfortheSTM32powermeterimplementation.
Thesystemdesign,STM32parameterevaluation,ADCfeatureenhancement,andinternationalstandardsarealsocoveredhere.
1.
1STM32ADCparametersThemostimportantpartofthepowermeteranditsmicrocontrollerusedinmeteringapplicationsistheembeddedADC.
Itsparametersarethekeytodecidingiftherequirementsforprecisionoftheimplementedmetercanbefulfilled(internationalstandardsmentionedinthesesections).
ThefirststepistoevaluatetheparametersgivenintheADCspecifications:ForthegivenSTM32ADC,thespecificationsandtestsshow:Equation1Integralnon-linearityerroris.
Equation2Theresolutionofthe12-bitADCis=0.
02%ofthefullscaleADCrange.
Equation3If,thentheaccuracy=resolutionofgivenADC.
Equation4Theaccuracyofthe12-bitADCis=0.
02%ofthefullscaleADCrange.
1.
2RequirementsformeterinClassBTheEuropeanstandarddefiningtherequirementsforelectricitymeteringequipmentshouldbethesourceofconstraintsandlimitsforthedesignpresentedinthisapplicationnote.
EN50470-1:2006andEN50470-3:2006arereferencedinthiscase.
AllthecomputationisdirectedtotheprecisionofClassB.
Table1.
STM32ADCparameterspecificationsSymbolParameterTestconditionsTyp.
Max.
UnitETTotalunadjustederrorfPCLK2=24MHz,fADC=12MHz,RAIN3322Watt-hourmeterusingtheSTM32Definitionsofthepowermeterparameters(accordingtoEN50407-1:2006)RMSvaluesindicatedI-current-theelectricalcurrentflowingthroughthemeter.
Ist-startingcurrent-thelowestvalueofthecurrentatwhichthemeterisdeclaredtoregisteractiveelectricalenergyatunitypowerfactor.
Imin-minimumcurrent-thelowestvalueofthecurrentatwhichtheEuropeanstandardspecifiesaccuracyrequirements.
AtandaboveImin,uptoItr,relaxedaccuracyrequirementsapply.
Itr-transitionalcurrent-thevalueofthecurrentat,andabovewhich,uptoImax,fullaccuracyrequirementsoftheEuropeanstandardapply.
Iref-referencecurrent-fordirectmeters,10timesthetransitionalcurrent.
(Thisvalueisthesameasthebasiccurrent,IbdefinedintheEN62052-11,chapter3.
5.
1.
2.
)Forcurrenttransformeroperatedmeters,20timesthetransitionalcurrent.
(ThevalueisthesameasratedcurrentIn.
)Imax-maximumcurrent-thehighestvalueofcurrentatwhichthemeterpurportstomeettheaccuracyrequirementsofthisEuropeanstandard(EN62052-11,chapter3.
5.
2.
).
Itr-canbechosen(forClassB)fromthesetofvalues:0.
5,1,1.
5and2AExample1ExampleofonesetupforameterItr-chosen0.
5AIst=0.
04Itr=20mAImin=0.
5Itr=250mAImax>50Itr,Imax>25AFigure1showstheprescribedprecisioningivencurrentintervals.
Figure1.
RequirementsforClassBpowermeterprecision,threeranges,VW,PLQP$P$QRWGHILQHG,PLQ,WUP$$,WU,UHI,PD[$$!
$0Watt-hourmeterusingtheSTM32AN33228/38DocID18304Rev1Figure2.
Templateusedtocheckmeteraccuracy(uptoImax)1.
3STM32ADCdynamicmeasurementrangeTheprecisionandresolutionoftheADCdeterminesthedynamicrangeofmeasuredvoltageandcurrent.
ThissectionanalyseswhetherthegivenADCiscapableofcovering,withitsprecisionandresolution,thewholerangeforrequestedmaximumcurrentandvoltage.
TheinputcurrentandvoltagearescaledtothefullscaleoftheSTM32ADC:ByavoltagedividerforvoltagemeasurementByashuntandexternaloperationalamplifierforalowcurrentmeasurementByashuntandexternaloperationalamplifierforahighcurrentmeasurement.
1.
3.
1VoltagemeasurementOnevoltagechannel,nominalvoltage230VRMSisusedUpeak-to-peak=230x2x2x120%=780V(120%meansasafetymargin)Resolutionfor780V:ULSB:peak-to-peak=780Vx0.
02%=0.
16VResolutionfor230V:ULSB:RMS=230Vx0.
02%=0.
055VRMSValue0.
02%representsresolutionandprecisionoftheADCandisdefinedinSection1.
1:STM32ADCparameters.
Therangewhereitisnecessarytotakecareoftheprecisionisbetween80%to115%(extendedoperatingrange)ofthenominalvoltage:UMAX=230VRMSx115%=253VRMSUMIN=230VRMSx80%=184VRMSForthelowestandhighestvoltagevaluetheprecisionofthevoltagemeasurementis:ErrorofUMAX=0.
055VRMS/184VRMS=0.
030%ErrorUMIN=0.
055VRMS/253VRMS=0.
022%Errorvaluesaremuchlowerthanprescribedbystandards:1%>>0.
030%.
DocID18304Rev19/38AN3322Watt-hourmeterusingtheSTM321.
3.
2TherearetwocurrentrangesinthemeterLowgainrange(LG):for100Arangearesolutionandaccuracywiththe12-bitADCare:Imax=100x2x1.
414=300Apeak-peakResolutioninAformaximumvalue:300Ax0.
02%=60mAResolutioninAforRMSvalue:100ARMSx0.
02%=20mARMSMinimalerrorofmeasurementofcurrentabout:Startingcurrent:Ist:20mARMS/20mARMS=100%(noprecisionprescribed)Minimumcurrent:Imin:20mARMS/250mARMS=8%(1,5%prescribed)Transitioncurrent:Itr:20mARMS/500mARMS=4%(1%prescribed)Referencecurrent:Iref:20mARMS/5ARMS=0.
4%(1%prescribed)Maximumcurrent:Imax:20mARMS/100ARMS=0.
02%(1%prescribed).
ErrorvaluesarelowerthanprescribedstandardsincaseofIrefandImax.
LowercurrentsIminandItrcannotbemeasuredwithinthisLGrange.
Highgainrange(HG):for10Arangearesolutionandaccuracywiththe12-bitADCare:Imax=10x2x1.
414=28Apeak-peakResolutioninAformaximumvalue:28Ax0.
02%=5.
8mAResolutioninAforRMSvalue:10ARMSx0.
02%=2.
4mARMSMinimalerrorofmeasurementofcurrentabout:Startingcurrent:Ist:2.
4mARMS/20mARMS=12%(noprecisionprescribed)Minimumcurrent:Imin:2.
4mARMS/0.
5ARMS=0.
48%(1,5%prescribed)Transitioncurrent:Itr:2.
4mARMS/1ARMS=0.
24%(1%prescribed)Referencecurrent:Iref:2.
4mARMS/5ARMS=0.
048%(1%prescribed)Maximumcurrent:Imax:2.
4mARMS/10ARMS=0.
024%(1%prescribed).
ErrorvaluesarelowerthanprescribedstandardsinthecaseofIst,Imin,Itr,andIref.
HighercurrentImaxcannotbemeasuredwithinthisHGrangeduetoADCsaturation.
Fromtheanalysisperformedinthissectionitcanbeseenthatasystemusingonerangeforvoltageandtworangesforcurrentmeasurementcanfulfillrequirementsfortheprescribedprecisionofthesystem.
Watt-hourmeterusingtheSTM32AN332210/38DocID18304Rev11.
4ErrorsourcesontheSTM32meterTherearealotofsourcesoferrorwhenmeasuringcurrentandvoltage.
Theycanbecompensatedinmostlyallcases.
1.
ADClinearity:itlimitstotalaccuracycompensatedbyADCsymmetry,seeSection1.
5.
2.
Temperature:externalvoltagereferencekeepsADCconversionstable.
3.
OpampandADCoffsets:theyareremovedbyACcoupling,calibrationanddigitalfiltering.
4.
ADCgain:itiscompensatedbycalibrationofthemeter.
5.
ThermalnoisepresentontheSTM32meterPCBboard:seeSection1.
6.
6.
Crosstalkbetweensubsequentchannelmeasurement:compensationisdiscussedinSection1.
7.
7.
Linearityofopamps:itispresent,notcompensated.
Selectionofagoodopampismade.
8.
Phaseshiftbetweenchannels;thecompensationisshowninSection2.
7.
1.
5LinearityofSTM32ADCanditsINLreductionIncreasingtheADCresolutiondoesnotresultinhigheraccuracysincethetechniquesforobtaininghigherresolutioncanreduceDNL(differentialnon-linearity)butnotINL(integralnon-linearity),seeSection1.
9:ADCenhancementbyoversamplingtechnique.
Thelinearitycanbeenhanced(INLreduction)from0.
7to0.
17LSBbytheapplicationofasimpletechniquetotheHWandSWdesign.
GoodknowledgeoftheADCisassumedforthistechnique,describedinaseparatedocumentsuppliedonrequest.
1.
6ThermalnoisepresentonSTM32meterplatformThenumberofeffectivebitsofagivenADCdependsonthepresenceofnoiseinthesystem,namelyonthePCBandmicrocontrolleritself.
IfthenoiseiswhiteGaussiannoise(orsimilar),thenumberofeffectivebitscanberecoveredbyoversamplinganddecimationmentionedinSection1.
9.
Figure3bringsadirectnoisemeasurementofthesystem.
ThesinglevoltagelevelwasconnectedtoaninputoftheADContheSTM32powermeterboardandathousandsampleswerecollected.
Figure3showsahistogramofthevaluestaken.
DocID18304Rev111/38AN3322Watt-hourmeterusingtheSTM32Figure3.
TypicalthermalnoisepresentonSTM32meterplatform.
HistogramshowsnoiseequivalenttowhiteGaussiannoiseMeasuredthermalnoise(overallontheboard)degradestheADCresolutionandaccuracyby2to5LSB.
Thismeansthatthenumberofeffectivebitsdropsfrom12tolessthan10.
TorecoverfromthissituationitisnecessarytousetechniquesforNOEB(numberofeffectivebits)enhancement,seeSection1.
9.
Usingoversamplingrequires,insomecases,theadditionoftheditheringsignal.
Accordingtothenoiselevelfoundinthissystem,itisnotnecessarytoaddtheditheringsignal.
It'sadditiondoesnotbringanyenhancementintheperformance.
1.
7CrosstalkbetweensubsequentmultiplexedchannelsWhenreadingmorechannelssubsequentlywithmaximumspeed,valuessampledfromthesubsequentchannelmaybeinfluencedbythereadingofthepreviouschannel.
Thisiscalledcrosstalkbetweensubsequentmultiplexedchannels.
ItiscausedbythebalanceofexternalimpedanceandcapacitanceofasignalsourceandaninternalimpedanceandcapacitanceofthesampleandholdcircuitinthegivenADC.
Thelongerthesampleandholdphase,thelowerthecorrelationbetweensubsequentsamples.
Thetechniquetoovercomethisphenomenonpresentedinthissectionisbasedonreadingeverychannelinthesequencetwiceandonlythesecondvalueistakenasthevalidone.
Theerrorisreducedfrom0.
07%ofADCfullrangetolessthan0.
0001%.
Thetotalconversiontimeiscalculatedasfollows:Equation5Tconv=samplingtime+12.
5cyclesExample2WithanADCCLK=14MHzandasamplingtimeof1.
5cycles:Tconv_14MHz=1.
5+12.
5=14cycles=1sWatt-hourmeterusingtheSTM32AN332212/38DocID18304Rev1Example3WiththesettingusedinthisapplicationADCCLK=9MHzandasamplingtimeof1.
5cycles:Tconv_9MHz=1.
5+12.
5=14cycles=1.
56sTSampling_time=(1.
5cycles/14cycles)x1.
56s=167nsFigure4.
InternalandexternalanaloginputpincapacitorsandresistorsEquation6R129=820andR137=820(resistorsbetweenanoutputofopampandanADCinput)RAIN=R129=R137=820ROpAmp=80=RC=(RADC+RAIN)+ROpAmp)C=1900x12pF=22.
8nsError%=100xexp.
[-1x(TSampling_time/)]FromTable3itisrecommendedtouseeverysecondvaluesampledonthesamechannel.
Thisapproachrendersanerrorcausedbythisphenomenonnegligible.
Table2.
STM32ADCinputcharacteristicsspecificationsSymbolParameterConditionsMin.
Typ.
Max.
UnitRADCSamplingswitchresistance1kCADCInternalsampleandholdcapacitor12pFTable3.
CrosstalkbetweensubsequentmultiplexedchannelsNumberofthesamechannelreadings[-]Tconv[cycle/s]TSampling_time[ns]Error[%]11.
5/1.
551670.
0723.
0/3.
103340.
0034.
5/4.
655010.
0046.
0/6.
206680.
00BJE45.
'YYY7%%"*/Y*-"7753"*/$QBSBTJUJD7"*/7753"%$$"%$CJUDPOWFSUFS4BNQMFBOEIPME"%$DPOWFSUFSDocID18304Rev113/38AN3322Watt-hourmeterusingtheSTM321.
8PowerandenergymeasurementbySTM32embeddedADCThissectiongivesacompleteoverviewofthewholehardwareandfirmwareoftheSTM32powermeterdesign.
Figure5showsablockdiagramofthefirmware,Figure6andFigure7showthephysicalrealizationofthecurrentandvoltagepath.
Figure5.
CompleteblockdiagramofthealgorithmusedinSTM32powermeterFigure5showsthealgorithmflowmeasurement.
AfastmeasurementofthecurrentandvoltagewithinjectednoisefromsurroundingenvironmenttriggeredbynetworksynchronizedtimerDecimationofmeasuredsamplesRMSvaluescomputationUseofapreciseRTCclocksourceforenergycomputation.
Watt-hourmeterusingtheSTM32AN332214/38DocID18304Rev1Figure6showstheconnectorsofthepowermeter(circleswiththenumbers1,2,3,and4)anditsconnectiontothenetworkandloadontheleftsideandvoltageandcurrentmeasurementcircuitontherightside.
VoltagecircuitrydepictedinthisimageshowsthatthevoltagedividerconsistsofresistorsandacapacitoranditisreferencedtoUm(Vmid)voltage,whichishalfof+VREF(2.
5V).
Thevoltagedividerhasagainof0.
0027.
Um(Vmid)voltageisalsomeasuredbythesystem.
Figure6.
VoltagecircuitryofSTM32meter677NJE"7/7447/-_774445.
"%$JO7NJE"%$JO7PMUBHFEJWJEFSHBJOY6FGG7676NBY76HNBY6NBY6NJE6HNBY76NJO6NJE6HNBY773&'7".
DocID18304Rev115/38AN3322Watt-hourmeterusingtheSTM32AcurrentcircuitisdepictedinFigure7.
Thecircuitconsistsoftwostages:Thefirststagewhichamplifies50timesthevoltageacrosstheshuntconnectedtothecurrentterminals(circleswithnumbers2and3)Thesecondstagewhichamplifiesthesignalcomingfromthefirststage.
Thesecondstagehastwopathswithdifferentgain:1and10.
Boththesecondstageoutputs(forgainof1andforgainof10)areconnectedtotheSTM32ADC(ADCin2andADCin3).
Figure7.
CurrentcircuitryofSTM32meterTheintroductionoftwoparallelpathswithinthesecondstagewiththedifferentgainallowstheusertomeasurewithhigherresolutionatthelowcurrentpartofthemeasuredcurrentrange.
Evenwiththetworangemeasurements,anADCenhancementmustbeemployedinordertocoverbothrangeswithdesiredprecision.
Section1.
9describes,indetail,atechniqueforADCenhancement.
1.
9ADCenhancementbyoversamplingtechniqueInordertoreachtherequiredprecisionandresolutionofthesystem,itisnecessarytomaintainthenumberofeffectivebits(NOEB)higherthanthatofferedbytheembeddedADC.
AftertheimprovementofthelinearityandINLreductioninSection1.
5,itispossibletoincreasethenumberofeffectivebitsfrom10bits(seeSection1.
6:ThermalnoisepresentonSTM32meterplatform)uptothe14bitsnecessarytoreachtherequiredprecisionofthewholesystem.
Thetheoryandimplementationoftheresolutionenhancementbyoversamplingisdescribedinaseparatedocumentsuppliedonrequest.
Watt-hourmeterusingtheSTM32AN332216/38DocID18304Rev11.
10OutputvaluesThissectionanditssubsectionstheoreticallycomputeoutputvaluesasURMS,IRMS,P(instantpower),E(energy)andpulseoutput.
Thesevaluesmustbecalibratedlateronbyagainandanoffsetconstantinordertocompensateanimprecisionintheanalogcircuitry.
SomereferencevaluesandconstantsaredefinedADCreferencecircuitTL431givesavoltageof2.
5VUADCref=2.
5VDCoffsetvalueUmidisdeliveredfromUADCref:usingvoltagedividerR116,R117,andR120Umid=UADCrefxR116||R117/(R116||R117+R120)=2.
5x0.
498=1.
245VOneLSBofthe12-bitADCisequalto:LSB12-bit=2.
5V/4096=0.
00061V[V/LSB]ConversionconstantfromItoUforRSHUNT=400is:SHUNT400=2500[1/](1/Uout/IIN=RxI/I=RSHUNT=0.
0004)ConversionconstantfromItoUforRSHUNT=200is:SHUNT200=5000[1/](1/Uout/IIN=RxI/I=RSHUNT=0.
0002)Figure8showsexperimentalmeasurementsofthemaximumoutputsignalfromanoperationalamplifierusedinthecurrentanalogcircuitry.
Itcanbeseenthatthesignalwithpeakvalue(amplitudeofthesinussignalwithDCvalueinthemiddle)higherthan1.
245VisclampedduetothelimitationgivenbyUmid,UADCref.
Figure8.
CurrentcircuitryofSTM32meter,opampsaturationmarkedbyredcircleDocID18304Rev117/38AN3322Watt-hourmeterusingtheSTM321.
10.
1RMSvoltageThevoltageanalogcircuitryisdescribedindetailinthissection.
Mainphasevoltageisreducedbyavoltagedividerdirectlyconnectedtothephasevoltage.
Thevoltagedividerconsistsofaparallelandserialconnectionofthesecomponents:L1+R1+C1||C2+12xR2andR14TheoutputvoltagefromthevoltagedividerisgivenbytheVOLTDIVIDERthatiscomputedfrom:Equation7Rall=R1+12xR2+R14=100R+12x47k+1.
5k=565.
6kEquation8Voltagedivisionis:VOLTDIVIDER=[-]VOLTDIVIDERconstantmeansthattheinputvoltageisdividedbynumber377.
Voltagerepresentedinvoltsiscomputedby:Equation9ULSBinLSB-actualoutputofADCchannelUVinvolts-outputfromMETERUV=CUxULSBThecalibrationconstantforthevoltagecircuitryconsistsof:Equation10CU=VOLTDIVIDERxLSB12-BITxV_IMPRECISIONwhereLSB12-BITisdefinedinSection1.
1:STM32ADCparameters,V_IMPRECISIONistheimprecisionandtoleranceofthecomponentsusedinanalogcircuitry,mainlyresistorsandsoldering.
Sincewewantthesmallestvaluetobe1V,wemustmultiplyeverythingby1.
000.
000additionally.
Thisalsohelpstomaintainthepreservationoftheprecision.
Inordertosavethemicrocontrollercomputationalpowerandtokeepprecisionashighaspossible,itisbeneficialtoavoiddivisionoperationduringallthecomputationsduringaperiodanddoitasthelaststepaftereveryperiodcomputation.
AccordingtoSection1.
9:ADCenhancementbyoversamplingtechnique,duringoversampling,thesumof18samplesfromADCresultsastheVSUMvaluerepresentingmeasuredvoltagewithhigherprecision.
ComputationofthevoltageRMSvaluetakes44VSUMvalues.
Theymayonlybesquared,thensummed,andfinallytheycanbedividedbycommondecimationandRMSconstant.
R14Rall1,5k565,6k-0,002652==Watt-hourmeterusingtheSTM32AN332218/38DocID18304Rev1AstandardcomputationofthedecimationandRMSvaluecomputationEquation11V(i)=1/18xSUM[U(i)]URMS=1/44sqrt[V(i)]2ComputationwithdelayeddivisionsavingthecomputationalpowerandtheprecisionEquation12VSUM=SUM[U(i)]URMS=1/÷44x1/÷18xsqrt(SUM{SUM[U(i)](y)}2)Thefinalvaluemustbedividedby28.
1424(or28142ifthevaluesareinmillivolts)ormultipliedby0.
035533(or0.
000035533ifthevaluesareinmillivolts).
Figure9.
Voltagecircuitry-calibrationCUconstantcomputation1.
10.
2RMScurrent-highgainedCurrentanalogcircuitryisdescribedindetailinthissection.
Mainphasecurrentismeasuredasavoltageonsmallresistance-shunt.
Theshunt(R142)convertingcurrenttothevoltagetobemeasuredhasavalueof:1.
2002.
400Thevoltagefromtheshuntisamplifiedbythefirststageofthecurrentamplificationwithagainof50.
Forcurrentthatneedsfurthergain,anadditionalgainof10isadded.
Ifapathwiththeadditionalmultiplication10isused,allthevariableshaveindexHG(highgain).
Thecompletegainis50x10=500times.
ThevalueobtainedaftertheamplificationmustbemultipliedbyOPAMPGAINHGinordertogettheoriginalvalue.
Equation13OPAMPGAINHG=0.
002IAHG=CIHGxILSBHGwhereILSBisthevalueinLSBfromADCandIAisthecurrentinamperes.
CIHG=SHUNT400xOPAMPGAINHGxLSB12-BITxHG_IMPRECISION[A/LSB]WhereSHUNT400andLSB12-BITweredefinedinSection1.
1:STM32ADCparameters.
HG_IMPRECISIONistheimprecisionandtoleranceofthecomponentsusedintheHGpathofanalogcircuitry;mainlyresistorsandsoldering.
'LYLGHU9!
9$'&9!
/6%&RUUHFWLRQ/6%!
9'HFLPDWLRQ506FRPSXWDWLRQGLYLVLRQ$0DocID18304Rev119/38AN3322Watt-hourmeterusingtheSTM32Sincewewantthesmallestvaluetobe1A,wemustmultiplyeverythingby1.
000.
000additionally.
Nodecimation,shiftsordivisionareperformedduringcomputationinordertopreserveprecisionandreducemicrocontrollercomputation.
Thecorrectmultiplicationordivisionisdoneattheendofthewholecomputationalchain.
Thefinalvaluemustbedividedby28.
1424(or28142ifthevaluesareinmilliamperes)ormultipliedby0.
035533(or0.
000035533ifthevaluesareinmilliamperes).
Figure10.
Currentcircuitry-calibrationCIconstantcomputation1.
10.
3RMScurrent-lowgainedThebasicgainofthecurrentinputis50.
Thereisanadditionalgainof1.
Ifthepathwiththeadditionalmultiplication1isused,allthevariableshaveindexLG(lowgain).
Thecompletegainis:Equation14OPAMPGAINLG=0.
02IALG=CILGxILSBLG[A]=[A/LSB]x[LSB]whereILSBisthevalueinLSBfromADCandIAisthecurrentinamperes.
Equation15CILG=SHUNT400xOPAMPGAINLGxLSB12-BITxLG_IMPRECISIONwhereSHUNT400andLSB12-BITweredefinedinSection1.
1:STM32ADCparameters.
LG_IMPRECISIONistheimprecisionandtoleranceofthecomponentsusedintheLGpathofanalogcircuitry;mainlyresistorsandsoldering.
ThefinalcomputationisdescribedinSection1.
10.
4:Power,Section1.
10.
5:Energy,andSection1.
10.
6:Pulseoutput.
1.
10.
4PowerInstantpoweriscomputedby:Equation16p=i(t)xu(t)PW=(CIxCU)xIINxUINPW=CPxIINxUIN6KXQW$!
92SDPS9!
9$'&9!
/6%&RUUHFWLRQ/6%!
$'HFLPDWLRQ506FRPSXWDWLRQGLYLVLRQ$0Watt-hourmeterusingtheSTM32AN332220/38DocID18304Rev1EventheCPistheoreticallyequalto(CIxCU);CPissetduringthecalibrationprocessasaconstantbetweenasuppliedinstantpowerPTheorandtheinstantpowerPWmeasuredbytheSTM32powermeter.
Equation17PTheor=CPxPWThedifferencebetweenCPgivenbythecalibrationprocessand(CIxCU)isgivenbythephaseshiftthat,evenwhencarefullycompensated,doesstillnothaveanegligibleinfluenceonthecomputationofthepower.
TheinstantpoweroveroneperiodofmainsPWcanbecomputedalsofromtheenergyEtakenoveroneperiodofmainsequalto20ms:Equation18Equation19wheretSisthesamplingperiodforu(t)andi(t).
tistheperiodofmainsequalto20ms.
Inordertoreachthedesiredprecisioninthepulsegeneration,PWandalltheenergyvaluesarecomputedinW.
1.
10.
5EnergyEnergyiscalculatedasaproductofcurrentIIN,voltageUIN,timeTtimerandpowercalibrationconstantCP(Ttimer-timeinseconds).
Equation20EWh=CPxIINxUINxTtimerInordertosavethemicrocontrollercomputationalpower,thepreviouslycomputedinstantpowerPWcanbeusedtogetenergy.
Equation21EWh=PWxTtimerEquation22Equation23Eutittstsutitt44------utit===PWEt--------1t-----t44------utit144------utit===Efragment144------utitts144------tsutit144------t44------utit====144------t44------utit=Efragment144------tP=DocID18304Rev121/38AN3322Watt-hourmeterusingtheSTM32Tokeepenergyresolutionupto1mW,weneedpowertobespecifiedby25bitsormore.
Inordertoreachdesiredprecisioninthepulsegeneration,EfragmentandalltheenergyvaluesarecomputedinWs.
1.
10.
6PulseoutputInordertoreducejitterwhengeneratingthepulseoutputsignal,thefollowingalgorithmisused:Theenergyiscomputedonceperperiodofmains(i.
e.
every0.
02s)EWhTheenergycomputedisdividedby44.
EfragmentWh=EWh/44ThisfragmentisaddedtotheaccumulatoreverytimetheADCistriggered(44timesperoneperiodofmains)thatisequalto2.
2kHzWhenevertheaccumulatorsurpassesacertainlevel,ETHR,impulsethreshold,thepulseLEDistoggledandtheETHRisdistractedfromtheaccumulatorInordertoreachdesiredprecisioninthepulsegeneration,ETHRandalltheenergyvaluesarecomputedinWs.
Thepulseconstant(thenumberofpulsesgeneratedperconsumedkWh)issetbythemanufacturer.
Example4ImpulseconstantKissetbythemanufacturerto:K=3200impulses/kWhRelationbetweenjoulesandwattspersecondisthefollowing:Wxs=JWxh=3600JkWxh=3.
600.
000J1kWxh=3.
600.
000.
000.
000WxsInordertobeabletosetcorrectlyETHR,itisnecessarytoknowthat1impulsemeans:3200impl.
1kWh1impl.
XkWh3200impulses=1kWh=3.
600.
000JTheenergyofoneimpulseEIMPLis:x=EIMPL=1kWh/K[imp/impl/kWh]=3.
600.
000.
000.
000/K[Ws]EIMPL=1125J=1125WsEIMPL=1.
125.
000.
000WsBecausetheLEDistoggledbyreachingtheETHRvalue(impulse-threshold),thegenerationofonecompletepulse(risingandfallingedge)requirestwoevents(twotimesreachingETHRwithinEIMPLstep).
Itisnecessarytodividethethresholdconstantfor1implEIMPLbytwo:ETHR=EIMPL/2=1.
125.
000.
000/2=562.
500.
000WsComputationalissuesandcompensationalgorithmsAN332222/38DocID18304Rev12ComputationalissuesandcompensationalgorithmsThissectiondealswithissuesthatcaninfluencemeasurementsandcomputationandwerenotmentionedinSection1.
4:ErrorsourcesontheSTM32meter.
Thetopicscoveredinthissectiondealwithcoherentsampling,precisefrequencymeasurement,properzerocrossingdetectionandphaseshiftcorrection.
Thecorrectapproachusedwhendealingwiththistopicleadstotheprecisionimprovementandmakesitpossibletokeepprecisionintherequiredrange.
Coherentsamplingisthesamplingoftheperiodicalsignalwherethenumberofthesamplesperperiodofthesignalisstillthesame.
Thesamplingtimeofthefirstsampleisstillinthesametimepositioninrelationtothephaseofthesampledsignal.
Thetimingofthefollowingsamplesisstillthesameandconstant.
Inthiscase,44samplesperperiodofthemains(50Hz,period20ms)arealwayskept.
Non-coherentsamplingis,onthecontrary,thesamplingoftheperiodicalsignalwherethenumberofthesampleperperiodofthesignalisnottheintegernumber.
Thesamplingdoesnotneedtostartinthesamepositioninrelationtothephaseofthesampledsignal.
Thetimingofthesubsequentsamplescanvary.
Forexample,44.
76samplesperperiodofmainsareacquired.
Itmeansthatthesamplerateisabithigherthanrequiredinthecaseofcoherentsampling.
2.
1Non-coherentsamplingissuesIfnon-coherentsamplingispresent(itmeansnointegernumberofsamplesperperiodofmainsistaken),itispossibletoobserveanadditionaldisruptingsignalinthegraphofcomputedinstantpowerfromsuchsampledcurrentandvoltage.
Theadditionaldisruptingsignalconsistsoftwofrequencies:ahighfrequencyFHandalowfrequencyFL.
Figure11.
Instantpower(1)1.
Y-axis:voltage,X-axis:cyclesofmains/100(50Hz).
Whenusingthenon-coherentsampling,themeasuredperiodofthesignalisnotcompletelycoveredandeveryperiodandthiscoveragediffersfromperiodtoperiod.
TheamountoftheDocID18304Rev123/38AN3322Computationalissuesandcompensationalgorithmspowercomputedfromthesesamplesisnotthesameforeveryperiodofmains.
ThiscausestheparasiticsignalwiththefrequencyFH.
Aftersometime(Tx)thecoverageoftheperiodisthesameasitwasatthebeginning(inrelationtothephaseofthemeasuredsignal).
ThistimeTxistheperiodofthefrequencyFH.
Figure12.
ParasiticfrequencyFHindetail(1)1.
Y-axis:voltage,X-axis:cyclesof50Hz.
Inthisexample,thesamplingof44samplesperperiodissynchronizedwithafrequencyof49.
93785Hz.
Duringeveryperiodofthemains,thelastsampleisdisplacedbytimeTdiff_sample.
Equation24Tdiff_sample=1/50Hz-1/49.
93785Hz=0.
00002489sIneverycycleofthemains,allthesamplesareshiftedbyTdiff_sample.
TheyagainpasstheirinitialpositioninthetimeTshift.
Equation25Tshift=(1/50Hz)/Tdiff_sample=803.
5cycles(of50Hz)Sincethecomputedinstantactivepowerisafunctionwithdoublethefrequencyoftheinputvoltageandcurrent(negativeinstantvoltageandnegativeinstantcurrentagaingiveinstantpositivepower),theTshiftshouldbedividedbytwo:Equation261/FH=(803.
5/2)*0.
020s=8.
035sThatthespecificsampleagainpassesitsinitialpositiondoesnotmeanthatitisexactlyinthesameposition.
Thishappensafterevenmorecyclesofmains.
ThiscausesthefluctuationoftheinstantpowerbyadditionaldisruptionofsignalwithFL.
TheperiodofFLis,inthisexample,17,500cyclesofmainsthatisequalto350s(obtainedbyasimulation).
ThejitterininstantpowerbringsjittertotheaccumulatedenergyvaluethatbringsthejittertotheLEDpulseoutputgeneration.
Inordertoobtaincorrectinstantpower,duringeveryperiodofthemains,oroverashortperiodoftime,itisnecessarytoprovidecoherentsampling.
ComputationalissuesandcompensationalgorithmsAN332224/38DocID18304Rev12.
2TimerevaluationforcoherentsamplingtriggeringInordertointroducecoherentsamplingintothesystem,itmustbeevaluated,ifthetimeranditsresolutionispreciseenoughtoensurepreciseoutputs(instantpower,RMSvoltageandcurrent).
Thissectionevaluatesthequalityofthesynchronizationwiththenetworkwhichispossiblewiththegivensystem.
Itevaluateserrorsinrespecttothedistancefromidealsynchronizationtothenetwork.
Samplingfrequencyfor44samplesper20ms(peronecycleofmains50Hz)resultsintheADCsampletimeof454.
5s.
TheSTM32timerusedforsynchronizationwiththenetworkandfortriggeringoftheADCsamplingisa16-bittimer.
Thistimerhasatimestampgenerationresolution:27.
777nswhentheSTM32isrunningon36MHz.
PrecisionofsamplingfrequencygenerationOnecycleof50Hzcanbedividedexactlyinto720.
000stepswhenusingthegiventimer.
Thetimergenerates16363timestampeventswithintwosubsequentsamplingtriggersoutof44.
Theerrorofthetriggergenerationforonesamplepositionis:Equation271/16363=0.
000061=0.
0061%~0.
01%ExperimentalresultsinFigure13showtheinfluenceofthesamplinginstantgenerationcorrectnessontheinstantpowererror.
Table4.
Precisionvs.
timersetting.
Simulatedonsignalu(t)=sin(2xpix50xt)Distancefromidealsampling(timersteps)Sampletimeerror(%)URMS(V)ErrorURMS(%)Pat1(W)ErrorP(%)10.
00890.
7070750.
0040.
4999560.
009100.
08890.
7067940.
0440.
4995570.
0891000.
88890.
7039840.
4430.
4671890.
8815004.
44440.
6923072.
0930.
4792904.
14210008.
88880.
6819743.
5540.
4650896.
982140612.
49650.
6788743.
9930.
4608707.
826281224.
99560.
7015480.
7860.
4921701.
566421837.
48950.
724468-2.
4550.
524853-4.
9715625(1)1.
5625=11250/2isexactlyhalfofthesamplingperiod,sotheerroriszero.
Table4wascomputedforthesamesettingtaking64samplesperperiodinsteadof44.
For44samplespersecond,theerrorsindicatedareevenlower,seethetextaboveTable4.
50.
00000.
7071070.
0000.
5000000.
000DocID18304Rev125/38AN3322ComputationalissuesandcompensationalgorithmsFigure13.
ErrorofURMSvs.
thetimererrorintimerticksFigure14.
ErrorofURMS(1)1.
DetailofFigure13(zoominx-axis).
Table4showsthattheprecisionofthetimerresolutionisenoughtomakecoherentsamplinginordertoreachtherequirementsforprecision.
Thereisnoneedforadditionalcorrectionorapproximationofthesamples,unlessthefuturerequirementsforthehigheraccuracyclassofthemeterappear.
Thesystemisalwaysabletosynchronizetothenetworkfrequencywiththeerrorofthethreestepsofthetimerconstants.
ThisleadstotheerrorofURMSthreetimes0.
004%(accordingtoTable4)(thatmeansanerrorURMSvalueof0.
012%).
Thisisstilltentimeslowerthanotherinfluencestothesystemthatcanaffectoverallprecision.
2.
3TimersettingconstraintsforcoherentsamplingtriggeringTheautomaticsystemthatisimplementedtosynchronizesamplingwiththenetwork(negativefeedbackintroducedinSection2.
4)setsoneparameter.
Thisparameteristhereloadconstantofthetimerforsamplingtriggering.
Allowedvaluesofthisconstantshouldbelimitedtoanintervalavoidingincorrectsystembehaviorincaseitissettoaverydifferentvaluefromtheidealone.
ThelimitsofthetimerreloadconstantarecomputedfromvariationoftheSTM32microcontrollermainsystemclockandfromallowedvariationofthenetworkfrequencyprescribedbyinternationalstandards.
Sampletimeprecision(stepsof16-bittimeratthe36MHzSTM32device)Sampletimeprecision(stepsof16-bittimeratthe36MHzSTM32device)ComputationalissuesandcompensationalgorithmsAN332226/38DocID18304Rev1Tosetthecorrectlimits,itisnecessarytocombinethemaximumerrorofHSIandnetworkfrequencyvariation:Max.
HSIerror=±3%Max.
50Hzvariation=±2%Themax.
deviationfromcorrectfrequencyis±5%.
Themainssignalissampled44timesperperiodofmains,thisresultsinthesamplefrequencyFS:Equation28FS=50Hzx44samples=2200HzFSequaltotimerconstantCTimerthatisderivedfrommainsystemclock.
CTimer=36.
000.
000Hz/2200Hz=16363Themaximumandminimumvaluesforthetimerconstantare:CTimer-MAX=CTimerx105%=17182CTimer-MIN=CTimerx95%=15545Thetimerconstantcanbesetfromoneborder(CTimer-MAXorCTimer-MIN)tothecentervalue(CTimer)after818stepswhenupdatingtheconstantbyoneeverycycleofmains.
Thatis818x0,02s=16seconds(correctionisdoneeverysecondperiodofthesignal,so,infact,thePLLtakes32secondstogetfromtotalbordertocenter).
Thisistoolong,soitisnecessarytoimplementfasteriteration.
Section2.
4showsafastlockingalgorithmforsynchronizationwiththemains.
2.
4PrecisetimersettingforcoherentsamplingAllthecomputation(RMScurrent,RMSvoltage,instantpower)andtheconversionoftheinstantpowerintoenergyneedscorrecttimingandtheinfluenceoftheSTM32mainclockmustbetakeninaccount.
ThehighspeedinternalRCoscillator(HSI)inaccuracy(overalongperiod)isnotanissue,sincethefrequencyismeasuredandupdatedeveryperiodofmainsandthetimerissetaccordingly.
Table5.
Highspeedinternal(HSI)RCoscillatorSymbolParameterConditionsMin.
Typ.
Max.
UnitfHSIFrequency8MHzACCHSIAccuracyoftheHSIoscillatorUser-trimmedwiththeRCC_CRregister1%FactorycalibratedTA=–40to105°C–22.
5%TA=–10to85°C–1.
52.
2%TA=0to70°C–1.
32%TA=25°C–1.
11.
8%DocID18304Rev127/38AN3322ComputationalissuesandcompensationalgorithmsThemetershouldbeabletomeasureandcorrectthemainsfrequencyfluctuationof±2%;itmeansfrom49to51Hzaccordingtotheinternationalstandard.
TheHSIRCoscillatorhasafrequencyfluctuation±3%(eventheinternalHSIcanbecalibratedbyRTCtoaccuracy±1%)overthewholetemperaturerange(thevalue±3%isusedforcomputationastheworstcase).
IfthecombinationofthemaximumnetworkfrequencyvariationandmaximumHSIfrequencyvariationis±5%,itmeansfrom47.
5to52.
5Hz.
Themetermustbeabletoadapttothisvariationandmeasurecorrectlyinthisrangeofvalues.
Allthecomputationforprecisetimingisupdatedonlywheninputvoltageishigherthan50V.
Apossiblevoltagedropoversomeperiodscanbringafrequencydetectionerror.
Theinternationalstandardsallowincorrectmeasurementduringtheperiodofthetimewhenvoltageisunder80%ofitsnominalvalue.
Thealgorithmfortheprecisetimersettingusesthemainszerocrossinginformation.
Inordertokeepthewholenumberofthesamplesperperiodofthemains,thepositivezerocrossingofthemainsmuststillappearinthesamepositioninthesampleddataarray(forexample:ifwedetectzerocrossingatthe4thsampleoutof44,inthenextperiodofmainsthezerocrossingmustappearinthesameposition,itmeansthe4thsampleoutof44).
Thesampletriggeringtimerconstantmustbeupdatedtokeepthezerocrossingatthesamesampleindex.
Thetimerconstantisupdatedonlyifthezerocrossingisdifferentfromthepreviousone.
Ifthedifferenceispositive,thetimerconstantisupdatedby-1,ifthedifferenceisnegative,thetimerconstantisupdatedby+1.
Thisnegativefeedbacklocksthesamplingfrequencytothefrequencyofmains.
Thesamplingfrequencydifferencerepresentedbyonesample(44samplesperperiodof50Hz)is1.
16Hz(whichis2%).
Ifthetimersettingdiffersfrommainsbylessthan2%,thedifferenceinzerocrossingpositionappearsaftermanycyclesofmains(thelowerthedifference,themorecyclesthereare).
Ifwereactonlybyaddingorsubtractingvalue1fromthetimerconstantonlywhenthedifferenceisonewholesample,thefrequencylockinglastsfor225steps(overthewholerange-seethebeginningofthissection).
Morethan5sisneededtostabilizethezerocrossingsampleindexvaluetolessthanonebetweendirectlysubsequentperiodsofmains.
Furthermore,afterthatsynchronizationperiod,ifthedifferenceislowerthanonewholesampleindex,theupdateofthetimerisdoneafterthedifferenceappearsovermoreperiodsandreachesonesampleindex.
Typically,thelock-intimeisabout30secondsadditionally.
Reductionofthenecessarytimeforzerocrossingstabilization(synchronizesthesamplingwiththemainsfrequency)canbedonebyintroducingasampleindexdivisioninordertogetfinerandfasterzerocrossingstabilization.
Usingthistechnique,thelock-inalgorithmneeds1-2secondstofullysynchronizesamplingwiththenetwork.
ComputationalissuesandcompensationalgorithmsAN332228/38DocID18304Rev1Afterdetectionofthezerocrossingpositioni,thefinerzerocrossingiscomputedaccordingtoFigure15,Equation29andEquation30.
Figure15.
FinercalculationofzerocrossingEquation29di=bi/(abs.
ai+abs.
bi)Equation30c+d=1whereaiistheamplitudeofthesignalpriortoazerocrossing,andbiistheamplitudeofthesignalafterthezerocrossing.
Thesubindexpositiondicomputedisintherangefrom0to1.
Thedifferenceofthetwosubsequentzerocrossingsisdi-di+1.
ThevalueTupdatethatcanbeaddedorsubtractedfromthetriggertimerreloadconstantmustbeanintegernumberbiggerthatone.
Thedifferencecanbedividedinto20stepsbytheroundingofTupdate=[20x(di-di+1)].
Thisleadstoadivisionofthepositionindexofthezerocrossingto20subvalues.
Thetriggertimerreloadconstantisupdatedbythisdifferencetostabilizethezerocrossinginthisfinerposition.
Thismakesinitiallockingfaster(byfactor20).
AsdescribedinSection2.
6,thesignalusedforzerocrossingdetectionisfilteredsothatonlyfundamentalfrequencyispreset.
Thisavoidserrorswhencomputingthezerocrossingpositionfinerthatonesampleindex.
2.
5FrequencymeasurementThefrequencyvalueisderivedfromthecoherentsamplingtriggerperiod.
Thesamplingtriggerperiodismeasuredusingapreciseexternallowspeedoscillator(LSE).
Fromthatvaluethefrequencyiscomputed.
Inordertogetahigherresolutionofthemeasuredfrequencyvalue,morevaluesmustbeaccumulatedandaveraged.
Theaccumulationoftenvaluesbringstheresolutionthatissufficientandcanbedisplayed.
EDFG$0DocID18304Rev129/38AN3322Computationalissuesandcompensationalgorithms2.
6FilteringofinputsignalforproperzerocrossingdetectionProperdetectionofthezerocrossingisthekeyparameterinordertomeasureandcomputeallthevaluescorrectly.
Possibleproblemsarecausedwhenthevoltagechannelcontainsmoreharmonicsandsuchasignalwiththeseharmonicscrossesthezerovoltagelinemoretimes.
Figure16showsthevoltagesignalthatiscrossingthezerolinetwice.
Thesamesituationcanbecausednotonlybyhigherharmonicsbutalsobynoisepresentinallthecircuitry.
Figure16.
VoltagesignalcrossingzerovoltagelinetwiceInordertoavoidanincorrectzerocrossingdetection,afilterwasintroduced.
Thefilteristhesimplemovingaverage.
Thelengthofthefilteris18.
Sincethenumberofthesamplesperperiodofmainsis44,thefilterremovesalltheharmonicsstartingat50Hzwithgrowingattenuation.
Figure17showsthesignalafterthefilteringthatallowsforfailure-lesszerocrossingdetection.
Figure17.
VoltagesignalusedforcorrectzerocrossingafterproperfilteringComputationalissuesandcompensationalgorithmsAN332230/38DocID18304Rev1Sincethevoltagesignalwithverylowamplitudecanleadtoincorrectzerocrossingdetection,thezerocrossingdetectionisnotperformedonthevoltagesignalwithanamplitudelowerthat50V.
Themeasuredfrequencyandlockingtothezerocrossingisnotupdatedinthiscase.
2.
7PhaseshiftcorrectionThissectiondescribeshowtodealwithphaseshiftintheanalogcircuitryoftheSTM32powermeter.
TheevaluationoftheerrorcausedbyphaseshiftandthelevelsofitscorrectioniscomputedinSection2.
7.
1,Section2.
7.
2,andSection2.
7.
3.
2.
7.
1PhaseshiftmeasuredfortheSTM32meterThephaseshiftthatneedstobecompensatedwasmeasureddirectlyintheSTM32meter.
Thesevalueshelptosetthelimitsandresolutionofthephaseshiftcompensationmethod.
Figure18.
Zerocrossingforgreen-U,blue-ILG,red-IHGFigure18showsthatthereisadelaybetweenvoltageUandcurrentsILGandIHG.
ThisdelaybetweenUandILGorbetweenUandIHGisinthesamerangeforbothrangesanditis5-8s.
Thisdelayismainlycausedbythecapacitanceandinductanceinthesignalpathoftheinputvoltagedivider(seeSection2.
10).
2.
7.
2Phaseshiftcorrection-errorevaluationThephaseshiftbetweenvoltageandcurrentisalsocausedbynon-simultaneoussamplingofthesevalues,seeSection1.
9.
DocID18304Rev131/38AN3322ComputationalissuesandcompensationalgorithmsThevoltageandILareshiftedbytwosamples:Equation31Tshift_I_L~2samples~3s~0.
05deg.
ThevoltageandIHareshiftedbyfoursamples:Equation32Tshift_I_H~4samples~6s~0.
1deg.
Table6showswhatlevelofthephaseshiftcorrectionisnecessarytobereachedinordertolowertheerrorcausedbythephaseshifttoanacceptablevalue.
Itcanbeseenthatweneedtocorrectthephaseshifttoavaluelowerthan0.
1deg.
ThisvaluecanbeeasilyreachedbythephaseshiftcompensationfilterintroducedinSection2.
7.
3,compensatingwiththestepof0.
013deg.
Thevalue0.
013deg.
allowsnegligibleerroroftheinstantpowercausedbythephaseshifttobereached.
DatafromTable6aredepictedinFigure19,Figure20,andFigure21.
Table6.
ErrorofinstantpowercausedbyphaseshiftSamplingtimetriggershiftedby[deg.
]Errorofinstantpower[%]forPF=1Errorofinstantpower[%]forPF=0.
50.
010.
0000020.
0302320.
020.
0000060.
0604660.
050.
0000380.
1512000.
10.
0001520.
3025000.
20.
0006090.
6052000.
50.
0038081.
51530010.
0152303.
03810020.
0609176.
10570050.
38050015.
476300ComputationalissuesandcompensationalgorithmsAN332232/38DocID18304Rev1Figure19.
ErrorofinstantpowerforPF=1andPF=0.
5Figure20.
ErrorofinstantpowercausedbyphaseshiftforPF=13KDVHVKLIWEHWZHHQ8DQG,>GHJ@(UURURILQVWDQWSRZHU>@IRUGHJIRUGHJ$0)RUSRZHUIDFWRUDQG>FRVGHJ@3KDVHVKLIWEHWZHHQ8DQG,>GHJ@(UURURILQVWDQWSRZHU>@IRUGHJIRUGHJ$0DocID18304Rev133/38AN3322ComputationalissuesandcompensationalgorithmsFigure21.
ErrorofinstantpowercausedbyphaseshiftforPF=0.
52.
7.
3Phaseshiftcorrection-filterimplementationThephaseshiftinthetimedomainisnotassimpleasinthefrequencydomainorinasystemwheremoreADCareemployedforcurrentandvoltagemeasurements.
InthisHWimplementationweneedtouseanapproachthatallowsuseffectivelyinterpolatevaluesofthevoltagesothattheyarecorrectlyalignedtocurrent.
Thisapproachisdescribedinaseparatedocumentsuppliedonrequest.
Thephasecompensationrangethatmaybereachedwiththisapproachis:Withthestepof0.
73s(0.
013deg.
)Maximumpositiveshift=-6.
2s(0.
11deg.
)Maximumnegativeshift=+6.
2s(0.
11deg.
)Withthestepof0.
77s(0.
014deg.
)Maximumpositiveshift=-12.
4s(0.
22deg.
)Maximumnegativeshift=+12.
4s(0.
22deg.
)Whenahighervalueofthephaseshiftneedstobecompensated,anextensiontothemethodusedisintroduced.
2.
8CalibrationprocedureCalibration(computationofthecorrectionfactorbetweenmeasuredandexpectedoutput)isaveryimportantprocessanditscorrectperformanceresultsintheoveralldesiredprecision.
Evenwhenthepowermetermeasuresthecurrentandvoltagewiththemaximumerror0.
5%,weneedtoperformcalibrationonanevenhigherlevelofaccuracy.
Ifthisisnotdone,calibratethemeterwiththeerrorof0.
5%,intheworstcase(overthewholemeasuredrange)themaximumerrormaybeanadditional0.
5%,whichresultsinanerrorof1%(0.
5+0.
5)intotal.
Thismeansthatthemeasuredvalueshouldbeusedforcalibrationafteritserroristhelowestpossible.
Thishappensafteraveragingthevalueoveralongerperiod)RUSRZHUIDFWRU3KDVHVKLIWEHWZHHQ8DQG,>GHJ@(UURURILQVWDQWSRZHU>@IRUGHJ$0ComputationalissuesandcompensationalgorithmsAN332234/38DocID18304Rev1oftime.
Calibrationisperformed,inthiscase,afterthecollectionofdata(RMSvoltage,RMScurrent,instantactiveandreactivepower)over64periodsofmains(abitmorethanonesecondor50Hz).
Iftheerrorduringthecalibrationprocessreducesto0.
1%,intheworstcasethereisanerrorof0.
6%,(0.
1+0.
5)intotaloverallthetests.
Thecalibrationprocedureconsistsofthesesteps:1.
ConnectingtheSTM32metertoprecisepowersupply.
2.
Settingnominalcurrentforlowerrange(5A)currentandnominalvoltage(230V).
3.
Afterthepowersupplystabilizes(refertothevoltageandcurrentsourcespecifications),waitforanadditionaltwosecondsatleast(inordertocollectenoughcalibrationdata).
4.
Pressingthebutton(number4)onthemeterkeyboard.
5.
Settingnominalcurrentforhighermeterrange(40A)andnominalvoltage(230V).
6.
Afterthepowersupplystabilizes(refertothevoltageandcurrentsourcespecification),waitforanadditionaltwosecondsatleast(inordertocollectenoughcalibrationdata).
7.
Pressingthebutton(number4)onthemeterkeyboard.
8.
Afterthisprocedure,allthecalibrationsarewrittenintoEEPROMandloadedaftereverypower-upofthepowermeter.
2.
9ReactiveandapparentpowercomputationThereactivepowercanbecomputedsimplybyQ=S2+P2orbyusingafilteringmethod.
Sincethefirstmethodhasitslimitations,thefilteringapproachisintroduced.
Thisapproachisdescribedinaseparatedocumentsuppliedonrequest.
DocID18304Rev135/38AN3322Computationalissuesandcompensationalgorithms2.
10Analogpartschematic-part1Figure22.
Analogpartschematic-part11.
Thecomponentisoptionalandtheusercanfinetuneitsvalueaccordingtotheirrequirements.
9UHI559665&Q)9PLG9PLG8&Q)/9PLG8&76,'555596.
555558$76,'59669&&8'76,'55559669&&5559669&&,D,'//'//9&&9665555555&&9UHIZH*1'Z\/(0,VXSSUHVRU5591919159PLG5555-9PLG5555-'//'//9&&966,D,3359PLG-9PLG5RJRZVNL&S)&S)966'5'5'5'5'5'5'5'5'5'5'5'593&Q)13&Q)13&966$0ComputationalissuesandcompensationalgorithmsAN332236/38DocID18304Rev12.
11Analogpartschematic-part2Figure23.
Analogpartschematic-part2&Q)&Q)55966&Q)9&&9PLG&58%76,'5:9UHI33587/&96659&&&Q)&9669&&&9665$0DocID18304Rev137/38AN3322References3ReferencesImprovingADCResultsThroughOversamplingandPost-ProcessingofData.
(n.
d.
).
Retrieved2009,fromActel:www.
actel.
com/documents/Improve_ADC_WP.
pdf.
AN2668-applicationnote.
4RevisionhistoryTable7.
DocumentrevisionhistoryDateRevisionChanges13-May-20131Initialrelease.
AN332238/38DocID18304Rev1PleaseReadCarefully:InformationinthisdocumentisprovidedsolelyinconnectionwithSTproducts.
STMicroelectronicsNVanditssubsidiaries("ST")reservetherighttomakechanges,corrections,modificationsorimprovements,tothisdocument,andtheproductsandservicesdescribedhereinatanytime,withoutnotice.
AllSTproductsaresoldpursuanttoST'stermsandconditionsofsale.
Purchasersaresolelyresponsibleforthechoice,selectionanduseoftheSTproductsandservicesdescribedherein,andSTassumesnoliabilitywhatsoeverrelatingtothechoice,selectionoruseoftheSTproductsandservicesdescribedherein.
Nolicense,expressorimplied,byestoppelorotherwise,toanyintellectualpropertyrightsisgrantedunderthisdocument.
IfanypartofthisdocumentreferstoanythirdpartyproductsorservicesitshallnotbedeemedalicensegrantbySTfortheuseofsuchthirdpartyproductsorservices,oranyintellectualpropertycontainedthereinorconsideredasawarrantycoveringtheuseinanymannerwhatsoeverofsuchthirdpartyproductsorservicesoranyintellectualpropertycontainedtherein.
UNLESSOTHERWISESETFORTHINST'STERMSANDCONDITIONSOFSALESTDISCLAIMSANYEXPRESSORIMPLIEDWARRANTYWITHRESPECTTOTHEUSEAND/ORSALEOFSTPRODUCTSINCLUDINGWITHOUTLIMITATIONIMPLIEDWARRANTIESOFMERCHANTABILITY,FITNESSFORAPARTICULARPURPOSE(ANDTHEIREQUIVALENTSUNDERTHELAWSOFANYJURISDICTION),ORINFRINGEMENTOFANYPATENT,COPYRIGHTOROTHERINTELLECTUALPROPERTYRIGHT.
STPRODUCTSARENOTAUTHORIZEDFORUSEINWEAPONS.
NORARESTPRODUCTSDESIGNEDORAUTHORIZEDFORUSEIN:(A)SAFETYCRITICALAPPLICATIONSSUCHASLIFESUPPORTING,ACTIVEIMPLANTEDDEVICESORSYSTEMSWITHPRODUCTFUNCTIONALSAFETYREQUIREMENTS;(B)AERONAUTICAPPLICATIONS;(C)AUTOMOTIVEAPPLICATIONSORENVIRONMENTS,AND/OR(D)AEROSPACEAPPLICATIONSORENVIRONMENTS.
WHERESTPRODUCTSARENOTDESIGNEDFORSUCHUSE,THEPURCHASERSHALLUSEPRODUCTSATPURCHASER'SSOLERISK,EVENIFSTHASBEENINFORMEDINWRITINGOFSUCHUSAGE,UNLESSAPRODUCTISEXPRESSLYDESIGNATEDBYSTASBEINGINTENDEDFOR"AUTOMOTIVE,AUTOMOTIVESAFETYORMEDICAL"INDUSTRYDOMAINSACCORDINGTOSTPRODUCTDESIGNSPECIFICATIONS.
PRODUCTSFORMALLYESCC,QMLORJANQUALIFIEDAREDEEMEDSUITABLEFORUSEINAEROSPACEBYTHECORRESPONDINGGOVERNMENTALAGENCY.
ResaleofSTproductswithprovisionsdifferentfromthestatementsand/ortechnicalfeaturessetforthinthisdocumentshallimmediatelyvoidanywarrantygrantedbySTfortheSTproductorservicedescribedhereinandshallnotcreateorextendinanymannerwhatsoever,anyliabilityofST.
STandtheSTlogoaretrademarksorregisteredtrademarksofSTinvariouscountries.
Informationinthisdocumentsupersedesandreplacesallinformationpreviouslysupplied.
TheSTlogoisaregisteredtrademarkofSTMicroelectronics.
Allothernamesarethepropertyoftheirrespectiveowners.
2013STMicroelectronics-AllrightsreservedSTMicroelectronicsgroupofcompaniesAustralia-Belgium-Brazil-Canada-China-CzechRepublic-Finland-France-Germany-HongKong-India-Israel-Italy-Japan-Malaysia-Malta-Morocco-Philippines-Singapore-Spain-Sweden-Switzerland-UnitedKingdom-UnitedStatesofAmericawww.
st.
com
简介华圣云 HuaSaint是阿里云国际版一级分销商(诚招募二级代理),专业为全球企业客户与个人开发者提供阿里云国际版开户注册、认证、充值等服务,通过HuaSaint开通阿里云国际版只需要一个邮箱,不需要PayPal信用卡,不需要买海外电话卡,绝对的零门槛,零风险官方网站:www.huasaint.com企业名:huaSaint Tech Limited阿里云国际版都有什么优势?阿里云国际版的产品...
提速啦(www.tisula.com)是赣州王成璟网络科技有限公司旗下云服务器品牌,目前拥有在籍员工40人左右,社保在籍员工30人+,是正规的国内拥有IDC ICP ISP CDN 云牌照资质商家,2018-2021年连续4年获得CTG机房顶级金牌代理商荣誉 2021年赣州市于都县创业大赛三等奖,2020年于都电子商务示范企业,2021年于都县电子商务融合推广大使。资源优势介绍:Ceranetwo...
SugarHosts糖果主机商我们较早的站长们肯定是熟悉的,早年是提供虚拟主机起家的,如今一直还在提供虚拟主机,后来也有增加云服务器、独立服务器等。数据中心涵盖美国、德国、香港等。我们要知道大部分的海外主机商都只提供Linux系统云服务器。今天,糖果主机有新增SugarHosts夏季六折的优惠,以及新品Windows云服务器/云VPS上线。SugarHosts Windows系统云服务器有区分限制...
3322为你推荐
google地球打不开手机谷歌地球怎么打不开?手机游戏排行榜20152017年的手游排行榜?安装程序配置服务器失败SQL安装程序配置服务器失败站长故事爱迪生发明东西的故事依赖注入依赖注入是什么意思?中小企业信息化信息化为中小企业发展带来了哪些机遇彩信中心移动的短信中心号码是多少如何快速收录如何让百度快速收录虚拟机软件下载谁有好用的虚拟机软件?发邮件怎么发怎样发邮件?
免费域名申请 免费com域名申请 星星海 GGC 外国服务器 万网优惠券 免费博客空间 e蜗牛 我爱水煮鱼 lol台服官网 cdn加速原理 创建邮箱 万网空间管理 路由跟踪 qq金券 万网空间 免费个人主页 深圳主机托管 葫芦机 alexa搜 更多