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.
-----------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)
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?