Part Number Hot Search : 
MAX52 K2224 BR1020 TZA102 20CTT4 UN2114 F10N6 B30PCI
Product Description
Full Text Search
 

To Download AN3254 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  november 2010 doc id 17783 rev 1 1/24 AN3254 application note spi protocol for the st pmc1 metering device introduction the stpmc1 device is an assp designed for ef fective measurement in power line systems utilizing the rogowski coil, current transformer, and shunt or hall curren t sensors. used in combination with one or more stpmsx ics, it implements all the functions needed in a 1, 2, or 3-phase energy meter. it can be coupled with a microprocessor for multifunction energy meter or it can directly drive a stepper motor for a simple active energy meter. all the data measured by the stpmc1 are accessible through the spi port, which is also used to configure and calibrate the device. the configuration and calibration data are retained in a 112-bit otp block; in any case, these data can be dynamically changed in microprocessor based meters. measured data (like active and reactive energy, total and per phase, phase v rms , i rms and instantaneous voltage and current, line frequency, phase status, etc.) should be read by the microcontroller at a fixed time interval to be further processed. this application note describes the spi protocol to read measured data from the stpmc1 in a multiphase energy meter and how these readings should be processed by the application. for more details on the device please refer to the stpmc1; programmable poly-phase energy calculator ic , datasheet. figure 1. stpmc1 based application block diagram ? n r s t current sensor current sensor current sensor voltage sensor voltage sensor voltage sensor current sensor stpms1 stpms1 stpms1 stpms1 stpmc1 dar das dah dan dat ( ( mcu application support and peripheral control mcu application support and peripheral control spi mcu application support and peripheral control mcu application support and peripheral control spi 4 wires stepper counter stepper counter led indicators energy no load tamper negative powe r www.st.com
contents AN3254 2/24 doc id 17783 rev 1 contents 1 spi module description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.1 connection to microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 spi interface timings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 3 spi operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.1 remote reset request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.2 data registers writing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 3.3 data registers permanent writing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.4 reading data registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4 data processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.1 reading process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.1.1 data register assembling example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.2 parity check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.2.1 parity check example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.3 unpacking data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5 converting readings into m easured values . . . . . . . . . . . . . . . . . . . . . 16 5.1 energies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.2 other values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 5.2.1 voltage, current, and frequency calculation . . . . . . . . . . . . . . . . . . . . . . 18 5.2.2 other values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 6 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
AN3254 spi module description doc id 17783 rev 1 3/24 1 spi module description the stpmc1 spi interface supports a simple serial protocol, which is implemented in order to enable a communication between a host system (microcontroller or pc) and the device. with this interface it is possible to perform the following tasks: remote reset of the device temporary and permanent programming of internal configuration/calibration data and system signals reading of internal data registers (shown in figure 5 ). four pins of the device are dedicated to this purpose: scs, syn, scl, and sda. when the stpmc1 is in standalone mode, syn, scl, and sda can provide information on the meter status (see the stpmc1 datasheet for more information) and are not used for spi communication. in this document, the syn, scl, and sda operation as part of the spi interface is described. scs, syn, and scl are all input pins while sda can be input or output depending on whether the spi is in write or read mode. the internal registers are not directly accessible, rather, a 32-bit of transmission latches are used to pre-load the data before being read or written to the internal registers. the condition in which scs, syn, and scl inputs are set to a high level determines the idle state of the spi interface and no data transfer occurs. any spi operation should start from this idle state. the exception to this rule is when the stpmc1 has been put into standalone application mode. in such mode it is possible that pin states of the scl, sda, and syn are not high due to the states of corresponding internal status bits. scs: enables spi operation when low, both in standalone and in peripheral operating mode. this means that the master can abort any task in any phase by deactivation of scs. in standalone mode scs high enables syn, scl, and sda to output the meter status. syn: when scs is low, the syn pin status sele cts if the spi is in read (syn=1) or write mode (syn=0). when scs is high and syn is also high, the results of the input or output data are transferred to the transmission latches. scl: is the clock pin of the spi interface. th is pin function is also controlled by the scs status. if scs is low, scl is the input of the serial bit synchronization clock signal. when scs is high, scl is also high, determining the idle state of the spi. configuration bit sclp controls the polarity of the clock. sclp=0 sets the clock idle state scl=1, while sclp=1 sets the clock idle state scl=0. sda: is the data pin. if scs is low, the operation of sda is dependent on the status of the syn pin. if syn is high, sda is the output of serial bit data (read mode). if syn is low, sda is the input of serial bit data signal (write mode). if scs is high, sda is idle. when scs is active (low), the signal sda shoul d change its state at the trailing edge of signal scl and the signal sda should be stable at the next leading edge of signal scl. the first valid bit of sda is always started with activation of signal scl. this is valid if sclp=0, otherwise the polarity of the clock is inverted. a high level signal for these pins means a voltage level higher than 0.75 x v cc , while a low level signal means a voltage value lower than 0.25 x v cc .
spi module description AN3254 4/24 doc id 17783 rev 1 1.1 connection to microcontroller the spi master should be implemented by a host system, a pc, or a microcontroller. the microcontroller?s spi bus is usually a 4-wire bus with full duplex functionality, whose signals are usually named as: sclk: serial clock (output from master) mosi: master output, slave input (output from master) miso: master input, slave output (output from slave) ss: slave select (active lo w, output from master) the best way to connect this standard spi port to the stpmc1 spi is to have scs and syn driven from some general purpose i/o port and scl and sda driven from spi pins. the suggested connection between the microcontroller and the stpmc1 is the following: miso connected to sda mosi not connected sclk connected to scl ss connected to scs a general purpose i/o pin connected to syn. in this way, the spi peripheral unit of the microprocessor should operate as 2-wire (simplex synchronous transfers) spi. the microprocessor spi peripheral can be used during stpmc1 device reading, while during the writing process it is possible to implement the spi protocol via firmware. in fact, in real applications the meter is calibrated and configured during meter production, so the main microcontroller task is to read from the device and, more rarely, to reset the device. moreover the reading time is crucial for a correct evaluation of the device data, it is advisable to emulate the writing procedure by firmware and to read using the spi peripheral functionality, therefore exploiting all the port performances to reach very fast reading.
AN3254 spi interface timings doc id 17783 rev 1 5/24 2 spi interface timings in ta b l e 1 above, f xtal1 is the oscillator clock frequenc y (see the stpmc1 datasheet for details). table 1. spi interface timings symbol parameter min. typ. max. unit f sclkr data read speed 32 mhz f sclkw data write speed 100 khz t ds data setup time 20 ns t dh data hold time 0 ns t on data driver on time 20 ns t off data driver off time 20 ns t syn syn active width 2/f xtal1 s
spi operations AN3254 6/24 doc id 17783 rev 1 3 spi operations 3.1 remote reset request the stpmc1 has no reset pin. it is automatically reset by the power on reset (por) circuit when the v cc crosses the 2.5 v value but it can be reset also through the spi interface giving a dedicated command, the timing diagram is shown in figure 2 . the reset through spi (remote reset request - rrr) is sent from the onboard microprocessor when a malfunction of the metering device has been detected. unlike the por, the rrr signal does not cause the 30 ms retarded restart of the analog module and the 120 ms retarded restart of the digital module. this reset does not clear the mode signals. note: all the time intervals must be longer than 30 ns. t 7 t 8 is the reset time, this interval must also be longer than 30 ns. 3.2 data registers writing each writable bit (configuration and mode signals bits) of the stpmc1 has its own 7-bit absolute address (see the stpmc1 datasheet for configuration bits map). in order to change the state of some pins, a byte of data via the spi must be sent to the device. this byte consists of 1-bit data to be written (msb), followed by a 7-bit address of the destination bit, which makes a command byte. figure 2. remote reset request timing t 10 t 2 t 1 t 4 t 3 t 6 t 5 t 8 t 7 t 9 sda scl syn scs
AN3254 spi operations doc id 17783 rev 1 7/24 for example, to set the stpmc1 configuration bit 47 (part of the r-phase current channel calibrator) to 1, the decimal 47 must be converted to its 7-bit binary value: 0101111. the byte command is then composed as: 1 bit data value+7 bits address = 10101111 (0xaf) the same procedure should be applied for the mode signals, which also have their specific address. the lsb of the comm and is also called exe bit because, instead of a data bit value, the corresponding serial clock pulse is used to generate the necessary latching signal. in this way, the writing mechanism does not need the measurement clock in order to operate, which makes the operation of the spi module of the stpmc1 completely independent from the rest of the device logic, except from the signal por. the writing procedure timing is shown in figure 3 . t 1 t 2 (> 30 ns): spi out of idle state t 2 t 3 (> 30 ns): spi enabled for write operation t 3 : data value is placed in sda t 4 : sda value is stable and shifted into the device t 3 t 5 (> 10 s): writing clock period t 3 t 5 : 1-bit data value t 5 t 6 : 6-bit address of the destination latch t 6 t 7 : 1-bit exe command t 8 : end of spi writing t 9 : spi enters idle state figure 3. timing for writing confi guration bits and mode signals t 2 t 1 t 4 t 3 t 6 t 5 t 8 t 7 t 9 sda scl syn scs
spi operations AN3254 8/24 doc id 17783 rev 1 commands for changing configuration bits and system signals should be sent during active signals scs and syn, as it is shown in figure 3 . the syn must be put low in order to disable the sda output driver of the device and to make the sda an input pin. a string of commands can be sent within one period of active signals scs and syn or a command can be followed by reading the data record but, in this case, the syn should be deactivated in order to enable the sda output driver and a syn pulse should be applied before activation of the scs in order to latch the data. given the connection between the stpmc1 and a microcontroller, as shown in the previous paragraph, it is possible to implement the writing procedure in the firmware through the following steps: 1. disable the spi peripheral 2. set miso, sclk, and ss to be output 3. set the pin which is connected to syn to be output high 4. activate scs first and then syn 5. activate scl 6. apply a bit value to sda and deactivate scl 7. repeat the last two steps seven times to complete one byte transfer 8. repeat the last three steps for any remaining byte transfer 9. deactivate syn and the scs 10. enable again the spi module. to temporarily set any bit, it is necessary to set the rd system signal before any other bit. this bit determines the device functioning from otp shadow latches and not from otp memory. the procedure to set this signal is that shown above. in the case of a precharge command (0xff), emulation of the above is not necessary, it can be sent before any reading command. in fact, due to the pull up device on the sda pin the processor needs to perform the following steps: 1. activate syn first in order to latch the results 2. after at least 1 s activate scs 3. write one byte to the transmitter of spi this produces 8 pulses on the scl with sda=1 4. deactivate syn 5. read the data records as shown in section 3.4 (the sequence of reading is altered) 6. deactivate scs. 3.3 data registers permanent writing in order to make a permanent set in otp memory of some configuration bits, the following procedure should be conducted:
AN3254 spi operations doc id 17783 rev 1 9/24 1. collect all addresses of bits to be permanently set into some list 2. clear all otp shadow latches 3. set the system signal rd 4. connect a current source of at least +14 v, 1 ma to 3 ma to the v otp pin 5. wait until v otp voltage is stable 6. write one of the bits from the list (as the rd signal is set, the bit is written in the corresponding otp shadow latch) 7. set the system signal we 8. wait for 300 s 9. clear the system signal we 10. clear the otp shadow latch which was set in step 6 11. until all wanted bits are permanently set, repeat steps 5 to 10 12. disconnect the current source 13. wait until v otp voltage is less than 3 v 14. clear the system signal rd 15. read all data records, in the last two there is read back of all configuration bits 16. if verification of cfg bits fails and there is still a chance to pass, repeat steps 1 to 16. for the steps above which ask of set or clear, apply the timing shown in figure 3 with proper data on the sda. for step 15 apply the timing shown in figure 4 . for a permanent set of the tstd bit, which locks the device, the procedure above must be conducted in such a way that steps 6 to 13 are performed in series during a single period of active scs because the idle state of scs would make the signal tstd immediately effective. this would abort the procedure, and it would possibly destroy the device. in fact the clearing of system signal rd would connect all gates of 3 v nmos sense amplifiers of already permanently set bits to the v otp source. 3.4 reading data registers there are two phases of reading, called latching and shifting. latching is used to sample results into transmission latches. this is done with the active pulse on syn when scs is idle. the length of pulse on syn must be longer than 2 periods of the measurement clock, i.e. more than 500 ns. shifting starts when scs becomes active. in the beginning of this phase another, but much shorter pulse (30 ns) on syn should be applied. an alternative way is to extend the pulse on syn into the second phase of reading. latching and shifting finish at the dotted line in the timing diagram shown in figure 4 .
spi operations AN3254 10/24 doc id 17783 rev 1 t 1 t 2 : latching phase. interval value > 2 / f xtal1 t 2 t 3 : data latched, spi idle. interval value > 30 ns t 3 t 4 : enable spi for read operation. interval value > 30 ns t 4 t 5 : serial clock counter is reset. interval value > 30 ns t 5 t 6 : spi reset and enabled for read operation. interval value > 30 ns t 7 : internal data transferred to sda t 8 : sda data is stable and can be read after the shifting phase, it is possible to read data, applying 32 serial clocks per data record. up to 28 data records can be read this way. there are seven groups of four data records available, each consisting of a parity nibble (see section 3.2 ) and a 28-bit data field. figure 5 and figure 6 show the records structure and the information they hold in the default sequence of reading. the system which reads the data record from the stpmc1 should check the integrity of each data record. if the check fails, the reading should be repeated, but this time only the shifting phase should be applied otherwise a new data would be latched into the transmission latches and the previous reading would be incorrectly lost. most of the registers contain the values of the electrical parameters and the status of the signals, except the registers cf0, cf1, cf 2, and cf3 which represent the configuration bitmap. the data records have a fixed position of reading. this means that no addressing of records is necessary. the sequence of data records during the reading operation is fixed. however, an application may apply a precharge command prior to the reading phase. this command increases the group pointer forcing the device to respond with the next group data records sequence. in this way, a faster access to later groups is possible. figure 4. timing for reading data registers t 2 t 1 t 4 t 3 t 6 t 5 t 8 t 7 last bit of 32 nd byte 1 st byte 1 st byte sda scl syn scs
AN3254 spi operations doc id 17783 rev 1 11/24 figure 5. stpmc1 data registers ? upper status parity parity parity parity parity parity parity tsg bits dc un parity 20 bit 8 bit 4 bit 4 bit dap drp dfp dmn prd dmr dms dmt 3-phase reactive energy 3-phase active energy wide band 3-phase active energ y fundamental period system read back lower status ir mom ur mom is mom us mom it m om ut mom in mom si rms parity der ir rms ur rms parity des is rms us rms parity det it rms ut rms parity den in rms un rms 12 bit 16 bit 4 bit upper status parity parity parity parity parity parity parity tsg bits dc un parity 20 bit 20 bit 8 bit 4 bit 4 bit dap drp dfp dmn prd dmr dms dmt 3-phase reactive energy 3-phase active energy wide band 3-phase active energ y fundamental period system read back lower status ir mom ur mom is mom us mom it m om ut mom in mom si rms parity der ir rms ur rms parity des is rms us rms parity det it rms ut rms parity den in rms un rms 12 bit 16 bit 4 bit
spi operations AN3254 12/24 doc id 17783 rev 1 figure 6. stpmc1 data registers ? parity parity parity parity 20 bit 8 bit 4 bit dar das dat cf1 cf0 drr drs drt r-phase active energy wide band r- phas e s tat us dfr dfs dft cf2 28 bit s-p has e st atus s-phase active energy wide band t-phase active energy wide band t-phase status b its [27..0] of configurators parity parity parity parity r-phase reac tive energy r- phas e s tat us s-p has e st atus s-phase reactive energy t- phase re ac tive energy t-phase status bits [55..28] of configurators parity parity parity parity r- phase activ e energy f undamenta l r- phas e s tat us s-p has e st atus s-phase active energy fundamental t-phase active energy fundamental t-phase status bits [83..56] of configurators acr acs act cf3 parity parity parity parity ir rms ah accumulator if bad ur r- phase e lapsed s-p hase elapse d is rms ah accumulator if bad us it rms ah accumulator if bad ut t-phase elapsed bits [111..84] of configurators parity parity parity parity 20 bit 20 bit 8 bit 4 bit dar das dat cf1 cf0 drr drs drt r-phase active energy wide band r- phas e s tat us dfr dfs dft cf2 28 bit s-p has e st atus s-phase active energy wide band t-phase active energy wide band t-phase status b its [27..0] of configurators parity parity parity parity r-phase reac tive energy r- phas e s tat us s-p has e st atus s-phase reactive energy t- phase re ac tive energy t-phase status bits [55..28] of configurators parity parity parity parity r- phase activ e energy f undamenta l r- phas e s tat us s-p has e st atus s-phase active energy fundamental t-phase active energy fundamental t-phase status bits [83..56] of configurators acr acs act cf3 parity parity parity parity ir rms ah accumulator if bad ur r- phase e lapsed s-p hase elapse d is rms ah accumulator if bad us it rms ah accumulator if bad ut t-phase elapsed bits [111..84] of configurators
AN3254 data processing doc id 17783 rev 1 13/24 4 data processing 4.1 reading process as previously mentioned, to start an spi communication with the stpmc1 to read new values of registers, it is necessary to apply a latching phase first. then a shifting phase starts, as described in figure 4 . after that, 32 pulses of serial clocks need to be applied to pin scl in order to read the dap register. if an additional 32 pulses are app lied to pin scl, the drp register is read. reading can be continued by applying 32 clocks per register until all registers of interest are read or a precharge command is applied first (8 pulses to pin sclnlc while syn=0 and sda=1) which moves ahead the internal group pointer to group 1 (register dmr) which effectively skips dfp and prd registers, and then reading may be continued. the internal group pointer is incremented by 1 after each precharge command sent. if, for example, in the previous case two precharg e commands are sent, the pointer will be set to group 2 (register der). it is up to an application to decide how many records should be read out from the device. after all the registers are read, scs can be returned to idle state which ends the shifting phase. the shifting phase can be repeated and it should read the same values. this repetition is used to improve the reliability of successf ul reading in a strong emi environment. every register is packed into 4 bytes where the most significant nibble (4 bits) is reserved for parity code and the rest of the 28 bits are used for data. this means that every register is protected by its own parity bit. as shown in figure 7 , the first read out byte of the data record is the least significant byte (lsb) of the data value and the fourth is the most significant byte (msb) of the data value, then it is necessary to re-order the four bytes after reading. figure 7. stpmc1 data register assembling 7 0 7 0 7 0 7 0 7 0 7 0 15 8 15 8 23 16 23 16 0 0 24 24 8 bit spi reading order 32 bits register assembling 1 st byte - lsb msb lsb 4 th byte - msb 7 0 7 0 7 0 7 0 parity nibble msb lsb parity nibble 28 bit data
data processing AN3254 14/24 doc id 17783 rev 1 normally, each byte is read out as the most significant bit (msb) first. but this can be changed by setting the msbf configuration bit. if this is done, each byte is read out as the least significant bit (lsb) first. 4.1.1 data register assembling example the following is an example of the reading and re-arranging of stpmc1 registers. on the left there are the eight data records as they are read, represented as hexadecimal bytes while msbf was cleared, on the right is the corresponding register. 1. 65 7a 7c 82 dap = 82 7c 7a 65 2. 00 7a 0c e0 drp = e0 0c 7a 00 3. 00 00 8c 92 dfp = 92 8c 0 00 4. 00 06 6e 22 prd = 22 6e 06 00 5. ? 4.2 parity check each bit of parity nibble is defined as odd parity of all seven corresponding bits of data nibbles. in order to check the data record integrity, the application should execute something similar to the following c code, given as an example: int badparity (unsigned char *bp) { register unsigned char prty = grp; /* temporary register set to group # (0..6)*/ prty = *bp, /* take the 1st byte of data */ prty ^= *(bp+1), /* xor it with the 2nd byte */ prty ^= *(bp+2), /* and with the 3rd byte */ prty ^= *(bp+3), /* and with the 4th byte */ prty ^= prty<<4, prty &= 0xf0;/* combine and remove the lower nibble */ return (prty != 0xf0); /* returns 1, if bad parity */ } if the parity nibble check fails, the reading task should be repeated, but this time without the request of latching, otherwise a new data would be latched and the previous reading would be incorrectly lost. in a very harsh emi environment, it would be a good practice to read the data records twice and then compare both readings. in this way, the probability of detect ing bad readings would be significantly improved. however, a single piece of bad data can be discarded because no meaningful information is lost as long as the reading frequency is about 30 ms.
AN3254 data processing doc id 17783 rev 1 15/24 4.2.1 parity check example let us calculate the parity of dmr, the first register of the second group: dmr: 02 80 00 c8 prty = grp = 1 /* prty set to 1 - group #*/ prty = *bp = 3 /* xor it with 1st byte of data 02 */ prty ^= *(bp+1) = 83 /* xor it with the 2nd byte 80*/ prty ^= *(bp+2) = 83 /* and with the 3rd byte 00 */ prty ^= *(bp+3) = 4b /* and with the 4th byte c8 */ prty ^= prty<<4 = fb /* and with b0 */ prty &= 0xf0 = f0 /* parity is ok */ 4.3 unpacking data after reading (and the following re-ordering of bytes read), each register should be unpacked in order to obtain all individual values. for this purpose it is necessary to mask the 28 bits according to the register map shown in figure 5 and figure 6 . for example, the dap register is unpacked into an 8-bit value of status (least significant byte) and a 20-bit value of the 3-phase active energy counter (the remaining upper 3 bytes with parity code masked out).
converting readings into measured values AN3254 16/24 doc id 17783 rev 1 5 converting readings into measured values 5.1 energies the first three registers contain 20-bit values of the internal 3-phase energy up/down counters, and in the following groups there are the registers containing each phase energy counter. the value of the least significant bit of every energy counter is related to power meter constant p, which is the number of pulses per kwh that the meter, through calibration, is configured to provide to the led pin. this means that this value changes with the application and relative calibration. given p, the number of pulses per kwh provided, the energy registers lsb value is indicated in ta b l e 2 below: for example, the energy registers lsb values for sys = 0, 1, 2, 4, 5, 6, 7 when p = 64000 pulses/kwh = 17.7 hz*kw are: k p = k f = 15.258 *10 -6 wh k q = k r = 15.258 *10 -6 varh the energy registers lsb values for sys = 3 and the same p are: k p = 15.258 *10 -6 wh k f = 30.517 *10 -6 wh k q = k r = 30.517 *10 -6 varh table 2. energy registers lsb value register sys = 0,1,2,4,5,6,7 sys = 3 3-ph active energy wide band (p) 3-ph reactive energy wide band (q) 3-ph active energy fundamental (f) 3-ph reactive energy fundamental (r) k p 1000 p2 10 ? ---------------- - wh [] = k p 1000 p2 10 ? ---------------- - wh [] = k q 1000 p2 10 ? ---------------- - varh [] = k q 1000 p2 9 ? -------------- varh [] = k f 1000 p2 10 ? ---------------- - wh [] = k f 1000 p2 9 ? -------------- wh [] = k r 1000 p2 10 ? ---------------- - varh [] = k r 1000 p2 9 ? -------------- varh [] =
AN3254 converting readings into measured values doc id 17783 rev 1 17/24 this also means that the stpmc1 energy counters hold a very small energy value (in the example above, when lsb represents 15.258 wh, the whole register stores 16 wh), and further energy integration must be performed inside the application. to accomplish this task, the procedure below should be followed. because all energy counters rollover in approx imately 1 s when they are integrating maximal power, the reading must be done frequently enough. it is suggested to read the registers at least 32 times per second. for each energy type, a variable e should be allocated, having the following structure (below is the variable definition for an st7 microcontroller): typedef struct energ { unsigned long old; /* previous energy value - 32 bits */ unsigned int quot; /* quant/16 - 16 bits */ signed int quant; /* new - old, measure of power - 16 bits */ signed long frac; /* fractional part of energy integrator - 32 bits */ signed long integ; /* integer part of energy integrator - 32 bits */ } energ; the application should keep the previous value of each energy counter in order to evaluate the difference of readings, from which also a direction of energy flow can be obtained. this value should be stored in e old before a reading. after the reading, the new energy register reading should be stored in e new . to calculate consummated energy the software should implement a 32-bit integrator. the suggested integrator is two stages, with e frac and e integ 32-bit signed integer variables. into e frac is added the value e quant , obtained as the difference between e old and e new energy values; then the e old value should be rewritten with the e new value in order to enable a correct e quant computation next time. when e frac collects a certain amount of energy, let?s say 10 wh for active energy (corresponding to a certain threshold value according to k p ), e integ should change for 1 bit and the e frac should change by the threshold value. in this way, e frac stores 0.01 kwh, after which e integ is increased by one, and the e integ variable holds accumulated energy of which the least significant bit represents 10 wh. considering an active energy meter where p = 64000 imp/kwh, for a step of 0.01 kwh = 10 wh, as each bit of e quant represents k p wh (it is the same resolution of the internal energy counter, because e quant is calculated as a difference of two energy counter values), the threshold value is 10/k p = 10/15.258*2 06 = 0xa0021. in a microcontroller based application, a high priority timer interrupt should be set to perform measuring tasks every 1/512 s. within this interrupt service 16 different subtasks could be established in order to break the whole mete r task into 16 shorter consecutive subtasks (reading of device register, checking the data read, and, if ok, computing the value of e quant ). in this way, the main program and other interrupt services are not blocked for more than a few 100 us every 2 ms, and the meter task is completed in 16 steps - that is in 1/32 s.
converting readings into measured values AN3254 18/24 doc id 17783 rev 1 the interrupt service sh ould do the following: update e frac and e integ of the energy variable using e quot = e quant / 16 generate output pulses (if needed) from e frac call the next subtask perform other tasks (if needed) in this way the addition of e quant is split in 16 times. this generates a microcontroller output pulse that has a 16 times better accuracy of position in time, which would reduce the jitter of an eventual led output. 5.2 other values 5.2.1 voltage, current, and frequency calculation the ratio between the register value and the actual voltage, current, or frequency value is a function of the voltage and current sensor sensitivity and of the device internal parameters, like analog amplification, reference voltage, measurement frequency, calibrator, attenuation of each stage of decimation filter, and power meter constant. formulas to convert the readings into meaningful values are reported below. for details on the device configuration bits mentioned below, please refer to the stpmc1 datasheet. in any case, as the internal parameter values , here given as constants, are subject to process drift, and the sensors sensitivity are subj ect to tolerance, even if these fluctuations are compensated by the calibrators, the best way to obtain the proper parameters is to measure known signals and calculate the ratio between the register value and actual value. the device linearity ensures that the ratio remains constant. figure 8 , 9 , and 10 below show the signal processing chains for each phase current and voltage. figure 8. voltage signal path
AN3254 converting readings into measured values doc id 17783 rev 1 19/24 each block of the path contributes to the signal processing with the parameters shown below. ta bl e 3 shows the variable parameters that must be considered as inputs for the following calculation, while ta bl e 4 shows the device internal constant parameters. x_i can be one of the current readings in the registers from dmr to den (ir mom, is mom, etc., si rms, ir rms, is rms, etc.), and x_u can be one of the voltage readings in the registers from prd to den (dc un, ur mom, us mom, etc., ur rms, us rms, etc.). x_period is the 12 bits value in the prd register. figure 9. current conditioning figure 10. current signal path table 3. input parameters parameter meaning r1, r2 voltage divider resistors value [ohm] ks current sensor sensitivity value [v/a] x_i current register value expressed as decimal x_u voltage register value expressed as decimal x_period period register value expressed as decimal ai current channel gain
converting readings into measured values AN3254 20/24 doc id 17783 rev 1 line frequency is calculated as follows: frequency = fm /( x_period * 2 5 ) the integrator and differentiator gains are calculated as follows: kint = 2 * x_period * 2 5 / (p * 2 16) kdif = 1/ (2 * kint) typical values for these gains are: table 4. stpmc1 internal parameters value parameter value meaning ku 0,875 voltage calibrator ideal value if pm = 0 (1) 0,9375 voltage calibrator ideal value if pm = 1 ki 0,875 current calibrator ideal value if pm = 0 0,9375 current calibrator ideal value if pm = 1 kisum 0,875 calibrator ideal value for si rms (sum of currents) (2) au 4 voltage channel gain len_i 2 16 current register length len_u 2 12 voltage register length len_isum 2 12 si rms (sum of currents) register length kint_comp 1,004 gain of decimation filter 3.14159 fm 4 * 10 6 if oscillator frequency is 4.000 or 8.000 mhz 2 22 if oscillator frequency is 4.194 or 8.388 mhz 4915200 if oscillator frequency is 4.915 or 9.830 mhz kut 2 for ct/shunt 1 for rogowski coil vref 1.23 internal voltage reference 1. pm is cfg 21, it sets the meter precision (class 1 or class 0.1) 2. 12 bits in dmn register table 5. kint and kdif typical values kdif 0,6135 gain of differentiator @ line frequency = 50 hz 0.7359 gain of differentiator @ line frequency = 60 hz kint 0,815 gain of integrator @ line frequency = 50 hz 0.679 gain of integrator @ line frequency = 60 hz
AN3254 converting readings into measured values doc id 17783 rev 1 21/24 from these values the following scaling parameters are calculated for rogowski coil sensor: kf = frequency / 50 kdspu = 1 kdspi = kf and for ct or shunt current sensors: kdspu = kdif * kint kdspi = kdif the un rms value (12 bits in den register) conversion formula is: u = x_u * 2 / len_u for the sum of rms currents si rms (12 bits in dmn register) the value is obtained as follows: si = x_i * vref/(ks * kisum * ai * len_isum * kint * kint_comp * kdspi) for the data from the momentary registers, as the related momentary voltage and current parameters are signed (they can be positive or negative), it is necessary to evaluate the sign with the following task. this does not apply to the rms values: if (x_i & (len_i>>1)) // positive current x_i = x_i & ((len_i>>1)-1); else // negative current { x_i = (len_i>>1) - x_i; x_i = x_i * (-1); } if (x_u & (len_u>>1)) // positive voltage x_u = x_u & ((len_u>>1)-1); else // negative voltage { x_u = (len_u>>1) - x_u; x_u = x_u * (-1); } both rms and momentary current and voltage conversion formulas then are: u = (1+r1/r2)* x_u * vref /(kut * ku * au * len_u * kint_comp* kdspu) i = x_i * vref/(ks * ki * ai * len_i * kint * kint_comp * kdspi)
converting readings into measured values AN3254 22/24 doc id 17783 rev 1 for sys configuration bits 2 or 3 (no neutral wire) the voltage value should be further multiplied by 2: u = u * 2 5.2.2 other values the acr, acs, and act registers hold the information needed for this calculation. concatenating act[7:0], acs[7:0], and acr[7:0] bytes, two 12-bit vectors, defined below, are obtained: act[7:0], acs[7:0], acr[7:0] = asr[11, 10:0], art[11, 10:0] the delay times are calculated with the following formulas: where f mclk depends upon the oscilla tor value according to ta b l e 6 : the phase delays in degrees can be calculated as follows: time asr asr 10 0 ; [] 2 11 () asr 11 [] ? 1 + () 8 f mclk --------------- ? = time art art 10 0 ; [] 2 11 () asr 11 [] ? 1 + () 8 f mclk --------------- ? = table 6. f mclk value f xtal1 mdiv f mclk 4.000 mhz 0 8.000 mhz 4.194 mhz 0 8.192 mhz 4.915 mhz 0 9.830 mhz 8.000 mhz 1 8.000 mhz 8.192 mhz 1 8.192 mhz 9.830 mhz 1 9.830 mhz ? time f line ----------- - 360 ? =
AN3254 revision history doc id 17783 rev 1 23/24 6 revision history table 7. document revision history date version description 19-nov-2010 1 first release
AN3254 24/24 doc id 17783 rev 1 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 he rein 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 as sumes no liability whatsoever relating 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. i f 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 whatsoev er 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 parti cular 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 milita ry, 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 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 whatsoev er, 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. ? 2010 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN3254

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X