Pmod PWM

In this notebook, The Pmod PWM driver is exercised. Specifically, An AXI Timer is used to a generate pulse width modulated (PWM) signal.

To see the results of this notebook, you will need a Digilent Analog Discovery 2

</tr>

and WaveForms 2015

1. Instantiation

Import overlay and instantiate Pmod_PWM class.


In [1]:
from pynq import Overlay
Overlay("base.bit").download()

2. Connect Scope

In this example, we choose the Digilent Analog Discovery 2 as the scope.

  • The 1+ pin (of channel 1) has to be connected to pin 0 on PMODA interface.
  • The 1- pin (of channel 1) has to be connected to GND on PMODA interface.

This example uses PMODA interface. In order to use PMODB interface, users can replace PMODA to PMODB in the examples below. Similarly, users can change the pin number.


In [2]:
from pynq.iop import Pmod_PWM
from pynq.iop import PMODA

pwm = Pmod_PWM(PMODA, 0)

3. Generate a clock of $50\%$ duty cycle and $10\,\mu$s period

In this example, we generate a $10\,\mu$s clocks with $50\%$ duty cycle for 4 seconds and the stop. Issuing stop command stops both timer sub-modules.

Users have to choose channel 1 for waveform display in the scope.

The output would look like this:


In [3]:
import time

# Generate a 10 us clocks with 50% duty cycle
period=10
duty=50
pwm.generate(period,duty)

# Sleep for 4 seconds and stop the timer
time.sleep(4)
pwm.stop()

4. Generate a clock of $25\%$ duty cycle and $20\,\mu$s period

Repeating the above test for another set of parameters. The output would look like this:


In [4]:
import time

# Generate a 20 us clocks with 25% duty cycle
period=20
duty=25
pwm.generate(period,duty)

# Sleep for 5 seconds and stop the timer
time.sleep(5)
pwm.stop()