# Question about sampling rate of xadc

**URL:** <https://discuss.pynq.io/t/question-about-sampling-rate-of-xadc/7920>\
**Category:** Support\
**Created:** [January 10, 2025, 11:12am UTC](https://discuss.pynq.io/t/question-about-sampling-rate-of-xadc/7920 "2025-01-10T11:12:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lil\_yeongji](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@lil\_yeongji](https://discuss.pynq.io/u/lil_yeongji)\
**Post date:** [January 10, 2025, 11:12am UTC](https://discuss.pynq.io/t/question-about-sampling-rate-of-xadc/7920/1 "2025-01-10T11:12:59Z")

</div>

Hello everyone

I have a question that I have while working on an example using xadc ip.

I am working on an example that converts an analog signal coming from an analog input pin into a digital signal using xadc ip. I set the xadc settings to DCLK frequency=100M, ADC Conversion Rate=200ksps as shown below, created a block diagram like the picture, and operated it with the attached code in the Python environment.

However, when I look at the actual results, the sampling rate seems to be operating at about 8ksps.

Isn’t the xadc sampling rate the ADC Conversion rate? I clearly set it to 200ksps, but it seems to be so different from the results I got, which is strange.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/9/97101234737ccfeb07c907db44e12d3e909fb8a2.png)

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/4/45d31b7de0788f4e9da1a3fc6f737d9f4166742c.png)

-----------Jupyter notebook code--------------------

from pynq import Overlay, MMIO  
import time  
import matplotlib.pyplot as plt

overlay = Overlay(‘0109.bit’)  
adc\_base\_address = overlay.ip\_dict[‘xadc\_wiz\_0’][‘phys\_addr’]  
adc\_addr\_range = overlay.ip\_dict[‘xadc\_wiz\_0’][‘addr\_range’]  
adc = MMIO(adc\_base\_address, adc\_addr\_range)

def read\_adc\_samples(channel\_offset, duration, sample\_rate=200000):  
“”"  
Sample ADC data for a specific duration and at a specific sample rate.  
Args:  
channel\_offset: Register offset for the ADC channel.  
duration: Sampling duration (in seconds).  
sample\_rate: Sampling rate (in Hz).  
Returns:  
List of sampled ADC voltage values.  
“”"  
samples =   
interval = 1 / sample\_rate  
start\_time = time.time()

```
while (time.time() - start_time) < duration:
    raw_value = adc.read(channel_offset) 
    voltage = (raw_value * Vref) / resolution  
    samples.append(voltage)
    time.sleep(interval)  

return samples

```

def calculate\_peak\_to\_peak(samples):  
“”"  
Calculate the Peak-to-Peak voltage from sampled data.  
Args:  
samples: List of sampled ADC voltage values.  
Returns:  
Peak-to-Peak voltage value.  
“”"  
max\_value = max(samples)  
min\_value = min(samples)  
return max\_value - min\_value

def monitor\_ac\_peak\_to\_peak(duration=0.01, sample\_rate=200000):  
“”"  
Monitor the AC signal and calculate its Peak-to-Peak voltage.  
Args:  
duration: Sampling duration (in seconds).  
sample\_rate: Sampling rate (in Hz).  
“”"  
try:  
while True:  
# Sample ADC data  
samples = read\_adc\_samples(vaux\_offset, duration, sample\_rate)

```
        # Calculate Peak-to-Peak voltage
        v_pp = calculate_peak_to_peak(samples)
        
        # Print Peak-to-Peak voltage
        print(f"Peak-to-Peak Voltage: {v_pp:.3f} V")
        
        # Plot the sampled data (optional)
        plt.plot(samples)
        plt.title("AC Signal Samples")
        plt.xlabel("Sample Index")
        plt.ylabel("Voltage (V)")
        plt.grid()
        plt.show()
        
        # Delay between calculations
        time.sleep(1)
except KeyboardInterrupt:
    print("\nMonitoring stopped by user")

```

# Run the monitoring function

monitor\_ac\_peak\_to\_peak(duration=0.01, sample\_rate=200000)

* * *

 ![image](https://us1.discourse-cdn.com/flex019/uploads/pynq1/original/2X/7/712b7a1bb322bf67bd6cdc7765d19ad44e3bcf45.png)

If you look at the result screen, you can see that the frequency of the analog input signal is 1kHz, but one cycle is measured for about 8 sample indices.  
 → The sampling rate is 8ksps?

---

<div class="post-metadata">

**Author:** ![matthew](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@matthew](https://discuss.pynq.io/u/matthew)\
**Post date:** [January 10, 2025, 6:16pm UTC](https://discuss.pynq.io/t/question-about-sampling-rate-of-xadc/7920/2 "2025-01-10T18:16:50Z")

</div>

Hi,  
What is the “result screen”? The xadc configuration, where it is indicated in “Analog sim file options” that the frequency is 1 kHz?

If you are using the xadc ip block, why are you not using the output ports, only the input ports at the left of the block?

---

<div class="post-metadata">

**Author:** ![lil\_yeongji](https://avatars.discourse-cdn.com/v4/letter/l/d6d6ee/32.png) [@lil\_yeongji](https://discuss.pynq.io/u/lil_yeongji)\
**Post date:** [January 12, 2025, 12:28pm UTC](https://discuss.pynq.io/t/question-about-sampling-rate-of-xadc/7920/3 "2025-01-12T12:28:19Z")

</div>

The result screen is obtained by drawing a graph about the input signal on the Jupyter notebook.

The input signal is a sine wave that I created randomly using a function generator.  
(offset=0.5v, amplitude=0.22v, freq.=1kHz)
