Page 1 of 3

Read ADC-values

Posted: Tue Jun 21, 2022 1:12 pm
by Felix-Peter2000
Hello,
i have the following problem. I am using a function generator to input a sinus signal via channel IN1 and now i want to have the ADC values. How can i have the adc read out? I program this all in Python. I know this is not a specific question, but i am missing the approach. Can someone maybe give me some help? Thank you very much.

Greetings
Felix

Re: Read ADC-values

Posted: Tue Jun 21, 2022 2:56 pm
by M0JPI
Hi Felix,

I think there are number of different ways you could get the ADC values. My preferred Python method is to use Jupyter Notebooks and the Mercury FPGA Overlay.

The Red Pitaya Documents and examples show how to do this.

I have also made a short YouTube video showing how I used the IN1 ADC input in Python and Jupyter Notebooks.

An alternative to the Mercury FPGA Overlay is to use the SCPI server. There are examples of how to use the SCPI server with Python in the documents.

John M0JPI

Re: Read ADC-values

Posted: Wed Jun 22, 2022 10:00 am
by Felix-Peter2000
Hi John,
i also use the Mercury FPGA overlay. Have programmed the Red Pitaya as a fuction generator. I did this directly through Midnight Commander on the Red Pitaya. Am also considering programming the FPGA directly using VHDL.
Thank you very much for the help and the video. Will have a look an work it out.

Regards
Felix

Re: Read ADC-values

Posted: Fri Jun 24, 2022 3:34 pm
by redpitaya
Hello Felix,

Here is the link to the Python examples available on our webpage:
https://redpitaya.com/rtd-iframe/?ifram ... dProg.html

If you are looking for more examples with Jupyter, you can find them on our Github.

Re: Read ADC-values

Posted: Sun Aug 28, 2022 12:41 pm
by Felix-Peter2000
Ok, thank you. I will have a look.

Re: Read ADC-values

Posted: Wed Sep 28, 2022 1:49 pm
by Felix-Peter2000
M0JPI wrote:
Tue Jun 21, 2022 2:56 pm
Hi Felix,

I think there are number of different ways you could get the ADC values. My preferred Python method is to use Jupyter Notebooks and the Mercury FPGA Overlay.

The Red Pitaya Documents and examples show how to do this.

I have also made a short YouTube video showing how I used the IN1 ADC input in Python and Jupyter Notebooks.

An alternative to the Mercury FPGA Overlay is to use the SCPI server. There are examples of how to use the SCPI server with Python in the documents.

John M0JPI

Hello John,

I have a question. Why is 41667 used as decimation? How do you get this value?

Best regards
Felix

Re: Read ADC-values

Posted: Mon Oct 03, 2022 10:37 pm
by M0JPI
Hi Felix,

I can't remember. I think 41667 gives a sample rate of 3KHz. I think I chose that to take in down to the rate of my simple microphone and to keep file/memory size down.

Re: Read ADC-values

Posted: Fri Nov 04, 2022 11:12 am
by Felix-Peter2000
Hello dear members,

I am currently trying to implement an idea. My ADC works quite well so far, I get my ADC values. Here once my code.

Code: Select all

from redpitaya.overlay.mercury import mercury as overlay

import numpy as np 
import time

fpga = overlay()

# Enable Input
# Instance of the oscilloscope object is used for the input.
# Channel 1 is set with IN 2, with 1.0 volt. Low setting.
in2 = fpga.osc(1, 1.0)

# Data rate decimation  125 Msps / 12500 = 10 Ksps
in2.decimation = 10000  

# Trigger timing [sample periods]
N = in2.buffer_size
in2.trigger_pre  = 0
in2.trigger_post = N

# synchronization and trigger sources are the default,
# which is the module itself
in2.reset()
in2.start()
in2.trigger()

# wait for data
while (in2.status_run()): pass
data = in2.data(N)

Is it possible while a sampling take place to change the decimation. I want to have different decimation in different time ranges. my in2.status_run() only triggers the in2.decimation. So I have to tell the in2.status_run() to trigger e.g. the in2.decimation2.

I imagined it like this.

Code: Select all

from redpitaya.overlay.mercury import mercury as overlay

import numpy as np 
import time

fpga = overlay()

# Enable Input
# Instance of the oscilloscope object is used for the input.
# Channel 1 is set with IN 2, with 1.0 volt. Low setting.
in2 = fpga.osc(1, 1.0)

# Data rate decimation  125 Msps / 12500 = 10 Ksps
in2.decimation = [10000, 500, 300, 150, 50]  

# Trigger timing [sample periods]
N = in2.buffer_size
in2.trigger_pre  = 0
in2.trigger_post = N

# synchronization and trigger sources are the default,
# which is the module itself
in2.reset()
in2.start()
in2.trigger()

END_TIME = 35000
# wait for data
timestamp = time.perf_counter()
while (time.perf_counter() - timestamp < END_TIME):
    time.sleep(0.01)
    passed_time = ((time.perf_counter() - timestamp)*1000)

    if passed_time <= 6000:
        in2.status_run(0)

    elif passed_time <= 12000:
        in2.status_run(1)

    elif passed_time <= 18000:
        in2.status_run(2)

    elif passed_time <= 24000:
        in2.status_run(3)

    elif passed_time <= 30000:
        in2.status_run(4)

data = in2.data(N)

adc = open("adcValue.txt", "w")
for i in range(5000):
 print(data[i], end=";",file=adc)
adc.close()
But unfortunately i get the error message:
File "test.py", line 14, in <module>
in2.decimation = [10000, 500, 300, 150, 50]
File "/home/jupyter/RedPitaya/redpitaya/drv/osc_fil.py", line 45, in decimation
self.regset.fil.cfg_dec = value - 1
TypeError: unsupported operand type(s) for -: 'list' and 'int'
UIO __del__ was activated.

Re: Read ADC-values

Posted: Mon Nov 07, 2022 4:00 pm
by Felix-Peter2000
Have been able to solve my problem. Now I would like to know if it would be possible to read my ADC values from the ADC memory? With which command can I access the memory? I program in Python.

Best regards
Felix

Re: Read ADC-values

Posted: Tue Nov 08, 2022 9:23 am
by juretrn
Hi,
did you check the API? There's a function "acq_GetDataRaw" in rp-api/api/src/acq_handler.c
I'm not a software guy, so I don't know if this is useful to you in Python, given this function is in C.