Acquiring Noisy and Incorrect Data using SCPI and Python

Applications, development tools, FPGA, C, WEB
Post Reply
diminDDL
Posts: 1
Joined: Fri Mar 10, 2023 3:17 pm

Acquiring Noisy and Incorrect Data using SCPI and Python

Post by diminDDL » Fri Mar 10, 2023 3:44 pm

I am facing a major issue with the acquisition of data from the Red Pitaya 125-14 using SCPI commands and Python. Despite my best efforts, the acquired data looks extremely noisy and incorrect, which is causing me a lot of problems.

I have signal generator 1 connected to the oscilloscope channel 1 and have been using that for testing. However, despite my best efforts, the data I am acquiring is not accurate and contains a lot of noise.

I have attached the code and screenshots of the acquired data for reference. I would be grateful if anyone could take a look and suggest any potential solutions to the problem.

Code: Select all

import matplotlib.pyplot as plot
import sys
import redpitaya_scpi as scpi
import numpy as np
from time import sleep
import time

#Setup the connection to the Red Pitaya
IP = "rp-f0a29f.local"
rp_s = scpi.scpi(IP)

#Set the parameters for the signal generator
wave_form = 'SQUARE'
freq = 2000
ampl = 1
#Decimation factor
dec = 32

#Generate the signal
def set_generator(waveform, frequency, amplitude, offset):
    rp_s.tx_txt('GEN:RST')
    rp_s.tx_txt('SOUR1:FUNC ' + str(waveform).upper())
    rp_s.tx_txt('SOUR1:FREQ:FIX ' + str(frequency))
    rp_s.tx_txt('SOUR1:VOLT ' + str(amplitude))
    rp_s.tx_txt('SOUR1:VOLT:OFFS ' + str(offset))
    rp_s.tx_txt('OUTPUT1:STATE ON')
    rp_s.tx_txt('SOUR1:TRIG:INT')

set_generator(wave_form, freq, ampl, 0)
sleep(0.5)

#Define a function to sample the oscilloscope
def sample_oscilloscope():
    #Set the parameters for the acquisition
    rp_s.tx_txt('ACQ:RST')
    rp_s.tx_txt('ACQ:DATA:FORMAT ASCII')
    rp_s.tx_txt('ACQ:DATA:UNITS VOLTS')
    rp_s.tx_txt(f'ACQ:DEC {dec}')
    rp_s.tx_txt('ACQ:SOUR1:GAIN HV')
    rp_s.tx_txt('ACQ:TRIG:LEV 0.5')
    rp_s.tx_txt('ACQ:TRIG CH1_NE')
    rp_s.tx_txt('ACQ:START')
    sleep(0.1)

    #Wait for the acquisition to finish
    while 1:
        rp_s.tx_txt('ACQ:TRIG:STAT?')
        if rp_s.rx_txt() == 'TD':
            break
    #Read the data from the acquisition
    rp_s.tx_txt('ACQ:SOUR1:DATA?')
    print('Reading data...')
    #rp_s.tx_txt('ACQ:SOUR1:DATA:STA:N? 0,1000')
    buff_string = rp_s.rx_txt()
    print('Done reading data!') 

    #Convert the data to a list of floats
    buff_string = buff_string.strip('{}\n\r').replace("  ", "").split(',')
    buff = list(map(float, buff_string))

    return buff

buff = sample_oscilloscope()

#Plot the data
plot.plot(buff)
plot.ylabel('Voltage')
plot.show()
Here is the captured waveform (it looks correct on the web oscilloscope):
Image

User avatar
redpitaya
Site Admin
Posts: 883
Joined: Wed Mar 26, 2014 7:04 pm

Re: Acquiring Noisy and Incorrect Data using SCPI and Python

Post by redpitaya » Mon Mar 20, 2023 12:25 pm

First of all, I would like to apologize for my late reply. We were representing Red Pitaya at Embedded World the previous week, so I didn't have time to read the support emails.

First, a few suggestions to make the code run faster:
- you have to set up the generator only once and then you can trigger it with the SOUR1:TRIG:INT command
- same with the ACQ, but you will need to run the following commands everytime you want to acquire data:

Code: Select all

rp_s.tx_txt('ACQ:TRIG:LEV 0.5')
rp_s.tx_txt('ACQ:START')	# try switching the ACQ, so that it matches this code
sleep(0.1)			# some delay due to higher decimation (it can be finetuned)
rp_s.tx_txt('ACQ:TRIG CH1_NE')
      
I have some additional questions:
- Which OS version are you using?
- What is the signal you are generating on the oscilloscope (or are you using the Red Pitaya's OUT1 as a generator)?
- Do you have 50 Ohm terminators near the inputs?

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 22 guests