In this notebook, PMOD Timer functionalities are illustrated. The Timer has two sub-modules: Timer0 and Timer1.
The Generate output and Capture Input of Timer 0 are assumed to be connected to PMODA pin1.
1. The Generate function outputs one clock (10 ns) pulse after a desired period.
2. The Capture input is sensitive to a rising edge or high level logic.
To see the results of this notebook, you will need a Digilent Analog Discovery 2
and WaveForms 2015
In [1]:
from pynq import Overlay
Overlay("base.bit").download()
Instantiate Pmod_Timer class. The method stop()
will stop both timer sub-modules.
In this example, we will use pin 0 of the PMODA interface. PMODB and other pins can also be used.
In [2]:
from time import sleep
from pynq.iop import Pmod_Timer
from pynq.iop import PMODA
pt = Pmod_Timer(PMODA,0)
pt.stop()
In this example, we choose the Digilent Analog Discovery 2 as the scope.
1+
pin (of channel 1) has to be connected to pin 0 on PMODA interface. Use the following settings for waveform.
Generate a 10 ns clock pulse every 1 microseconds for 4 seconds and then stop the generation.
Note that pulses are generated every $count\times10$ ns. Here count is defined as period.
You should see output like this:
In [3]:
# Generate a 10 ns pulse every period*10 ns
period=100
pt.generate_pulse(period)
# Sleep for 4 seconds and stop the timer
sleep(4)
pt.stop()
Note first parameter is the period interval.
Denoting the desired period as $T$ (in ns), we need to set the first parameter period
to:
$period = \frac{T}{10} $
The second parameter is the number of pulses to be generated.
Run the following cell and you should see output in the scope like this:
In [4]:
# Generate 3 pulses at every 1 us
count=3
period=100
pt.generate_pulse(period, count)
Now generate the pulses at every 1 $\mu$s interval.
In [5]:
# Generate pulses per 1 us forever
count=0
period=100
pt.generate_pulse(period, count)
Stop the generation.
In [6]:
pt.stop()
An event is either a rising edge or a high logic level. The parameter is duration, $period\times10$ ns, in which the event is to be detected. It returns 0 if no event occurred, otherwise it returns 1.
Use a waveform generator in this example. Connect W1 channel of the Analog Discovery to Pin 1 of PMODA.
Do not run the waveform generation in the next cell.
In [7]:
# Detect any event within 10 us
period=1000
pt.event_detected(period)
Out[7]:
Now run the waveform generation and then run the next cell. Set the waveform generator settings as shown below:
In [8]:
# Detect any event within 20 ms
period=200000
pt.event_detected(period)
Out[8]:
An event is either a rising edge or a high logic level. The parameter is duration, $period\times10$ ns, in which the number of event are counted. In this example we are interested in number of events occurring in 10 $\mu$s.
Use a waveform generator in this example. Use the following settings of the waveform generator and run the generator. Then run the next example.
In [9]:
# Count number of events within 10 us
period=1000
pt.event_count(period)
Out[9]:
An event is either a rising edge or a high logic level. It expects at least two rising edges. The return result is in units of nanoseconds.
Use a waveform generator in this example. Use the following settings of the waveform generator and run the generation. Then run the next example.
In [10]:
period = pt.get_period_ns()
print("The measured waveform frequency: {} Hz".format(1e9/period))