Running DAC-ADC Pmod Example "adc.read()" hangs with Pmod AD1

I am trying to run the example " DAC-ADC Pmod Examples …" that can be found at the link below on a PYNQ-Z1. https://github.com/Xilinx/PYNQ/blob/v2.5/boards/Pynq-Z1/base/notebooks/pmod/pmod_dac_adc.ipynb

However, instead of a PmodAD4 I have a Pmod AD1 (The PmodAD4 is out of stock).

I am able to run all of the setup code,

from pynq.overlays.base import BaseOverlay
from pynq.lib import Pmod_ADC, Pmod_DAC
ol = BaseOverlay("base.bit")
dac = Pmod_DAC(ol.PMODB)
adc = Pmod_ADC(ol.PMODA)

I am able to write to the DAC (I can see this on an oscilloscope so I know it’s working).
dac.write(0.35)

But when I come to read from the ADC, it hangs,
sample = adc.read()

I can leave it for several minutes but it will never complete, and just stays as [*]. I tried restarting the PYNQ-Z1, restarting the kernel, and writing some of my own code but it always hangs at the same line. If I interrupt the kernel I get the error below, but I am not sure how to read into this error or what causes it.


KeyboardInterrupt Traceback (most recent call last)
in ()
----> 1 sample = adc.read()

/opt/python3.6/lib/python3.6/site-packages/pynq/lib/pmod/pmod_adc.py in read(self, ch1, ch2, ch3)
202
203 # Send the command
→ 204 self.microblaze.write_blocking_command(cmd)
205
206 # Read the last sample from ADC

/opt/python3.6/lib/python3.6/site-packages/pynq/lib/pmod/pmod.py in write_blocking_command(self, command)
152 “”"
153 self.write(MAILBOX_OFFSET + MAILBOX_PY2IOP_CMD_OFFSET, command)
→ 154 while self.read(MAILBOX_OFFSET + MAILBOX_PY2IOP_CMD_OFFSET) != 0:
155 pass
156

/opt/python3.6/lib/python3.6/site-packages/pynq/lib/pynqmicroblaze/pynqmicroblaze.py in read(self, offset, length)
304 “”"
305 if length == 1:
→ 306 return self.mmio.read(offset)
307 elif length > 1:
308 return [self.mmio.read(offset + 4*i) for i in range(length)]

/opt/python3.6/lib/python3.6/site-packages/pynq/mmio.py in read(self, offset, length)
140
141 # Read data out
→ 142 return int(self.array[idx])
143
144 def write(self, offset, data):

KeyboardInterrupt:

I am very new to Pynq, and to Juptyer notebooks in general (I come from an Ancaoda/spyder background) so I fully admit I may be missing something simple. Looking at the docs for the library call, I don’t see anything about this library only being for PmodAD2, but maybe there is a compatibility issue
that I am running into?

https://pynq.readthedocs.io/en/v2.7.0/pynq_package/pynq.lib/pynq.lib.pmod.html?highlight=Pmod_DAC#module-pynq.lib.pmod.pmod_adc

I am not sure how to get my PYNQ version number, as if I they root@pynq:/home/xilinx# pynq --version into the Jupyter terminal I get bash: pynq: command not found. However, if I open the file REVISION I see “Release 2018_02_16 e5c8aeb” so I assume that is my version.

Hi @adowney2,

Welcome to our community.
What board are you using? I would suggest you get the latest SD Card image version (2.7) from here PYNQ - Python productivity for Zynq - Board.

It is also likely that the driver you are trying to use does not work for that PMOD. You can use the PYNQ Peripherals project to write the driver for that PMOD. GitHub - Xilinx/PYNQ_Peripherals

Mario

Thanks for the help,

  • I am using a PYNQ-Z1.
  • I just installed the image last week, but there is a chance I could have installed an old one. How could I check what version I have? I would love to be able to figure this out.
    • From a Jupyter terminal, if I log and type pynq --version' I get bash: pynq: command not found`
    • However, if I open the file REVISION in the pynq directory I see “Release 2018_02_16 e5c8aeb” so I assume that is my version.
  • On the driver issue, how would I know what Pmods that driver would work for? I am getting the feeling that the PMODS are hit and miss in terms of working out of the box and are a Diligent thing that I will have to work around.

Hi,

In a notebook you can do

import pynq
print(pynq.__version__)

Each notebook should state which PMOD works with it. Also, the driver for each PMOD is open source, so you can check if the code implements the functionality to talk to the PMOD.
Writing your own driver if this is what you need should be relatively easy with the PYNQ Peripherals project

Mario

Thanks, This is helpful, Let me work through these ones by one.

import pynq 
print(pynq.__version__)

returns


AttributeError Traceback (most recent call last)
in ()
1 import pynq
----> 2 print(pynq.version)

AttributeError: module ‘pynq’ has no attribute ‘version

form the source file it, it has the following, but no version.

author = “Yun Rock Qu”
copyright = “Copyright 2016, Xilinx”
email = “pynq_support@xilinx.com

all = [‘lib’, ‘tests’]

For the PMOD, thanks!
I looked in the source code and in the header, I see “Pmod_ADC(object)” is only for " The Pmod AD2 (PB 200-217) ". To me, I thought that this worked for all ADC Pmods. I will have to look for / create a driver for the AD1. Here is a link to the source code.
pynq.lib.pmod.pmod_adc — Python productivity for Zynq (Pynq) Thanks for your help on this.

Hi,

Well, based on this. It would appear that you have in the best case scenario the PYNQ 2.3 version or older. Which is really old.
Please get the SD Card image for the 2.7 version.

Mario

Thanks, you were correct. I installed an older version. That is updated now. With 2.7 print(pynq.__version__) returns 2.7.0

I think that closes out all the questions I had on this thread. Thanks for your help!

1 Like