• 0

2.7 Voltage cap on mesurements


Go to solution Solved by attila,

Question

I am using the python API for Waveforms to interface an Analog Discovery 2 and are trying monitor a voltage. The problem is that the measurements on channel 1 are capped to about 2.7 Volt wile channel 2 can measure up to 12.5 (the voltage I am supposed to measure) just fine. When I open Waveforms and use the scope there everything seems to work just fine.

I am using the example code from AnalogIn_Record.py whit some small cleanup/modifications.

Does anyone have an idea what I might be doing wrong?

"""
   DWF Python Example
   Author:  Digilent, Inc.
   Revision:  2018-07-19

   Requires:                       
       Python 2.7, 3
"""

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


dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf")

class AnalogDiscovery2():
    def __init__(self):
        self.hdwf = c_int()
        dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))

    def record_analog_in(self, pin, duartion):
        return

    def __del__(self):
        dwf.FDwfDeviceCloseAll()

def rec(fs, duration_seconds=1, infinite=False):
    #declare ctype variables
    hdwf = c_int()
    sts = c_byte()
    hzAcq = c_double(fs)
    nSamples = duration_seconds * fs
    rgdSamples_1 = (c_double*nSamples)()
    rgdSamples_2 = (c_double*nSamples)()
    cAvailable = c_int()
    cLost = c_int()
    cCorrupted = c_int()
    fLost = 0
    fCorrupted = 0

    #open device
    print("Opening first device")
    dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))

    if hdwf.value == hdwfNone.value:
        szerr = create_string_buffer(512)
        dwf.FDwfGetLastErrorMsg(szerr)
        print(str(szerr.value))
        print("failed to open device")
        quit()

    #set up acquisition
    dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True))
    dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5))
    dwf.FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeRecord)
    dwf.FDwfAnalogInFrequencySet(hdwf, hzAcq)
    if infinite:
        dwf.FDwfAnalogInRecordLengthSet(hdwf, -1)#) # -1 infinite record length
    else:
        dwf.FDwfAnalogInRecordLengthSet(hdwf, c_double(nSamples/hzAcq.value))
        
    #wait at least 2 seconds for the offset to stabilize
    time.sleep(2)

    print("Starting oscilloscope")
    dwf.FDwfAnalogInConfigure(hdwf, c_int(0), c_int(1))

    cSamples = 0
    time_start = time.time()

    while (cSamples < nSamples):
        dwf.FDwfAnalogInStatus(hdwf, c_int(1), byref(sts))
        if cSamples == 0 and (sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed) :
            # Acquisition not yet started.
            continue

        dwf.FDwfAnalogInStatusRecord(hdwf, byref(cAvailable), byref(cLost), byref(cCorrupted))
        
        cSamples += cLost.value

        if cLost.value :
            fLost = 1
        if cCorrupted.value :
            fCorrupted = 1

        if cAvailable.value==0 :
            continue

        if cSamples+cAvailable.value > nSamples :
            cAvailable = c_int(nSamples-cSamples)
        
        dwf.FDwfAnalogInStatusData(hdwf, c_int(0), byref(rgdSamples_1, sizeof(c_double)*cSamples), cAvailable) # get channel 1 data
        dwf.FDwfAnalogInStatusData(hdwf, c_int(1), byref(rgdSamples_2, sizeof(c_double)*cSamples), cAvailable) # get channel 2 data
        cSamples += cAvailable.value

    time_used = time.time() - time_start
    dwf.FDwfAnalogOutReset(hdwf, c_int(0))
    dwf.FDwfDeviceCloseAll()

    print("Recording done")
    if fLost:
        print("Samples were lost! Reduce frequency")
    if fCorrupted:
        print("Samples could be corrupted! Reduce frequency")

    data_1 = np.fromiter(rgdSamples_1, dtype = np.float)
    data_2 = np.fromiter(rgdSamples_2, dtype = np.float)
    t = np.linspace(0, time_used, len(data_1))
    np.save("data_1", data_1)
    np.save("data_2", data_2)
    np.save("time", t)
    
if __name__ == "__main__":
    rec(100, 2)

 

Link to post
Share on other sites

3 answers to this question

Recommended Posts

  • 1
  • Solution

Hi @Amund

You have configured the Scope Channel 1 to 5V pk2pk range. This, with the default 0V offset will have input range of about +/-2.5V
The AD has 2 input ranges approximately 5Vpk2pk and 50Vpk2pk. Use:
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(50))

Link to post
Share on other sites
  • 0

Hi @Amund,

I have moved your thread to a more appropriate section of the forum where the engineer more experienced with the scripts associated with the WaveForms software will be able to see and respond to your question.

Thanks,
JColvin

Link to post
Share on other sites
  • 0
On 7/24/2020 at 11:09 AM, attila said:

Hi @Amund

You have configured the Scope Channel 1 to 5V pk2pk range. This, with the default 0V offset will have input range of about +/-2.5V
The AD has 2 input ranges approximately 5Vpk2pk and 50Vpk2pk. Use:
dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(50))

Ah, of course! Thank you very much!

Link to post
Share on other sites

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