Jump to content
  • 0

Help using AnaloImpedance_Measure


Davidson.Cassagnol

Question

Hello, I am trying to graph Impedance and Impedance Phase that is outputted by the code below I have modified AnalogImpedance_Measure.py to only measure DwfAnalogImpedanceImpedance, DwfAnalogImpedanceImpedancePhase and now I need to try and understand where the measurements are being stored so that I can then graph them. I'm creating a subplot for Impedance and another subplot for Impedance Phase, when the code is compiled you can see the output that I get. 

 

 

 


from ctypes import *
from dwfconstants import *
import math
import time
import sys
import numpy
import matplotlib.pyplot as plt
import numpy as np

rgMeasure = [[DwfAnalogImpedanceImpedance,"Impedance","Ohm"],
    [DwfAnalogImpedanceImpedancePhase,"ImpedancePhase","Radian"]]

# load dwf library
if sys.platform.startswith("win"):
    dwf = cdll.LoadLibrary("dwf.dll")
elif sys.platform.startswith("darwin"):
    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")
else:
    dwf = cdll.LoadLibrary("libdwf.so")

# print version information
version = create_string_buffer(16)
dwf.FDwfGetVersion(version)
print("DWF Version: "+str(version.value))

hdwf = c_int()
szerr = create_string_buffer(512)
# try to connect to the first available device
print("Opening first device")
dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))

# print error message if connection fails
if hdwf.value == hdwfNone.value:
    dwf.FDwfGetLastErrorMsg(szerr)
    print(str(szerr.value))
    print("failed to open device")
    quit()

# configure impedance measurement
frequnecy = 1e3
reference = 1e3
print("Reference: "+str(reference)+" Ohm  Frequency: "+str(frequnecy/1e3)+" kHz for nanofarad capacitors")
dwf.FDwfAnalogImpedanceReset(hdwf)
dwf.FDwfAnalogImpedanceModeSet(hdwf, c_int(8)) # 0 = W1-C1-DUT-C2-R-GND, 1 = W1-C1-R-C2-DUT-GND, 8 = AD IA adapter
dwf.FDwfAnalogImpedanceReferenceSet(hdwf, c_double(reference)) # reference resistor value in Ohms
dwf.FDwfAnalogImpedanceFrequencySet(hdwf, c_double(frequnecy)) # frequency in Hertz
dwf.FDwfAnalogImpedanceAmplitudeSet(hdwf, c_double(1))
dwf.FDwfAnalogImpedanceConfigure(hdwf, c_int(1)) # start
time.sleep(1)

dwf.FDwfAnalogImpedanceStatus(hdwf, None) # ignore last capture, force a new one

# measurement reading loop
while True:
    sts = c_byte()
    if dwf.FDwfAnalogImpedanceStatus(hdwf, byref(sts)) == 0: # handle error
        dwf.FDwfGetLastErrorMsg(szerr)
        print(str(szerr.value))
        quit()
    if sts.value == 2:
        break

for i in rgMeasure:
    cval = c_double()
    dwf.FDwfAnalogImpedanceStatusMeasure(hdwf, i[0], byref(cval))
    val = cval.value
    scale = ""
    if i[2] != "Radian":
        if abs(val)>=1e9:
            val /= 1e9
            scale = "G"
        elif abs(val)>=1e6:
            val /= 1e6
            scale = "M"
        elif abs(val)>=1e3:
            val /= 1e3
            scale = "k"
        elif abs(val)<1e-9:
            val *= 1e12
            scale = "p"
        elif abs(val)<1e-6:
            val *= 1e9
            scale = "n"
        elif abs(val)<1e-3:
            val *= 1e6
            scale = "u"
        elif abs(val)<1:
            val *= 1e3
            scale = "m"
    print(i[1]+": "+str(val)+" "+scale+i[2])


dwf.FDwfAnalogImpedanceConfigure(hdwf, c_int(0)) # stop
dwf.FDwfDeviceClose(hdwf)

Screenshot 2022-09-21 134344.png

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...