PMOD_timer pulse width issue

Hello,

PYNQ version: 2.5
Board: PYNQ-Z2

I am playing around with the PMOD_timer in my PYNQ-Z2. pynq VERSION IS 2.5.

First of all, I import the overlay to use the timers:

from pynq.overlays.base import BaseOverlay
base = BaseOverlay(“base.bit”)

Then I choose pin 0 of PMODA

from time import sleep
from pynq.lib import Pmod_Timer

pt = Pmod_Timer(base.PMODA,0)
pt.stop()

Then I want to create a square wave where I have 3.3V half of the time 0V the rest of time. Thus a clock signal. The example in the board says I have to choose a “period” variable such that the “desired period” (T) is T = 10*period

On a different note, the variable clk_period_ns is said to be the pulse width. So I choose period=20 which means T=10*period=200, and clk_period=100, which means I should have a clock signal with period 200 ns

period=20
pt.clk_period_ns = 100
print (pt.clk_period_ns)

I generate the pulse:

pt.generate_pulse(period)

But what I obtain is

Nothing like a clock signal. Also, there are no changes if I modify clk_period_ns

What could be the reason behind this?

1 Like

Hi,

Based on:

It is saying the pulse width is equal to the clock period (you can’t really change signals within a single IOP clock, so it is a reasonable assumption). And you can adjust how many clocks a pulse will appear, by changing the argument period. So if you want a clock signal output, you should change period=2, so

pt.generate_pulse(period=2)

will give you an output clock signal.

Btw,

shows that you should not change clk_period_ns since it is determined by the microblaze clock, therefore determined by fclk0.

So if you want to change the output clock frequency, try to adjust fclk0 using our Clocks class.

But I do think if you really want to generate an adjustable clock signal, you should use Pmod_PWM instead of Pmod_Timer.

3 Likes

Hi Rock,

Thank you very much for your answer.

Yes, you are 100% right on the fact I want to generate an adjustable clock signal. The problem I see with Pmod_PWM is the period is restricted between 1 and 65536 as specified in the line 97 of the following link:

That means the maximum I can generate is a 1 MHz clock signal, but I would like to get more than that if possible, especially seeing as the maximum frequency I can get playing with the Clocks class is 500 MHz.

As for PMOD_timer, which on paper would allow me to get bigger frequencies, the minimum period is 3, and I am not able to generate anything like a clock signal with it (I tried many options).

I wonder if there is an alternative solution for this I have been bypassing so far.

Thank you again.

Our source code for timer_pwm_generate is here:

So it can generate clock pulse in the units of number of microblaze clock cycles.
We are using it this way:

You can modify the microblaze code, or even try ipython microblaze to directly code microblaze code in jupyter, something like:

Just keep in mind that the IO pins coming out of the Pmod has a maximum clock frequency, which is around 10 - 15 MHz. Even if you are able to generate above 15MHz clock, you won’t be able to see it on the IO pins - those IO pins are not designed for extremely high clocks.

2 Likes

Hello Rock,

Thank you for your insightful comments.

I am wondering, is there any pin in the PYNQ that is able to handle more than those 10-15 MHz you speak about?

Let’s say I build a clock divider with Vivado parting from the 125 MHz referred in the constraints file. Would any pin around be able to support it? Which is the maximum supported anywhere?

Thank you again.

I am not aware of any pins that can do that. There might be future versions of PYNQ boards that can handle higher frequency, but for z1 and z2, the pins are quite normal and not high speed.

1 Like

Thank you Rock for all your help.

At the end I could find another solution modifying the Pmod_Timer Python code, so the period stored could lead to a clock signal.

For instance, one possible solution is to modify that line like this:

self.microblaze.write_mailbox(0, period-3)

If period = 3, I am able to see a clock signal in my oscilloscope.