# Amund

Members

2

## Posts posted by Amund

### 2.7 Voltage cap on mesurements

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:

Ah, of course! Thank you very much!

### 2.7 Voltage cap on mesurements

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

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
if infinite:
dwf.FDwfAnalogInRecordLengthSet(hdwf, -1)#) # -1 infinite record length
else:

#wait at least 2 seconds for the offset to stabilize
time.sleep(2)

print("Starting oscilloscope")

cSamples = 0
time_start = time.time()

while (cSamples < nSamples):
if cSamples == 0 and (sts == DwfStateConfig or sts == DwfStatePrefill or sts == DwfStateArmed) :
# Acquisition not yet started.
continue

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)```