IXYS MX844 12 BIT, MULTI-CHANNEL POWER & TEMP SENSOR FOR MONITOR & CONTROL SYSTEMS Features: • • • • • • • • • • • Description: Wide Input Supply Range: 4.5V to 40V Programmable gain differential amplifier (±10mV, ±25mV, ±50mV, ±250mV ranges) 4 channel differential input multiplexer (3 input channels plus ground) Integrated 12-bit ADC Serial data output (SDO) with data ready pin Fine calibration of Full Scale Range (FSR) using VTRIM pin Bi-directional Current Sense Internal temperature sensor with 0.2°C resolution Compatible with 3.3V and 5V Microcontrollers Operating Temperature Range: -40°C to 85°C 5mm x 5mm, QFN-28 RoHS Package Ordering Information Part No. Description MX844R QFN-28 Tube MX844RTR QFN-28 Tape & Reel DRV RIN Qty 73 2500 The MX844 is a fully integrated subsystem that measures temperature plus differential current and voltage. An internal temperature sensor measures ambient temperature with 2.5°C accuracy. Current and voltage measurements are made differentially through a four input multiplexer connected to a programmable gain fully differential sense amplifier. The differential sense amplifier is optimized to measure very small positive or negative voltages near ground for low side bi-directional sensing. A dual slope ADC converts the temperature sensor or sense amplifier outputs to a 12-bit digital word that includes 3 ½ digits plus sign. The input multiplexer channel and programmable gain amplifier range may be changed between ADC conversions. An on-chip voltage regulator enables the MX844 to operate over a wide input voltage range of 4.5 to 40 volts. Controller interrupt or over-voltage/over-current signals may be generated by a pair of 12-bit digital comparators configured as a window comparator or simple threshold detection function. The serial port supports standard 4-wire synchronous serial data, or asynchronous serial “talk-only” data, and is compatible with most 3.3V and 5V microcontrollers. VCC BUF CAZ CINT IZ VIN Regulator IN1P IN2P IN3P Registers ADC IN1N IN2N IN3N GND VTRIM Serial I/O Control Tem perature Sensor Divider M1 SDI SDO SCK CS AOUT DRDY CMP X1 X2 SYNC Typical Application: Charging system Load MX844 Batt Load MX844 Rectifier IN 93C46 eeprom IN uP T IN IN Battery charge/discharge current, voltage, temperature MX844 Drawing No. 084423 uP IN Isolated voltage, current, and temperature sensing 1 08/25/06 www.claremicronix.com IXYS MX844 Absolute Maximum Ratings (Voltages with respect to GND=0V) Parameter VIN, RIN, DRV All Other Pins Storage Temperature Operating Ambient Temp Operating Junction Temp Thermal Resistance (Junction to Ambient) Symbol Min TSTG TA TJ -55 -40 RθJA Max 45 6 150 85 100 Unit V V Co Co Co Co/W 110 Typical ESD Warning Absolute Maximum Ratings are stress ratings. Stresses in excess of these ratings can cause permanent damage to the device. Functional operation of the device at these or any other conditions beyond those indicated in the operational sections of this data sheet is not implied. Exposure of the device to the absolute maximum ratings for an extended period may degrade the device and affect its reliability. ESD (electrostatic discharge) sensitive device. Although the MX844 features proprietary ESD protection circuitry, permanent damage may be sustained if subjected to high energy electrostatic discharges. Proper ESD precautions are recommended to avoid performance degradation or loss of functionality. DC Electrical Characteristics o XTAL = 8MHz, T=25C, Cint = Caz = 10nF, Rint = 68K, TA = +25 C Parameter VCC line regulation Condition VIN = 6 to 45V, no external load Min 4.8 VCC load regulation VIN = 6V, 15 mA external load 4.7 VIN supply current VIN = 6V Input bias current selected input channel Max 5.3 Unit V V 3.2 4.5 mA 20 40 nA -4 4 nA 10 Input bias current offset Typ Input offset voltage differential, input=0, +/-10mV scale -0.4 0.4 mV input common mode all input channels -300 300 mV ADC gain error +/-250mV range, at 90% input -0.5 0.5 % +/-50mV range -1.25 0.25 % +/-25mV range -1.5 0.25 % +/-10mV range -1 0.25 % at half full scale -3 3 lsb ADC linearity ADC noise 1.5 Temperature error -2.5 Temperature slope Temperature offset +/-0.5 rms lsb Power on reset duration Digital output low I = 20mA Digital output high I = 6mA C o 0.2 Zero oC o 2.5 C/lsb 3310 lsb 100 uS 0.5 VCC-0.5 V V Digital input low GND 0.5 Digital input high 2 VCC V ±1 uA Digital input current V Clock frequency terminal X1 0.1 20 MHz Clock input low terminal X1 GND 0.4 V Clock input high terminal X1 2 VCC V Clock input current terminal X1 50 uA MX844 Drawing No. 084423 2 08/25/06 www.claremicronix.com IXYS MX844 PIN DESCRIPTION Pin No. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Pin Name GND VTRIM BUF IZ CAZ CINT IN1P IN1N IN2P IN2N IN3P IN3N M1 SYNC DRDY SCK SDO SDI CS X1 X2 AOUT CMP VCC2 VCC VIN RIN DRV MX844 Drawing No. 084423 Description Ground Optional Full Scale Trim Input Integrating Resistor Output Integrator Zero Output Auto Zero Capacitor Input Integrator Capacitor Input Input Channel 1 Positive Input Channel 1 Negative Input Channel 2 Positive Input Channel 2 Negative Input Channel 3 Positive Input Channel 3 Negative Divisor Mode Input A/D Converter Reset Input A/D Converter Data Ready Output (Active Low) Serial Clock Input Serial Data Output Serial Data Input Serial Chip Select (Active Low) Xtal 1 Input Xtal 2 Output Asynchronous Data Output Comparator Output Must Be Connected to Vcc Regulator Output / Logic Supply Input Regulator Voltage Input Regulator Internal MOSFET Gate Regulator External PNP Base Drive 3 08/25/06 www.claremicronix.com IXYS MX844 APPLICATION OPERATING MODE At the end of the power-on reset period, pin CS is sensed to determine the operating mode. Placing an external resistor to VCC on pin CS will cause the MX844 to enter the slave mode. In this mode the synchronous serial I/O port can be connected to a companion microcontroller for full control of the MX844 from the microcontroller. If a resistor to GND is connected to CS, then the MX844 enters the master mode at power-up and fetches commands from a 93C46 serial EEPROM operating in the 64 by 16 mode. In this mode, the MX844 operates as the master and sends clock, data, and select to the EEPROM and reads back the EEPROM data. This mode is useful when the MX844 operates as a stand-alone data acquisition system with a fixed pattern of measurement scanning. To facilitate electrically isolated measurements the data can be sent to a computer's serial port using only one wire connected through a single opto-isolator. If, neither an EEPROM or microcontroller are connected to the MX844, and CS is connected to VCC, operation defaults to that of all zeroes in the control register (ADC clock = input clock / 8, input channel IN1, +/- 50mV range). The asynchronous data output has a valid stream of measurement information. FUNCTIONAL DESCRIPTION Voltage Regulator There are three methods of powering the MX844. 1) An external 4.5 to 5.5V supply is connected to VCC, VCC2, and VIN. Pins DRV and RIN are noconnect or connected together. 2) VIN is connected to a 6 to 40V supply. DRV is connected to RIN, thus utilizing the internal pass element. 3) VIN is connected to a 6 to 40V supply. An external PNP transistor such as the MMBTA56 or BCX53 is used for the pass element. The PNP transistor's emitter, base, and collector are connected to pins VIN, DRV, VCC respectively. RIN must be connected to VIN. Power-On Reset The MX844 contains a power-on reset circuit that resets all the internal flip-flops and initializes the internal registers to zero. The reset circuit will also generate a reset condition if the voltage at pin VCC drops to approximately 3.8V. Oscillator The oscillator configuration consists of a crystal/resonator connected between pins X1 and X2 and a capacitor to GND on both pins. The capacitor value depends on the crystal/resonator but is usually between 15 and 27pF. Alternatively, an external clock may be input to pin X1, with X2 floating. Nominal DC self-bias at pin X1 is 800mV. In either case the clock is internally AC coupled, therefore clock rates below 100KHz are not recommended. Temperature Sensor The internal temperature sensor is selected for measurement by setting the control register bits for a full scale of +/-250mV and setting the unipolar bit. The temperature value read from the ADC consists of an offset value plus the slope. To convert to a standard temperature scale it is necessary to subtract the constant offset and then multiply by a constant that matches the standard scale desired. Self-heating of the internal temperature sensor will occur due to the device power dissipation. The maximum heating will occur when the internal pass element is used in conjunction with a high supply voltage. MX844 Drawing No. 084423 4 08/25/06 www.claremicronix.com IXYS MX844 Analog/Digital Converter Selection of the input channel and the full scale range is accomplished by writing 5 bits in the control register. An additional 3 bits in the control register in combination with the M1 pin setup the internal clock dividers. The ADC is a bipolar-input dual slope type with clock period tAD equal to a multiple of the clock period at pin X1 (tClock). The ADC conversion time consists of 1024 * tAD of auto-zero, 1024 * tAD of input integration, and 2048 * tAD of reference integration. The result of the analog to digital conversion can be read using the serial I/O port and is also transmitted on pin AOUT in an asynchronous serial format. The DRDY pin transitions low at the end of the reference integration period to indicate that data is stable and may be read through the synchronous serial I/O. The data becomes not valid when DRDY returns high. The status of DRDY is also available in bit 7 of the ADC_1 register. The SYNC pin is connected to GND to enable free-running ADC conversions. Alternatively, if SYNC transitions high, the ADC is immediately driven to the start of the auto-zero time. When SYNC is returned to a logic low, the next rising edge at pin X2 will start the ADC timing. The input channel and full scale range may be changed in between ADC conversions, however it is recommended that such commands be written into the MX844 as soon as possible after pin DRDY transitions low. This allows the maximum settling time prior to the next ADC conversion. ADC clock # 0 1023 1024 auto-zero 2047 2048 input integrate 4095 0 reference integrate 1023 1024 2047 2048 next auto-zero SYNC DRDY (active low) CMP (active low) AOUT 6 data bits 6 data bits DRDY and CMP cleared if ADC_2 register is read CMP is the digital compare output that is described later. AOUT is the asynchronous serial output of the ADC. The ADC output code is offset-binary. An example of the coding is shown here for the +/-50mV range and the corresponding unipolar range of 0 to 100mV: Bipolar input 50mV 0 + 1/2 LSB 0 - 1/2 LSB -50mV Unipolar input 100mV 50mV + 1/2 LSB 50mV - 1/2 LSB 0 Binary Output (D11:D0) 111111111111 100000000000 011111111111 000000000000 Hexadecimal FFF 800 7FF 000 Two external components, Rin and Cint, should be chosen such that the value of Cint in pF is 4 to 7 * tAD and the time constant of Rint * Cint is 300 to 450 * tAD. The value of Rint should be between 47K and 220K ohm. For example, for t(AD) = 1.6 uS, a set of suitable values would be 56K ohm and 10nF (RC = 560uS, ratio = 350). The value of the auto-zero capacitor Caz is typically equal to Cint. VTRIM is either a no-connect pin or can be used to fine trim the ADC full scale by +/- 1%. The following circuit is recommended if fine trimming is desired: VCC 20K 1K VTRIM GND MX844 Drawing No. 084423 5 08/25/06 www.claremicronix.com IXYS MX844 Digital Comparator Two 12-bit registers form a window comparator of the ADC output data. The value of comparator1 must always be set to a value greater than comparator2. There are three cases to consider, depending on whether the comparator values are above or below 800h: 1) If the value of comparator1 is greater than 800h and the value of comparator2 is less than 800h, then CMP pulses when the ADC value is greater than or equal to comparator1, or less than or equal to comparator2. 2) If the value of comparator1 is greater than 800h and the value of comparator2 is greater than 800h, then CMP pulses when the ADC value is greater than or equal to comparator1, or less than comparator2. 3) If the value of comparator1 is less than 800h and the value of comparator2 is less than 800h, then CMP pulses when the ADC value is greater than comparator1, or less than or equal to comparator2. In all cases, CMP will go logic low at the same time as DRDY transitions low and CMP will return high when the ADC_2 register is read or after 2048 *tAD (see the ADC timing diagram). The status of CMP is also available in bit 6 of the ADC_1 register. In a typical application CMP would cause a controller interrupt, at which time the controller reads the actual ADC output that caused the interrupt (which clears the DRDY and CMP status bits) and takes appropriate action. Another application would be to connect CMP to over-current or over-voltage shutdown circuitry. ASYNCHRONOUS OUTPUT The ADC result is transmitted on pin AOUT in 8-bit, no parity asynchronous NRZ serial format. Two characters of 8 bits each are transmitted for each ADC conversion, with a start bit just prior to the data (see the figure below). D0 D1 D2 D3 D4 D5 n0 n1 D6 D7 D8 D9 D10 D11 n2 cr7 D[11:0] is the 12-bit result of the ADC conversion. Bit cr7 is the value of the control register bit 7. Bits n2, n1, n0 are automatically inserted which indicate the address of the serial EEPROM. These bits can be used by the receiver to identify which channel and range are being transmitted. The EEPROM address is reset to zero by the SYNC pin pulse. The "ANALOG/DIGITAL CONVERTER" section of this document shows the timing of the asynchronous output bytes relative to the conversion cycle. MX844 Drawing No. 084423 6 08/25/06 www.claremicronix.com IXYS MX844 Example internal divider settings and clock frequencies for standard baud rates: CR7:5 M1 Baud divider 000 001 010 011 1 1 1 1 8*52 4*52 12*64 13*64 000 001 010 011 0 0 0 0 8*64 4*64 6*64 3*64 100 101 110 111 1 1 1 1 8*128 9*128 12*128 13*128 100 101 110 111 0 0 0 0 8*128 9*128 12*128 13*128 ADC divider Clock (MHz) baud rate ADC conv/s Clock (MHz) baud rate ADC conv/s 8 4 12 13 12.0 6.0 11.059 12.0 28.8K 28.8K 14.4K 14.4K 366 366 225 225 16.0 38.4K 8.0 38.4K 14.746 19.2K 16.0 19.2K 488 488 300 300 8 4 6 3 14.746 14.746 11.059 11.059 28.8K 57.6K 28.8K 57.6K 450 900 450 900 9.83 9.83 14.746 7.37 300 600 600 600 8*4*5 9.83 9*4*5 11.059 12*4*5 14.746 9600 13*4*5 16.0 9600 9600 9600 15 15 15 15 8*4*6 9.83 9*4*6 11.059 12*4*6 14.746 9600 13*4*6 16.0 9600 9600 9600 12.5 12.5 12.5 12.5 19.2K 38.4K 38.4K 38.4K SYNCHRONOUS SERIAL I/O The MX844 (slave) can communicate with a microcomputer (master) via a three wire plus chip select serial interface. The control register, the two digital comparator values, and the ADC result are accessed by specifying a 3-bit address A[2:0]. Chip select CS, serial clock SCK, and serial data input SDI are output from the master controller to the MX844. Serial data output SDO is driven by the MX844 when selected by CS = 0. SDO is high impedance when CS = 1. SCK and SDI are don't care when CS = 1. tClock = the period of the X1 input clock SERIAL INTERFACE TIMING READ: 1.5 * tClock min CS SCK SDI RW = 0 A2 A1 A0 1.2 * tClock min SDO B7 B6 WRITE: SDI B5 B4 B3 B2 B1 B0 2 * tClock max RW = 1 A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0 SCK minimum high or low time is 3 * tClock. SDO is high impedance until data read out, and then returns to high impedance due to the rising edge of CS. MX844 Drawing No. 084423 7 08/25/06 www.claremicronix.com IXYS MX844 REGISTER ADDRESS AND BIT ASSIGNMENT All registers are read/write except for the two ADC result registers which are read only. The left hand column refers to the data bits shown as B7 through B0 on the synchronous serial I/O timing diagram. CONTROL REGISTER, address A[2:0] = 000 binary ADC Clock divisor M1 low M1 high 8 8 4 4 6 12 3 13 192 160 216 180 288 240 312 260 Baud rate divisor M1 low M1 high 512 416 256 208 384 768 192 832 1024 1024 1152 1152 1536 1536 1664 1664 CR[7:5] Clock divisor bits 000 001 010 011 100 101 110 111 CR[4:3] Input channel select 00 01 10 11 IN1 IN3 GND IN2 CR[2:0] Full scale select V(INxP) – V(INxN) 000 001 010 011 100 101 110 111 +/- 50 mV +/- 25 mV +/- 250 mV +/- 10 mV 0 to 100 mV 0 to 50 mV selects the internal temperature sensor 0 to 20 mV COMP_1 REGISTER, A[2:0] = 001 binary 7:0 Eight least significant bits of comparator 1 COMP_2 REGISTER, A[2:0] = 010 binary 7:0 Eight least significant bits of comparator 2 COMP_MSN REGISTER, A[2:0] = 011 binary 7:4 3:0 Four most significant bits of comparator 1 Four most significant bits of comparator 2 MX844 Drawing No. 084423 8 08/25/06 www.claremicronix.com IXYS MX844 ADC_1 REGISTER, A[2:0] = 100 binary 7 DRDY status 0 = data ready 1 = data not ready 6 CMP status 0 = ADC data outside the comparator window 1 = ADC data inside the comparator window 5 4 reserved reserved 3 2 1 0 ADC data D11 ADC data D10 ADC data D9 ADC data D8 ADC_2 REGISTER, A[2:0] = 101 binary 7:0 ADC data D[7:0] Note: Reading this address sets the DRDY and CMP status bits to logic 1 and pins DRDY and CMP = high. EXTERNAL SERIAL EEPROM PROGRAMMING In this mode the MX844 auto-increments the EEPROM address from 0 up to 7 and then the address rolls back to 0. A single EEPROM word is read at the beginning of every ADC auto-zero period and is interpreted by the MX844 as a synchronous serial I/O write command. These commands control the scanning sequence of the ADC channels, the full scale ranges, and the internal dividers. The MX844 accesses the EEPROM as if it were a ROM and will not write or erase the EEPROM. In the master mode the first data bit serially read out of the EEPROM must always be a logic 1 which indicates a write (of the MX844 register). The second through fourth bits are the address field, followed by eight data bits. The last four bits of the EEPROM word are don't cares. One 16-bit word of the 93C46 serial EEPROM is used to hold one MX844 synchronous serial I/O instruction. Each pulse of SCK corresponds to one bit in the EEPROM. However, the data is aligned such that the MX844 R/W bit that occurs at the 5th SCK pulse of the serial interface timing is the MSB in the EEPROM word. The last 4 bits of the EEPROM word are always zero. For example, the instruction to write the byte 1Ah into the MX844 control register (IN2 +/-250mV scale) would be programmed into the EEPROM as the 16-bit quantity 81A0h. Entered into a typical programmer file editor in the leastsignificant-byte first format it would be the byte A0h followed by the byte 81h. Eight pairs of bytes can be specified in the programming file (EEPROM address 0 to 7). The MX844 will ignore the remaining contents of the EEPROM (address > 7). MX844 command: R/W A2 A1 A0 B7 B6 B5 B4 B3 B2 B1 B0 1 0 0 0 0 0 0 1 1 0 1 0 8 EEPROM programmer editor: 1 B3 B2 B1 B0 0 A MX844 Drawing No. 084423 0 0 0 9 A 0 R/W A2 A1 A0 8 B7 B6 B5 B4 1 08/25/06 www.claremicronix.com IXYS MX844 Circuit Examples The two examples shown below are for illustration only, and are not complete schematics. The power dissipation will determine if the external pass element is required regardless of whether an eeprom or a microcontroller are connected. MX844 INTERNAL PASS ELEMENT, SERIAL EEPROM CONNECTION MX844 EXTERNAL PASS ELEMENT, MICROCONTROLLER CONNECTION MX844 Drawing No. 084423 10 08/25/06 www.claremicronix.com IXYS MX844 APPLICATION EXAMPLE - POWER MONITOR This design example illustrates the application of the MX844 as an AC line power monitor. In this design the MX844 operates as a serial bus master, reading instructions from an external serial EEPROM. Following application of power, the first 16-bit word read from the EEPROM is 0x8200 (using "C" notation to indicate a hexadecimal number) which in conjunction with the connection of terminal M1 to VCC, causes the MX844 to set it's internal dividers for 488 A/D samples per second and an asynchronous baud rate of 38.4 Kbaud when using an 8 MHz clock. The first measurement is made from input channel IN1 on the +/- 50 mV scale. For the power meter this is a measurement of the AC line current flowing through sense resistor R1. A value of 0.002 Ohm for R1 results in a +/- 25A current scale. The second instruction is 0x83A0, which results in a measurement from input channel IN2 on the +/- 250 mV scale. For the power meter this is a measurement of the AC line voltage through the voltage attenuator consisting of resistors R2, R3, and R4 which provide a full scale of +/- 407 V. The MX844 cycles through the first eight addresses of the EEPROM. Therefore the first two instruction codes are repeated three more times in order to continuously alternate between AC line voltage and current measurements. This is how the EEPROM contents would appear in a typical programmer buffer editor: 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 A0 00 00 00 00 00 00 00 83 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 A0 00 00 00 00 00 00 00 83 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 A0 00 00 00 00 00 00 00 83 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 82 00 00 00 00 00 00 00 A0 00 00 00 00 00 00 00 83 00 00 00 00 00 00 00 Note that the 16-bit word is broken up into two bytes with the least significant byte first. The power monitor is powered directly off the line using resistors R14 - R20, diodes D1 and D2, and capacitor C1 to produce an unregulated DC voltage for the MX844. Opto-isolator U3 provides isolation between the AC power line and the computer serial port. Dual transistors Q1 and Q2 and related circuitry amplify the photodiode signal into the required RS-232 signal for the computer serial port. Power for the photodiode amplifier is very small and is supplied by the serial port DTR and RTS terminals. By analyzing the data stream from the MX844 the computer software program can determine the RMS line voltage, the RMS line current, the RMS power consumed, and the power factor of the load. Each digitized sample is transmitted to the computer as two 8-bit "characters" in asynchronous RS-232 format. Embedded in the two characters are the 12 bits of data and a 3-bit EEPROM address. MX844 Drawing No. 084423 11 08/25/06 www.claremicronix.com IXYS MX844 The software performs the following tasks: 1) 2) 3) 4) Synchronize to the EEPROM address. Acquire 256 samples. Separate into 128 voltage readings and 128 current readings. Calculate the RMS value of the voltage and the current (standard deviation of the 128 data set). Apparent power is Vrms * Irms. 5) Perform "flat top" windowing and then FFT on the voltage to determine the whether the frequency is 60Hz or 50Hz. The FFT also gives an RMS amplitude value for the voltage. 6) Determine the voltage at the time of the current measurements by sine wave interpolation between each pair of voltage readings. 7) Calculate the real power using the 128 measured current values and the 128 interpolated voltage values. Also calculate the power factor. Program listing: /* /* /* /* /* /* This program reads alternating samples of voltage and current from the MX844 AOUT terminal which is connected to a PC com1 port with the demo board circuitry. This demo program directly accesses the PC's 16550 UART using inp() and outp() functions and therefore must be compiled and run in real mode (DOS box) under win98. */ */ */ */ */ */ #include <stdio.h> #include <conio.h> #include <math.h> void frier(double *, double *, int); int round(double); #define NMAX 256 double xd[NMAX+2]; double yd[NMAX+2]; double pd[NMAX+2]; FILE *inf; int lost, m, onez, twoz, rdata, i, j, w, d[4*NMAX]; int ad[NMAX], ad2[NMAX], n[NMAX], n2[NMAX]; long t; int np,imax; double rt2,ln10,min,max,fmax,k,pi,nbw,resHz,samHz; double wt, b, a, vrms, irms, pf, rp, cv; double ivsum, sum, ss, sumi, ssi, aw, av; float vscale, iscale; main(argc,argv) int argc; char *argv[]; { rt2 = sqrt(2); ln10 = log(10); pi = 4 * atan(1); np = 128; /* number of points in FFT time series */ /* use the following line for 12MHz clock with a divider of 8 or 6MHz clock with a divider of 4 */ /* samHz = 12e6/8/4096/2;*/ /* use the following line for 8MHz clock with a divider of 4 */ samHz = 8e6/4/4096/2; vscale = (0.250 / 2048) * 1629 ; /* 440K & 270 resistor divider */ iscale = (0.050 / 2048) / 0.002; /* 0.002 ohm shunt */ MX844 Drawing No. 084423 12 08/25/06 www.claremicronix.com IXYS MX844 /* setup the com1 port */ outp(0x3fb,0x83); /* 8 bits no parity, outp(0x3f9,0); /* upper divisor = 0 /*outp(0x3f8,4);*/ /* lower divisor = outp(0x3f8,3); /* lower divisor = 3 outp(0x3fc,1); /* DTR +V, RTS -V */ outp(0x3fb,3); /* DLAB = 0 */ DLAB=1 */ */ 4 (28800 baud) */ (38400 baud) */ /* open the output log file */ inf = fopen("meter.log","w"); /* initialize arrays */ for(i=0;i<np;i++) { ad[i] = 0; ad2[i] = 0; n[i] = 0; n2[i] = 0; } for(i=0;i<4*np;i++) d[i] = 0; /* start data acquisition from MX844 */ lost = 1; while(lost == 1) { /* synchronize to MX844 async data stream */ /* find n0,n1 = 00 and n2,n3 = 00 */ twoz = 0; while (twoz == 0) { onez = 0; /* read bytes until n0,n1 = 00 */ while (onez == 0) { w = 0; while ((inp(0x3fd) & 1) == 0) d[0] = inp(0x3f8); if((d[0] & 0x00c0) == 0) onez } /* read the next byte */ w = 0; while ((inp(0x3fd) & 1) == 0) {w=1;} d[1] = inp(0x3f8); if((d[1] & 0x00c0) == 0) twoz = 1; else /* change "phase" */ { w = 0; while ((inp(0x3fd) & 1) == 0) d[0] = inp(0x3f8); } } /* end twoz */ {w=1;} /*wait for data ready*/ = 1; /* wait for data ready */ {w=1;} /*wait for data ready*/ m=0; /* read the actual data */ for(i=2;i<4*np;i++) { w = 0; while ((inp(0x3fd) & 1) == 0) {w=1;} /*wait for data ready */ d[i] = inp(0x3f8); if(w==0) m++; /* printf("\n%02X %1d",d[i],w); */ } /* check for loss of sync in the data */ lost = 0; for(i=0;i<np;i++) { m = ((0xc0 & d[2*i])>>6)+((0xc0 & d[2*i+1])>>4); if(m != i % 8) lost = 1; } if (lost == 1) { printf("lost sync\n"); for(t=0;t<200000;t++); /* wait to try again */ } } /* done with acquisition */ MX844 Drawing No. 084423 13 08/25/06 www.claremicronix.com IXYS MX844 /* separate voltage and current, report data */ for(i=0;i<np;i++) { ad[i] = (0x3f & d[4*i])+(64*(0x3f & d[4*i+1])); ad2[i] = (0x3f & d[4*i+2])+(64*(0x3f & d[4*i+3])); n[i] = ((0xc0 & d[4*i])>>6)+((0xc0 & d[4*i+1])>>4); n2[i] = ((0xc0 & d[4*i+2])>>6)+((0xc0 & d[4*i+3])>>4); } /* report voltage readings */ fprintf(inf,"Raw data: (n2,n1,n0) <ADC counts>\n"); fprintf(inf,"Voltage:\n"); for(i=0;i<np;i++) { fprintf(inf,"(%1d)%4d ",n[i],ad[i]); if(i%8 == 7) fprintf(inf,"\n"); } fprintf(inf,"\n"); /* report current readings */ fprintf(inf,"Current:\n"); for(i=0;i<np;i++) { fprintf(inf,"(%1d)%4d ",n2[i],ad2[i]); if(i%8 == 7) fprintf(inf,"\n"); } /* calculate Vrms */ sum = 0; ss = 0; for(i=0;i<np;i++) { sum += ad[i]; ss += (double)ad[i] * (double)ad[i]; } vrms = sqrt(ss/np - (sum/np)*(sum/np)); fprintf(inf,"\n%8.1f Volts rms\n",vrms * vscale); printf("\n%8.1f Volts rms\n",vrms * vscale); /* calculate Irms */ sumi = 0; ssi = 0; for(i=0;i<np;i++) { sumi += ad2[i]; ssi += (double)ad2[i] * (double)ad2[i]; } irms = sqrt(ssi/np - (sumi/np)*(sumi/np)); fprintf(inf,"%8.2f Amps rms\n",irms * iscale); printf("%8.2f Amps rms\n",irms * iscale); /* calculate apparent power (VA) */ aw = vrms * vscale * irms * iscale; printf("%8.1f VA\n",aw); fprintf(inf,"%8.1f VA\n",aw); fprintf(inf,"%5.1f calculated average V counts\n",sum/np); fprintf(inf,"%5.1f calculated average I counts\n",sumi/np); av = sum/np; /* fill the FFT data arrays */ for(i=1;i<=np;i++) /* fft data [1..np] instead of [0..np-1] */ { xd[i] = ad[i-1]; yd[i] = 0; } xd[0] = 0; yd[0] = 0; xd[np+1] = 0; yd[np+1] = 0; /* perform the windowing */ k = 2 * pi / (np - 1); /* i*k==0 if i=0, ==2*pi if i=127 */ for(i=0;i<np;i++) { /* remember [1..np] */ xd[i+1] *= 1-1.8533*cos(i*k)+0.7046*cos(2*i*k); } MX844 Drawing No. 084423 14 08/25/06 www.claremicronix.com IXYS MX844 resHz = samHz / np; nbw = 3.44 * resHz; /* frequency resolution */ /* calculate noise bandwidth */ frier(xd,yd, round(log(np)/log(2))); /* report the FFT result */ max = 0; for(i=1;i<=1+np/2;i++) { pd[i] = rt2 * sqrt(pow(xd[i],2) + pow(yd[i],2)); fprintf(inf,"%8.2f %12.4f",resHz*(i-1),pd[i]); fprintf(inf," %12.4f %12.4f\n",xd[i],yd[i]); if((pd[i] > max) && i>9) { max = pd[i]; imax = i; fmax = resHz*(i-1); } } if(pd[imax+1]/pd[imax] > 0.8) fmax += resHz/2; if(pd[imax-1]/pd[imax] > 0.8) fmax -= resHz/2; fmax = (double)round(fmax); fprintf(inf,"%5.1f Vrms from FFT at %2.0f Hz\n",max*vscale,fmax); /* interpolate V at time of I and calculate real power */ fprintf(inf,"Instantaneous VA:\n"); ivsum = 0; for(i=0;i<np-1;i++) { b = (double)ad[i] - av; wt = 2*pi*fmax/samHz; a = ((double)ad[i+1]-av-b*cos(wt))/sin(wt); wt = 2*pi*fmax*0.5/samHz; cv = a*sin(wt) + b*cos(wt); rp = -(iscale*(ad2[i] - av)*vscale*cv); fprintf(inf,"%7.2f ",rp); if(i%8 == 7) fprintf(inf,"\n"); ivsum += rp; } /* the last data point is special */ wt = 2*pi*fmax*1.5/samHz; cv = a*sin(wt) + b*cos(wt); rp = -(iscale*(ad2[np-1] - av)*vscale*cv); fprintf(inf,"%7.2f ",rp); if(i%8 == 7) fprintf(inf,"\n"); ivsum += rp; /* report the results */ fprintf(inf,"\n"); if(ivsum < 0) ivsum = -ivsum; printf("%8.1f real watts\n",ivsum/np); fprintf(inf,"%8.1f real watts\n",ivsum/np); pf = (ivsum/np) / aw; if(pf>1) pf=1; printf("%8.2f power factor\n",pf); fprintf(inf,"%8.2f power factor\n",pf); fclose(inf); } /* end main */ /* rounding function */ int round(double x) { if(x>0) return((int) (x + 0.5)); else return((int) (x - 0.5)); } MX844 Drawing No. 084423 15 08/25/06 www.claremicronix.com IXYS MX844 /* FFT routine */ void frier(double *x, double *y, int ig) /* ig = number of points as a power of 2 */ /* for example, ig = 8 for 256 point FFT */ { double p,y1,y2,y3,y4; int n,m,m1,m2,k,k1,k2,k3,k4,k5,i,j,l,ig1; n = 1 << ig; p = 8 * atan(1) / n; for(i=1;i<=n;i++) { *(x+i) /= n; *(y+i) /= n; } for(l=1;l<=ig;l++) { ig1 = 1 << (ig-l); m = 0; k4 = 1 << (l-1); for(i=1;i<=k4;i++) { k1 = m / ig1; k2 = 0; k3 = 1 << (ig-1); for(k=1;k<=ig;k++) { if((1 & k1) == 1) k2 += k3; k3 >>= 1; k1 >>= 1; } y1 = cos(p*k2); y2 = -sin(p*k2); for(k=1;k<=ig1;k++) { m1 = m + ig1 + 1; m2 = m + 1; y3 = *(x+m1) * y1 - *(y+m1) * y2; y4 = *(x+m1) * y2 + *(y+m1) * y1; *(x+m1) = *(x+m2) - y3; *(y+m1) = *(y+m2) - y4; *(x+m2) += y3; *(y+m2) += y4; m++; } m += ig1; } } for(i=1;i<=n;i++) { k1 = i - 1; k2 = 0; k3 = 1 << (ig-1); for(k=1;k<=ig;k++) { if((1 & k1) == 1) k2 += k3; k3 >>= 1; k1 >>= 1; } k5 = k2 + 1; if((k5-i) < 0) { y3 = *(x+i); *(x+i) = *(x+k5); *(x+k5) = y3; y3 = *(y+i); *(y+i) = *(y+k5); *(y+k5) = y3; } } } MX844 Drawing No. 084423 16 08/25/06 www.claremicronix.com IXYS MX844 POWER MONITOR DEMO BOARD CIRCUIT SCHEMATIC P1 5 4 R13 10K 5 3 U3 4N35S 1 5 2 6 R8 330K R7 470 + D2 S1J C1 100uF D1 15V R6 100K C3 3.3nF C4 22nF R22 470 R14 1K R15 1K R16 1K R17 1K 8 9 10 11 12 13 14 IN1N IN2P IN2N R9 470K 6 Q1B 2 3 Q1A 4 R10 7.5K 1 Q2B 6 R11 47K VCC TVCC CMP AOUT 8 MHz 28 27 26 25 24 23 22 Resonator X1 21 X2 1 GND 1 VTRIM 2 20 X1 3 BUF 3 U1 19 CS IZ 4 MX844 18 SDI CAZ 5 17 SDO CINT 6 16 SCK IN1P 7 15 DRDY C5 10nF R21 470 VIN RIN DRV 5 2 1 R12 150K C6 10nF 2 7 4 Q2A R5 22K SYNC M1 IN3N IN3P 8 VCC 1 4 3 2 CS DO DI CLK ORG 6 VSS 5 U2 93C46 + C8 10 uF C2 0.1uF C5 10nF R4 270 R18 1K R19 1K R20 1K R3 220K R2 220K 2 1 R1 0.002 1 P2 MX844 Drawing No. 084423 2 P3 17 08/25/06 www.claremicronix.com IXYS MX844 POWER MONITOR PRINTED CIRCUIT DEMO BOARD LAYOUT Artwork scale approximately actual size. P1 is a DB-9 connector for RS-232 connection. P2 and P3 are screw-type terminals for AC power line connection. All other components are surface mount. Silkscreen: Top Layer: Isolation path Bottom Layer: MX844 Drawing No. 084423 18 08/25/06 www.claremicronix.com IXYS MX844 POWER MONITOR PRINTED CIRCUIT BOARD PARTS LIST U1 U2 MICRONIX MX844 MICROCHIP 93LC46B Serial EEPROM 28-QFN 5x5mm 8-SOIC U3 LiteOn 4N35S Opto-isolator 6-SMT Q1 Q2 ON Semi MBT3904 ON Semi MBT3906 Dual 2N3904 Dual 2N3906 SOT-363 SOT-363 D1 D2 ON Semi MMSZ5245B Fairchild S1J 15V 0.5W Zener 600V Rectifier SOD-123 SMA X1 Abracon AWSCR-8.00MGD-T 8MHz Resonator 7434-SMT C1 C2 C3 Nichicon UWX1C101MCL1GB 100uF 16V Murata GRM155F51C104ZA01D 0.1uF Y5V 16V Murata GRM2165C1H332JA01D 3300pF COG 5% (low loss for integrator, COG acceptable, metal film is better) 6.3x5.4 SMT 0402 0805 C4 Murata GRM188R71H223MA01D C5-C7 Murata GRM155R71E103KA01D C8 Nichicon F931A106MAA 0.022uF X7R 20% 0.01uF X7R 10% 10 uF 10V 0603 0402 3.2 by 1.6 SMT R1 Panasonic ERJ-M1WTF2M0U R2-3 R4 R5 R6 R7, R21, R22 R8 R9 R10 R11 R12 R13 R14-R20 0.002 220K 270 22K 100K 470 330K 470K 7.5K 47K 150K 10K 1K (current sense type) P1 NORCOMP 182-009-212-531 2512 1206 0603 0603 0603 0603 0603 0603 0603 0603 0603 0603 1206 DB-9 for computer serial port P2, P3 Phoenix Contact MKDS 5/2-9.5 1714971 MX844 Drawing No. 084423 1% 1% 1% Suitable for AC line connection 19 08/25/06 www.claremicronix.com IXYS MX844 28 LEAD 5MM X 5MM X 0.90MM QFN PIN 1 (REF.) DIMENSIONS DIM. A A1 A2 b D D2 E E2 INCH MM. MIN. MAX. MIN. MAX. .031 .039 .80 1.0 0 .002 0 .05 .008 REF. .007 .012 .197 BSC .118 .128 .197 BSC .118 .128 e .0197 BSC L .0177 .0256 N 28 ,200 REF. .18 .30 5.00 BSC 3.00 TOP VIEW 3.25 5.00 BSC 3.00 3.25 .500 BSC .45 SIDE VIEW .65 28 3. MOLDED PACKAGE SHALL CONFORM TO JEDEC STANDARD CONFIGURATION MO-220 VARIATION VHHD-1. 2. DIMENSIONS AND TOLERANCING CONFORM TO ASME Y14.5M-1994. 1. COPLANARITY APPLIES TO THE EXPOSED HEAT SINK SLUG AS WELL AS THE TERMINALS. NOTES: (UNLESS OTHERWISE SPECIFIED) BOTTOM VIEW IXYS Corporation makes no representations or warranties with respect to the accuracy or completeness of the contents of this publication and reserves the right to make changes to specifications and product descriptions at any time without notice. Neither circuit patent licenses nor indemnity are expressed or implied. Except as set forth in IXYS’ Standard Terms and Conditions of Sale, IXYS Corporation assumes no liability whatsoever, and disclaims any expressed or implied warranty, relating to its products including, but not limited to, the implied warranty of merchantability, fitness for a particular purpose, or infringement of any intellectual property right. MX844 Drawing No. 084423 20 08/25/06 www.claremicronix.com IXYS World Wide Sales Offices IXYS Corporation 3540 Bassett Street Santa Clara, CA 925054 Tel: 1-408-892-0700 Fax: 1-408-496-0670 e-mail:[email protected] United Kingdom IXYS Semiconductor Limited Langley Park Way Langley Park Chippenham Wiltshire SN 15 1GE - England Tel: 44 1249 444524 Fax: 44 1249 659448 [email protected] Micronix An IXYS Company 145 Columbia Aliso Viejo, CA 92656-1490 Tel: 1-949-831-4622 Fax: 1-949-831-4628 Sales Offices ASIA / PACIFIC Asian Headquarters IXYS Room 1016, Chia-Hsin, Bldg II, 10F, No. 96, Sec. 2 Chung Shan North Road Taipei, Taiwan R.O.C. Tel: 886-2-2523-6368 Fax: 886-2-2523-6368 [email protected] [email protected] SALES OFFICES AMERICAS Eastern Region [Eastern North America, Mexico, South America] IXYS Corporation Beverly, MA Tel: 508-528-6883 Fax: 508-528-4562 [email protected] Check the IXYS Website for the local sales office nearest you. (www.ixys.com) Central Region [Central North America] IXYS Corporation Greensburg, PA Tel: 724-836-8530 Fax: 724-836-8540 [email protected] Western Region [Western North America] IXYS Coporation Solana Beach, CA Tel: 858-792-1101 [email protected] SALES OFFICES EUROPE http://www.claremicronix.com European Headquarters IXYS Semiconductor GMBH Edisonstrasse 15 D- 68623 Lampertheim Germany Tel: 49-6206-503203 Fax: 49-6206-503286 [email protected] MX844 Drawing No. 084423 IXYS cannot assume responsibility for use of any circuitry other than circuitry entirely embodied in this IXYS product. No circuit patent licenses nor indemnity are expressed or implied. IXYS reserves the right to change the specification and circuitry, without notice at any time. The products described in this document are not intended for use in medical implantation or other direct life support applications where malfunction may result in direct physical harm, injury or death to a person. Specification: MX844 ©Copyright 2006, IXYS Corporation All rights reserved. Printed in USA. 21 08/25/06 www.claremicronix.com