AXI GPIO connection with my 4 bit counter

I’m using PYNQ Z2 board for implementing 4 bit counter. For counter a verilog code implemented and added in my block design. Now I can’t read the counter values in jupyter notebook


I uploaded my block design. Is it right?
@ cathalmccabe

Hi @Vijay_Ilangovan,

Welcome to the PYNQ community.

How are you trying to read the counter with PYNQ?

I would also suggest to remove the gpio external connection.

Mario

I gave a python code below which I ran in jupyter notebook.
Using this can I can get the counter values, this is thought, will it work or not?
give your opinion for this.

from pynq import Overlay, MMIO
import time

Load the bitstream

overlay = Overlay(“design_1.bit”)

Correct base address from Vivado

base_address = 0x41200000 # Update to match Vivado address
address_range = 0x10000 # Set based on address range (64K in this case)

Create an MMIO object

mmio = MMIO(base_address, address_range)

Continuously read the counter value

try:
while True:
counter_value = mmio.read(0x0) & 0xF # Mask to get only the 4-bit value
print(f"Counter Value: {counter_value}")
time.sleep(1) # Wait for 1 second before the next read
except KeyboardInterrupt:
print(“Counter reading stopped.”)

thanks for reply @marioruiz

Yes, that should work. But, there’s no need for you to create the MMIO object. PYNQ already has a driver for the AXI GPIO IP.

You can do:

counter = overlay.axi_gpio_0.channel1
counter.setdirection('in')
counter.read()