Post Go back to editing

AD5933 Measurement (Status Reg)

Thread Summary

The user encountered incorrect impedance measurements with the AD5933 IC, receiving 0x60 and 0x66 in the Status Register and consistently high real data values (around 65k). The issue was resolved by converting the DFT output from two's complement in the code. The final code correctly handles the conversion, resulting in accurate measurements across different frequencies.
AI Generated Content

Hello,

im pretty new in programming IC's so please excuse my mistakes if they are dumb. So i use a Raspberry Pi for the communication and my code is in Python. My problem is i always keep getting 0x60, 0x66 in the Status Register which makes no sense. Just sometimes i get 0x62 which should indicate valid real/img data. As a result my measurements are wrong. I can show you my code maybe there are some mistakes

import smbus

import math

bus = smbus.SMBus(1)


ADRESSE = 0x0D

j=0

x=0


 

#Startfrequency

bus.write_byte_data(ADRESSE, 0x82, 0x07)          #051EB8 @10khz #028F5C @5khz

bus.write_byte_data(ADRESSE, 0x83, 0xAE)         #0F5C28 @30khz #07AE14 @15 khZ

bus.write_byte_data(ADRESSE, 0x84, 0x14)          #199999 @50khz #0CCCCC @25khz


 

#Frequency increment

bus.write_byte_data(ADRESSE, 0x85, 0x00)          #00014F @10hz

bus.write_byte_data(ADRESSE, 0x86, 0x41)          #004189 @500hz

bus.write_byte_data(ADRESSE, 0x87, 0x89)


 

#Number of increments

bus.write_byte_data(ADRESSE, 0x88, 0x00)

bus.write_byte_data(ADRESSE, 0x89, 0x96)


 

#Control Register Settling Time Cycles

bus.write_byte_data(ADRESSE, 0x8A, 0x00)

bus.write_byte_data(ADRESSE, 0x8B, 0x32)


   

#Control Register Standby Mode

bus.write_byte_data(ADRESSE, 0x80,bus.read_byte_data(ADRESSE,0x80)&0x07 |0xB0)

 

#Control Register Initialiaze with start frequency

bus.write_byte_data(ADRESSE, 0x80, bus.read_byte_data(ADRESSE,0x80)&0x07 |0x10)

  #Control Register Start Frequency Sweep

bus.write_byte_data(ADRESSE, 0x80, bus.read_byte_data(ADRESSE,0x80)&0x07 |0x20)


  #Control Register Increment Frequency

bus.write_byte_data(ADRESSE, 0x80, bus.read_byte_data(ADRESSE,0x80)&0x07 |0x31)

bus.write_byte_data(ADRESSE, 0x81, bus.read_byte_data(ADRESSE,0x80)&0x07 |0x00)


 


while x<8000:

  status = bus.read_byte_data(ADRESSE,0x8F)

  if status==0x62:

  real1= bus.read_byte_data(ADRESSE, 0x94)

  real2= bus.read_byte_data(ADRESSE, 0x95)

  imag1= bus.read_byte_data(ADRESSE, 0x96)

  imag2= bus.read_byte_data(ADRESSE, 0x97)

  r= (real1*256)+real2

  i= (imag1*256)+imag2

  #Magnitude Calculation

b=math.sqrt((r**2)+(i**2))

  #Gain Factior

  c=4.62e-11                #515.819e-12 #5.39e-11#6.93e-11

  #Impedance Calculation

  z=1/(b*c)

  print (z)

  print (r)

  print ( i)

  print (status)

  break

  if status!=0x62:

bus.write_byte_data(ADRESSE, 0x80,bus.read_byte_data(ADRESSE,0x80)&0x07 | 0x30)

print(status)

  x=x+1


 

  • Meanwhile i've managed to get 0x47 in the Status Reg. which would be valid Temp., valid re/im data and frequency sweep complete. But my values seem to be wrong. I am keep getting around 65533 for Re and around 3 for Im. I would really appreciate it if anyone could help me.

    My new Code is:

     

    import smbus

    import math

    bus = smbus.SMBus(1)


    ADRESSE = 0x0D

    j=0

    x=0

    q=0

     

    #Startfrequency

    bus.write_byte_data(ADRESSE, 0x82, 0x0F)          #051EB8 @10khz #028F5C @5khz

    bus.write_byte_data(ADRESSE, 0x83, 0x5C)         #0F5C28 @30khz #07AE14 @15 khZ

    bus.write_byte_data(ADRESSE, 0x84, 0x28)          #199999 @50khz #0CCCCC @25khz

     

    #Frequency increment

    bus.write_byte_data(ADRESSE, 0x85, 0x00)          #00014F @10hz

    bus.write_byte_data(ADRESSE, 0x86, 0x01)          #004189 @500hz

    bus.write_byte_data(ADRESSE, 0x87, 0x40)

     

    #Number of increments

    bus.write_byte_data(ADRESSE, 0x88, 0x01)

    bus.write_byte_data(ADRESSE, 0x89, 0xFF)

     

    #Control Register Settling Time Cycles

    bus.write_byte_data(ADRESSE, 0x8A, 0x00)

    bus.write_byte_data(ADRESSE, 0x8B, 0x0F)


    #Control Register Standby Mode

    bus.write_byte_data(ADRESSE, 0x80,bus.read_byte_data(ADRESSE,0x80)&0x07 |0xB1)

    #Control Register Initialiaze with start frequency

    bus.write_byte_data(ADRESSE, 0x80, bus.read_byte_data(ADRESSE,0x80)&0x07 |0x11)

      #Control Register Start Frequency Sweep

    bus.write_byte_data(ADRESSE, 0x80, bus.read_byte_data(ADRESSE,0x80)&0x07 |0x21)

     

     

     

    while q<520:

      status = bus.read_byte_data(ADRESSE,0x8F)

      flag = bus.read_byte_data(ADRESSE,0x8F) & 4

      q=q+1

      if flag==4:

      real1= bus.read_byte_data(ADRESSE, 0x94)

      real2= bus.read_byte_data(ADRESSE, 0x95)

      imag1= bus.read_byte_data(ADRESSE, 0x96)

      imag2= bus.read_byte_data(ADRESSE, 0x97)

      r= (real1*256)+real2

      i= (imag1*256)+imag2

      #Magnitude Calculation

      b=math.sqrt((r**2)+(i**2))

      #Gain Factior

      c=4.62e-11                #515.819e-12 #5.39e-11#6.93e-11

      #Impedance Calculation

      z=1/(b*c)

      print (z)

      print (r)

      print ( i)

      print (status)

      break

      if (bus.read_byte_data(ADRESSE,0x8F)&0x07)<4:

    bus.write_byte_data(ADRESSE, 0x80,bus.read_byte_data(ADRESSE,0x80)&0x07 | 0x31)

  • Hi,

    Your program looks fine to me.

    Can you try to measure the impedance you are using to calibrate the system?

    Best regards,

    Mark

  • Hey Mark,

    thanks for your answer. Do you mean to calculate the gain factor with the values i get from the impedance? Because when i calculate it (Re:65533, Im:5) i keep getting the same Impedance for all kind of different impedances for expamle for 180k Ohm, 330k Ohm etc.

  • Hi,

    I think this application note might help you.

    Best regards,

    Mark

  • Hey,

    yea i've already read the application note but didnt really help. I am not sure what is really wrong now. Maybe there is something wrong with my circuit.

    Meanwhile i've changed my Code a little bit and now the imaginary Datas are pretty good. So they are not around 5 anymore and real data isnt also around 65k.

    import smbus

    import math

    START_FREQ_1=0x82

    START_FREQ_2=0x83

    START_FREQ_3=0x84

    FREQ_INC_1=0x85

    FREQ_INC_2=0x86

    FREQ_INC_3=0x87

    NUM_FREQ_1=0x88

    NUM_FREQ_2=0x89

    SETTL_CYCL_1=0x8A

    SETTL_CYCL_2=0x8B

    CNTRL_1=0x80

    CNTRL_2=0x81

    STATUS_REG=0x8F

    TEMP_1=0x92

    TEMP_2=0x93

    REAL_1=0x94

    REAL_2=0x95

    IMAG_1=0x96

    IMAG_2=0x97

    bus = smbus.SMBus(1)

    ADRESSE = 0x0d

    j=0

    x=0

    c=0

    q=0

    #Startfrequency

    bus.write_byte_data(ADRESSE, START_FREQ_1, 0x0E)#051EB8 @10khz #028F5C @5khz #0EA645 @30khz (16,776mhz)

    bus.write_byte_data(ADRESSE, START_FREQ_2, 0xA6)#0F5C28 @30khz #07AE14 @15 khZ #075322 @ 15khz (16,776mhz)

    bus.write_byte_data(ADRESSE, START_FREQ_3, 0x45)#199999 @50khz #0CCCCC @25khz

    #Frequency increment

    bus.write_byte_data(ADRESSE, FREQ_INC_1, 0x00)#00014F @10hz #000140 @10hz(16,776mhz)

    bus.write_byte_data(ADRESSE, FREQ_INC_2, 0x01)#004189 @500hz #003E81 @500hz (16,776mhz)

    bus.write_byte_data(ADRESSE, FREQ_INC_3, 0x40)

    #Number of increments

    bus.write_byte_data(ADRESSE, NUM_FREQ_1, 0x01)#0096 @ 150

    bus.write_byte_data(ADRESSE, NUM_FREQ_2, 0xff)#01FF @ 511

    #Control Register Settling Time Cycles

    bus.write_byte_data(ADRESSE, SETTL_CYCL_1, 0x00)

    bus.write_byte_data(ADRESSE, SETTL_CYCL_2, 0x0F)

    #Control Register Standby Mode

    bus.write_byte_data(ADRESSE, CNTRL_1,bus.read_byte_data(ADRESSE,CNTRL_1)&0x07 |0xB0)

    #Control Register Initialiaze with start frequency

    bus.write_byte_data(ADRESSE, CNTRL_1, bus.read_byte_data(ADRESSE,CNTRL_1)&0x07 |0x10)

    while x<10000:

        x=x+1

    #Control Register Start Frequency Sweep

    bus.write_byte_data(ADRESSE, CNTRL_1,bus.read_byte_data(ADRESSE,CNTRL_1)&0x07 |0x20)

    status=bus.read_byte_data(ADRESSE,STATUS_REG)

    while (bus.read_byte_data(ADRESSE,STATUS_REG)&0x07)<4:

        status=bus.read_byte_data(ADRESSE,STATUS_REG)

        while (bus.read_byte_data(ADRESSE,STATUS_REG)&0x02)==0:

            bus.read_byte_data(ADRESSE,STATUS_REG)

        flag=bus.read_byte_data(ADRESSE,STATUS_REG)&2

        flag2=bus.read_byte_data(ADRESSE,STATUS_REG)&4

        if (flag==2)&(flag2!=4):

            real1= bus.read_byte_data(ADRESSE, REAL_1)

            real2= bus.read_byte_data(ADRESSE, REAL_2)

            imag1= bus.read_byte_data(ADRESSE, IMAG_1)

            imag2= bus.read_byte_data(ADRESSE, IMAG_2)

          

            #Temp

            bus.write_byte_data(ADRESSE, CNTRL_1, bus.read_byte_data(ADRESSE,CNTRL_1)&0x07 |0x90)

            f=bus.read_byte_data(ADRESSE, TEMP_1)

            g=bus.read_byte_data(ADRESSE, TEMP_2)

            h=(f*256)+g

            if h<8192:

                h=h/32

            else:

                h=h-16384

                h=h/32

         

            r= (real1*256)+real2

            i= (imag1*256)+imag2

            #Magnitude Calculation

            b=math.sqrt((r**2)+(i**2))

          

            #Gain Factior

            c=1.0756009e-10 #8.04780e-11

          

            #Impedance Calculation

            z=1/(b*c)

            print '******************'

            print '|Z|=',int (z), 'Ohm'

            print 'RE:',r

            print 'IM:',i

            print 'Temp:', int (h), 'Grad'

            print 'Status Reg:',bus.read_byte_data(ADRESSE,STATUS_REG)

            print '******************'

        if flag2==4:

            real1= bus.read_byte_data(ADRESSE, REAL_1)

            real2= bus.read_byte_data(ADRESSE, REAL_2)

            imag1= bus.read_byte_data(ADRESSE, IMAG_1)

            imag2= bus.read_byte_data(ADRESSE, IMAG_2)

          

            #Temp

            bus.write_byte_data(ADRESSE, CNTRL_1, bus.read_byte_data(ADRESSE,CNTRL_1)&0x07 |0x90)

            f=bus.read_byte_data(ADRESSE, TEMP_1)

            g=bus.read_byte_data(ADRESSE, TEMP_2)

            h=(f*256)+g

            if h<8192:

                h=h/32

            else:

                h=h-16384

                h=h/32

         

            r= (real1*256)+real2

            i= (imag1*256)+imag2

            #Magnitude Calculation

            b=math.sqrt((r**2)+(i**2))

          

            #Gain Factior

            c=1.0756009e-10 #8.04780e-11

            #Impedance Calculation

            z=1/(b*c)

            print '******************'

            print 'RESULT'

            print '|Z|=',int (z), 'Ohm'

            print 'RE:',r

            print 'IM:',i

            print 'Temp:', int (h), 'Grad'

            print 'Status Reg:',bus.read_byte_data(ADRESSE,STATUS_REG)

            print '******************'

            break

      

        if (bus.read_byte_data(ADRESSE,STATUS_REG)&0x07)<4:

            bus.read_byte_data(ADRESSE, REAL_1)

            bus.read_byte_data(ADRESSE, REAL_2)

            bus.read_byte_data(ADRESSE, IMAG_1)

            bus.read_byte_data(ADRESSE, IMAG_2)

          

            bus.write_byte_data(ADRESSE, CNTRL_1,bus.read_byte_data(ADRESSE,CNTRL_1)&0x07 | 0x30)

    #Shut Down

    bus.write_byte_data(ADRESSE, CNTRL_1,bus.read_byte_data(ADRESSE,CNTRL_1)&0x07 | 0xA0)

  • Hi,

    Your schematic looks fine to me.

    What measurements are you getting now?

    Also, may I know what is the value of your calibration resistor?

    Best regards,

    Mark

  • Hey Mark,

    i am getting for a 330k Resistor around Re: 63k and Im: 19k. I used to calibrate the gain factor with a 200k Resistor and got 8.047e-11.

    Best regards

  • Hi,

    Using the evaluation board and software, I obtained a gain factor of 5.06e-10 for a 200k calibration resistor and 200k feedback resistor and for the 330k resistor that I measured, I obtained Re: 2020 and Im: -5547.

    I think you can use this thread as a reference for the code.

    Best regards,

    Mark

  • I've now made the Circuit with AFE so with the OP amps as described in CN-0217. When i setup the start frequency at 30k it gives me RE/IM Data around 65k. But when i start at 250 Hz and go up with 10 Hz Steps i get these results

    As you see the RE Data jumps to 65k at 1280 Hz and goes back to "normal" at around 2300 Hz.

    So for certain frequencies it keeps giving me 65k and i dont know why. I've also tried it with different low frequencies but it's the same. At some point it always jumps to 65k.

  • I've managed to get it working now. Just in case someone has a similar issue. The problem was the output of the DFT which is in twos complement. I didn't convert the number so i always kept getting wrong values. I just had to add code to convert the number.