Skip to content

Instantly share code, notes, and snippets.

@PeterOgden
Created March 31, 2020 09:54
Show Gist options
  • Save PeterOgden/efc9d95f244bfbc8f5846477e6e9bd9c to your computer and use it in GitHub Desktop.
Save PeterOgden/efc9d95f244bfbc8f5846477e6e9bd9c to your computer and use it in GitHub Desktop.
Testing of 120 FPS capability of the ZCU104
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Test of 120 FPS Capability\n",
"\n",
"This notebook tests the HDMI of the ZCU104 in loopback configuration at 120 FPS for 1080p resolution\n",
"\n",
"First we need to instantiate the overlay and retrieve the instances of the the HDMI in and out"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
"require(['notebook/js/codecell'], function(codecell) {\n",
" codecell.CodeCell.options_default.highlight_modes[\n",
" 'magic_text/x-csrc'] = {'reg':[/^%%microblaze/]};\n",
" Jupyter.notebook.events.one('kernel_ready.Kernel', function(){\n",
" Jupyter.notebook.get_cells().map(function(cell){\n",
" if (cell.cell_type == 'code'){ cell.auto_highlight(); } }) ;\n",
" });\n",
"});\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from pynq.overlays.base import BaseOverlay\n",
"\n",
"base = BaseOverlay('base.bit')\n",
"hdmi_out = base.video.hdmi_out\n",
"hdmi_in = base.video.hdmi_in"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we create the video mode specifying 120 FPS as the final argument"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from pynq.lib.video import *\n",
"mode = VideoMode(1920, 1080, 24, 120)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we set the input HPD so that the output thinks there is a monitor attached"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"hdmi_in.frontend.set_hpd(1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then we can configure and start the output"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Frequency: 297000000\n"
]
},
{
"data": {
"text/plain": [
"<contextlib._GeneratorContextManager at 0x7f85a6ab38>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hdmi_out.configure(mode)\n",
"hdmi_out.start()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Followed by the input"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<contextlib._GeneratorContextManager at 0x7f77f4c2e8>"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hdmi_in.configure()\n",
"hdmi_in.start()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can check the FPS of the input by examining the `mode` of the input"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"120"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"hdmi_in.mode.fps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To test the integrity of the link we can write a frame of random data out and see if the same frame is read back in. We wait for a while to ensure that the frame we've written has cleared the input and output framebuffers"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"import time\n",
"outframe = hdmi_out.newframe()\n",
"outframe[:] = np.random.randint(255, size=(1080,1920,3), dtype='u1')\n",
"hdmi_out.writeframe(outframe)\n",
"\n",
"time.sleep(0.3)\n",
"\n",
"inframe = hdmi_in.readframe()\n",
"\n",
"np.array_equal(inframe, outframe)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can use the `%%timeit` magic to see how long reading and writing takes. At 120 FPS we expect a frame time of 8.33 ms"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100 loops, best of 3: 8.33 ms per loop\n"
]
}
],
"source": [
"%%timeit\n",
"f = hdmi_in.readframe()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"100 loops, best of 3: 8.33 ms per loop\n"
]
}
],
"source": [
"%%timeit\n",
"f = hdmi_out.newframe()\n",
"hdmi_out.writeframe(f)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This confirms that we're getting the full 120 FPS. Final thing is to stop the DMA engines"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"hdmi_in.stop()\n",
"hdmi_out.stop()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment