Bitbanged DVI on the RP2040 Microcontroller
===========================================
![](img/mountains.jpg)
*640x480 RGB565 image, 640x480p 60 Hz DVI mode. 264 kB SRAM, 2x Cortex-M0+, system clock 252 MHz*
Quick links:
[Board Schematic](hardware/board/picodvi.pdf)
[Software Readme and Example Photos](software/)
About this Project
-----------------
This project stems from a stupid idea I had during RP2040 bringup. I couldn't convince myself the idea was too stupid to work, so I took a leap of faith on it, and the results are documented here.
RP2040 was designed to run at 133 MHz, but we found (without too much surprise) that typical silicon can be pushed further. In fact, there was overlap between the maximum system clock, and the TMDS bit clocks of slower DVI video modes. We had done great stuff with VGA on the FPGA platform, which ran at 48 MHz, but wouldn't it be absurd and wonderful to connect your microcontroller straight to an HD TV with no other electronics in between? This seemed unlikely to work out, but I stayed up at night playing around with assembly loops, and I could not convince myself that DVI was out of reach. Everything seemed to fit:
- With some of the core-local hardware on RP2040, and a neat encoding trick, I could do pixel-doubled TMDS encode on-the-fly using around 60% of an M0+ (running at 252 MHz, for 640x480p 60 Hz DVI)
- PIO can yeet out data streams at system clock frequency, and drive a 1/10th rate clock on the side, with pretty minimal programming
- Some of the DMA features are help with putting together the sync/blanking patterns on the fly, rather than having the patterns flat in memory
- With the second processor utterly unencumbered, you can render some pretty graphics to put on your DVI display. There is even enough RAM for a QVGA framebuffer!
The greatest unknown was driving 252 Mbps serial through the general-purpose digital pads (especially *differential* serial, emulated with two single-ended pads). By this point I was utterly driven and consumed by the need to find out if DVI could work, so I laid out a board over a few evenings after work.
![](img/bare_board.jpg)
The Rev A board uses a slightly cursed coupling circuit I first saw (and used) on the ULX3S FPGA board, which just connects 3V3 IOs straight into the HDMI socket through some coupling caps.
![](img/ac_coupling.png)
Those who understand the TMDS physical layer are probably screaming, but I was fine, because I did not read the electrical section of the spec until after I got this board working. Then I screamed. Before the boards arrived I did some debugging, with these two strategies:
- Run the entire system at 12 MHz (crystal freq), so that the signals are probeable, but the relative speed of IO, DMA and CPUs is the same. This makes sure my code can keep the PIO state machines fed with data
- Swap in an alternate PIO program which outputs 10 bit UART data frames instead of direct serial (a 17% drop in throughput). I could then dump the TMDS stream with a logic analyser, and examine and parse it on my machine
I also tried out my slightly harebrained TMDS encoding scheme, which matches the letter but not the spirit of the DVI specification, on an FPGA board with some DVI gateware I wrote for a previous weekend project. This confirmed that the principle was sound, and that my TV and monitor would have no trouble with the output of the matching software encoder on RP2040, provided the chip could physically shove bits out of the pins fast enough.
Because this is a home project, I didn't touch the HDL sim, and stuck to ARM debug, UART and logic analyser for my debugging. This worked some kinks out of the software, and bringup of the freshly-soldered board was smooth. After swapping the blue and red lanes into the right order -- to which I will say, in my defense, I _consistently_ thought the blue+sync lane was lane 2 -- I had a clean RGB565 QVGA 60 Hz static image on my monitor.
Improved Output Circuit
-----------------------
After reading the TMDS electrical section of the DVI spec, and staring quietly out the window for a while, wondering how this board *ever* worked, I rethought the output circuit. Eight capacitors was clearly not the way to go -- what I really needed was eight *resistors*. That's what I call a DVI PHY.
![](img/dc_coupling.png)
I also revised my earlier approach of "turn all the GPIOs up to 11", and reduced the pad drive and slew. At work on Monday, a colleague agreed it would be a great idea to plug my microcontroller monstrosity into the scope setup we use for 4k HDMI testing. Here are the results at VGA 60 Hz (252 Mbps):
![](img/eye_mask_vga60.png)
I was sitting on the other side of the lab while he was running the test, and when the eye mask appeared he just said "do you wanna see something funny".
![](img/table_vga60.png)
A clean bill of health! We also tried 720p30 (372 Mbps), which requires overvoltage on typical silicon (something you can do with one register write on RP2040):
![](img/eye_mask_720p30.png)
![](img/table_720p30.png)
Honestly, this has shaken me. This is a silly amount of bandwidth for a tiny little microcontroller.
Although it passes the eye mask and a few other tests, this circuit is not fully compliant with the DVI spec. In particular, our logic `1` is not quite right, due to the CMOS drive on the GPIOs: any more than a \~60 mV mismatch between the Source and Sink +3V3 rails will push our high-level offset outside of the +- 10 mV allowed by the spec. This is a real nitpick, because a *differential* receiver is unlikely to care about a 10 mV *commmon mode* offset, but still -- it is out of spec. A better circuit could use a fast Si diode and a smaller resistor value, e.g. 220 ohm, so that the emulated CML output floats on the sink's +3V3 supply when we output our 3V3 CMOS high level, but still sinks the requisite 10 mA when driving low.
That said, it's compliant enough that I can wander around the office and plug it into every monitor I see, and not even _one_ of them explodes (if my manager is reading this -- hi).
Going Further
-------------
Everything we have done is software defined -- there's no video hardware on this chip. That would of course be _silly_ on a microcontroller. Let's list all the hardware resources used to display a pixel-doubled image on screen:
- 3 out of 8 PIO state machines (the DVI code requires these all be on the same PIO instance, of which there are two, with four state machines each)
- 6 out of 12 DMA channels (two per TMDS lane: one for control blocks, one for data)
- 30% of DMA bandwidth and PIO bus endpoint bandwidth
- 60% of CPU cycles on one core, other core 100% free
- Just over 50% of RAM with a QVGA RGB565 image (but RGB332 support is simple enough)
- The PicoDVI board's only HDMI-shaped socket
Hmm. All of these numbers are less than half of the total, and everything else is software. It's a shame there's only one socket I can put an HDMI cable in. I mean, I guess I _do_ have these adorable PMOD-DVI adapters that I keep plugging into FPGA boards and getting away with it:
![](img/dvi-pmod.jpg)
Oh. Maybe? It fits...
![](img/two_connectors.jpg)
I guess the jig is up at this point, because of course I wouldn't post something so daft-looking if it didn't work:
![](img/two_displays.jpg)
[The code is here.](software/apps/dual_display/main.c)
Example Apps
------------
The [software readme](software/) has some example apps which put the DVI library through its paces, with pictures for some of the fun ones. I won't duplicate that content here.
Encoding TMDS
-------------
DVI uses an encoding scheme called TMDS during the video periods. 8 data bits are represented by a 10 bit TMDS symbol, which is serialised at 10x the pixel clock. 3 lanes transfer 24 bits of data per pixel clock, which for our purposes is one pixel. TMDS is DC-balanced, although DVI as a whole is *not* DC-balanced on all lanes, due to the control symbol encoding. The algor
没有合适的资源?快使用搜索试试~ 我知道了~
RP2040微控制器 上的 Bitbanged DVI_C语言_Assembly_python_代码_相关文件_下载
共333个文件
gbr:53个
h:47个
png:31个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 12 浏览量
2022-07-06
16:34:28
上传
评论
收藏 17.18MB ZIP 举报
温馨提示
关于这个项目 RP2040 设计为以 133 MHz 运行,但我们发现(没有太多惊喜)典型的硅可以更进一步。事实上,最大系统时钟与较慢 DVI 视频模式的 TMDS 位时钟之间存在重叠。我们在运行频率为 48 MHz 的 FPGA 平台上使用 VGA 做了很多出色的工作,但是将您的微控制器直接连接到高清电视而不连接其他电子设备不是很荒谬和美妙吗?这似乎不太可能解决,但我在晚上熬夜玩组装循环,我无法说服自己 DVI 是遥不可及的。一切似乎都合适: 借助 RP2040 上的一些核心本地硬件和巧妙的编码技巧,我可以使用大约 60% 的 M0+(运行在 252 MHz,用于 640x480p 60 Hz DVI)即时进行像素加倍 TMDS 编码 PIO 可以以系统时钟频率输出数据流,并在侧面驱动 1/10 速率时钟,只需极少的编程 某些 DMA 功能有助于动态组合同步/消隐模式,而不是将模式平放在内存中 在第二个处理器完全不受阻碍的情况下,您可以渲染一些漂亮的图形以放在您的 DVI 显示器上。 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
RP2040微控制器 上的 Bitbanged DVI_C语言_Assembly_python_代码_相关文件_下载
(333个子文件)
picodvi.bak 46KB
picodvi.bak 46KB
pmod_hyperram.bak 10KB
picodvi_pmod.bak 9KB
pmod_qspi_psram.bak 8KB
picodvi.bck 48B
picodvi.bck 48B
frame0599.bin 7KB
builduf2 618B
tmds_encode.c 13KB
dvi_timing.c 12KB
dvi.c 10KB
main.c 7KB
main.c 7KB
sprite.c 7KB
main.c 6KB
main.c 6KB
mandelbrot.c 6KB
main.c 5KB
main.c 5KB
main.c 5KB
main.c 4KB
main.c 4KB
main.c 4KB
main.c 4KB
main.c 3KB
main.c 3KB
main.c 2KB
dvi_serialiser.c 2KB
tile.c 2KB
main.c 2KB
main.c 2KB
dht.c 1KB
ckcompress 3KB
pico_sdk_import.cmake 3KB
picodvi.dcm 48B
picodvi-rescue.dcm 48B
picodvi.dcm 48B
picodvi-PTH.drl 3KB
picodvi-PTH.drl 3KB
picodvi.drl 3KB
picodvi.drl 3KB
picodvi_pmod.drl 823B
picodvi-NPTH.drl 377B
picodvi-NPTH.drl 377B
fp-info-cache 2.9MB
fp-info-cache 2B
fp-lib-table 114B
fp-lib-table 114B
fp-lib-table 114B
fp-lib-table 105B
fp-lib-table 105B
picodvi-F_Cu.gbr 375KB
picodvi-F_Cu.gbr 375KB
picodvi-F.Cu.gbr 366KB
picodvi-F.Cu.gbr 366KB
picodvi-B_Cu.gbr 224KB
picodvi-B_Cu.gbr 224KB
picodvi-In2_Cu.gbr 211KB
picodvi-In2_Cu.gbr 211KB
picodvi-F_Mask.gbr 178KB
picodvi-F_Mask.gbr 178KB
picodvi-F.Mask.gbr 173KB
picodvi-F.Mask.gbr 173KB
picodvi-In1_Cu.gbr 158KB
picodvi-In1_Cu.gbr 158KB
picodvi-B.Cu.gbr 151KB
picodvi-B.Cu.gbr 151KB
picodvi-In2.Cu.gbr 130KB
picodvi-In2.Cu.gbr 130KB
picodvi-F.Paste.gbr 126KB
picodvi-F.Paste.gbr 126KB
picodvi-F_Paste.gbr 105KB
picodvi-F_Paste.gbr 105KB
picodvi-In1.Cu.gbr 100KB
picodvi-In1.Cu.gbr 100KB
picodvi_pmod-F.Cu.gbr 80KB
picodvi-B_Mask.gbr 78KB
picodvi-B_Mask.gbr 78KB
picodvi-F.SilkS.gbr 64KB
picodvi-F.SilkS.gbr 64KB
picodvi-B.Mask.gbr 63KB
picodvi-B.Mask.gbr 63KB
picodvi-B_Paste.gbr 52KB
picodvi-B_Paste.gbr 52KB
picodvi-B_SilkS.gbr 52KB
picodvi-B_SilkS.gbr 52KB
picodvi-F_SilkS.gbr 49KB
picodvi-F_SilkS.gbr 49KB
picodvi_pmod-F.Mask.gbr 40KB
picodvi-B.Paste.gbr 37KB
picodvi-B.Paste.gbr 37KB
picodvi_pmod-F.Paste.gbr 33KB
picodvi_pmod-B.Cu.gbr 28KB
picodvi_pmod-B.Mask.gbr 23KB
picodvi_pmod-F.SilkS.gbr 16KB
picodvi-B.SilkS.gbr 10KB
picodvi-B.SilkS.gbr 10KB
picodvi-Edge.Cuts.gbr 1KB
picodvi-Edge.Cuts.gbr 1KB
共 333 条
- 1
- 2
- 3
- 4
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功