"In this demonstration, an analog waveform is generated using the Digilent Analog Discovery 2, and the Waveforms software.:\n",
"In this demonstration, an analog waveform is generated using the Digilent Analog Discovery 2, and the Waveforms software.:\n",
"\n",
"\n",
"1. [Digilent Analog Discovery 2](http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/)\n",
"[Digilent Analog Discovery 2](http://store.digilentinc.com/analog-discovery-2-100msps-usb-oscilloscope-logic-analyzer-and-variable-power-supply/)\n",
For the waveform to be displayed, we collect multiple points in each period. However, according to the Nyquist theorem, the sample rate only has to be $2\times$ the frequency of the signal.
For the waveform to be displayed, we collect multiple points in each period. However, according to the Nyquist theorem, the sample rate only has to be $2\times$ the frequency of the signal.
The following block of code is just an example. For the Pmod ADC, the minimum delay between two samples is around $0.3\,$ms (corresponding to a sampling period of $3\,$kHz). So the maximum frequency of the input signal can be $1.5\,$kHz.
The following block of code is just an example. For the Pmod ADC, the minimum delay between two samples is around $0.3\,$ms (corresponding to a sampling period of $3\,$kHz). So the maximum frequency of the input signal can be $1.5\,$kHz.
For the interface ID used in the following example, if the Pmod ADC is connected to interface PMODA, type in `PMODA`; if the Pmod ADC is connected to interface PMODB, type in `PMODB`.
For the interface ID used in the following example, if the Pmod ADC is connected to interface PMODA, type in `PMODA`; if the Pmod ADC is connected to interface PMODB, type in `PMODB`.
For the WaveForms configuration, this example uses the following parameters:
For the WaveForms configuration, this example uses the following parameters:
| Wavegen Parameters | Configuration |
| Wavegen Parameters | Configuration |
| ---------------------- |
| ---------------------- |
| Type | Sine |
| Type | Sine |
| Amplitude | 1V |
| Amplitude | 1V |
| Offset | 1V |
| Offset | 1V |
| Symmetry | 50% |
| Symmetry | 50% |
| Phase | 0 |
| Phase | 0 |
Channel 0 (V1) on Pmod ADC is connected to port W1 on Digilent Analog Discovery 2.
Channel 0 (V1) on Pmod ADC is connected to port W1 on Digilent Analog Discovery 2.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` python
``` python
fromtimeimportsleep
fromtimeimportsleep
frompynq.overlays.baseimportBaseOverlay
frompynq.overlays.baseimportBaseOverlay
frompynq.libimportPmod_ADC
frompynq.libimportPmod_ADC
base=BaseOverlay("base.bit")
base=BaseOverlay("base.bit")
if_id=input("Type in the interface ID used (PMODA or PMODB): ")
if_id=input("Type in the interface ID used (PMODA or PMODB): ")
ifif_id.upper()=='PMODA':
ifif_id.upper()=='PMODA':
adc=Pmod_ADC(base.PMODA)
adc=Pmod_ADC(base.PMODA)
else:
else:
adc=Pmod_ADC(base.PMODB)
adc=Pmod_ADC(base.PMODB)
freq=int(input("Type in the frequency/Hz of the waveform: "))
freq=int(input("Type in the frequency/Hz of the waveform: "))
period=1/freq
period=1/freq
log_interval_us=0
log_interval_us=0
# Assume Channel 0 is connected to the waveform generator
# Assume Channel 0 is connected to the waveform generator
adc.start_log(1,0,0,log_interval_us)
adc.start_log(1,0,0,log_interval_us)
sleep(3*period)
sleep(3*period)
log=adc.get_log()
log=adc.get_log()
# Draw the figure
# Draw the figure
%matplotlibinline
%matplotlibinline
importmatplotlib.pyplotasplt
importmatplotlib.pyplotasplt
plt.plot(range(len(log)),log,'ro')
plt.plot(range(len(log)),log,'ro')
plt.title('PMOD ADC Waveform')
plt.title('PMOD ADC Waveform')
plt.axis([0,len(log),min(log),max(log)])
plt.axis([0,len(log),min(log),max(log)])
plt.show()
plt.show()
adc.reset()
adc.reset()
deladc,base
deladc,base
```
```
%% Output
%% Output
Type in the interface ID used (PMODA or PMODB): PMODB
Type in the interface ID used (PMODA or PMODB): PMODB