RGB out through an FPGA to HDMI

for bbc micro/electron hardware, peripherals & programming issues (NOT emulators!)
Post Reply
User avatar
tricky
Posts: 3784
Joined: Tue Jun 21, 2011 8:25 am
Contact:

RGB out through an FPGA to HDMI

Post by tricky » Sat Nov 15, 2014 12:39 pm

I have no experience writing VHDL (although I have read quite a bit) and my knowledge of electronics is basic at best.
Do any of you VHDL/Verilog coders think it would be practical to make an RGB to HDMI interface for the beeb using something like a Spartan3 (kits from £20) or Spartan6 (kits from £40)?
I have written quite a bit of emulation and it seems that converting RGB+sync to something that an FPGA could accept wouldn't need much more than a few resistors and maybe a diode or two.
I was planning to use the center of the h-sync to align the next line so that games that play tricks with h-sync pos and width would work.
Using 576p (720x576@50hz - or even 576i) should allow all the movement of the displayed pixels that could be required and be OK on a Spartan3. 1080i/p could be used to fill the screen better, but would require a Spartan6 level FPGA and probably some fiddling to remove most of the v-sync fly-back.
I expect there would need to be two scan line buffers, one to display (once for 576i, twice for 576p) while the next is being read/parsed/converted or about a quarter of a screen for 1080i/p to buffer for the v-sync fly-back.
Really getting carried away, I was thinking that the h-sync pos/width could be adjusted (probably during the off-screen part) to communicate with the converter to, for example reprogram the palette. eg making red, pink so that on a normal display things would still look OK, but on this converter more options would be available.
Getting really really carried away, mode 1/5 could be used after "programming" the converter to take pairs of pixels and access a larger palette, giving 16 programmable colours, this would probably require different gfx, but could be (red then yellow)->(orange then orange) - well, I think that I have got carried away enough and should probably stop now.

User avatar
flynnjs
Posts: 826
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: RGB out through an FPGA to HDMI

Post by flynnjs » Sat Nov 15, 2014 2:41 pm

Yes, I'm toying with giving this a go. The main problem is that the Beeb pixels are not the same aspect ratio as PAL pixels. Beeb ones are wider. This is because PAL says it is 720 pixels wide but the Beeb only puts 640 pixels into the same width.
That's not a problem on an analogue system but poses issues for mapping to HDMI unless you don't mind a screen that looks too narrow.
I should looks at how the BeemEm code does it but if it's resampled and filtered then that would be an interesting FPGA problem :)

User avatar
1024MAK
Posts: 9294
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: RGB out through an FPGA to HDMI

Post by 1024MAK » Sat Nov 15, 2014 2:56 pm

You have a standard to match, here is a link to a post with further links ('cus I like Stargate SG-1) :mrgreen:

Mark

User avatar
tricky
Posts: 3784
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: RGB out through an FPGA to HDMI

Post by tricky » Sat Nov 15, 2014 3:10 pm

flynnjs,
I had considered the pixel aspect ratio, but at somewhere between .915 and .935 you would need 12 to 16 screen pixels to 1 BBC pixel to get it "correct", or did you mean that two clocks would be needed, 1 for BBC pixels in and 1 for HDMI pixels out?
1024mak,
I had a look at the HDMI spec and see no problems, the two FPGAs I mentioned both come with sample HDMI out.

User avatar
flynnjs
Posts: 826
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: RGB out through an FPGA to HDMI

Post by flynnjs » Sat Nov 15, 2014 8:43 pm

It's not pleasant. It doesn't even fill the full 4:3 area of a
PAL monitor.
A proper PAL signal has 64us line with 52us of it being
the displayed area.
The Beeb has 1024 clock periods at 16MHz matching the
required 64us but only outputs 640 visible pixels which
is only 40us. The additional 12us appears as black part
each side of the graphics area.

Similarly, on PAL, 288 lines per field carry video whereas
the Beeb only outputs on 256 of them, again leaving a
black part at top and bottom.

In summary PC pixels are 1:1
Beeb pixels are 12:13 (narrower than square)
PAL pixels are 12:11 (wider than square)

If you used a PAL signal and rotated it 90 degrees you wouldn't
be far off !!

The most sensible solution I can think of is doubling both X and Y
giving 1280x1024 and living with the distortion.
You could add a push button to map into the middle of a 1680x1050
or 1920x1080 by adding black borders around the outside.
I just don't see any clean way of resampling.

User avatar
tricky
Posts: 3784
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: RGB out through an FPGA to HDMI

Post by tricky » Sun Nov 16, 2014 9:27 am

I agree that resampling isn't an option. Over the years I have had many CRTs and they have had varying sizes of borders with one portable having clearly visible teletext lines and the bottom border not even reaching the edge of the screen. I suggested 576p as that looked all that the cheaper Spartan3 could manage and should be supported by the oldest HDMI in a household. I guess most would also support 1080i, I don't have the HDMI spec to hand, and can't remember the three resolutions that make up the "minimum spec"

User avatar
hoglet
Posts: 8600
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: RGB out through an FPGA to HDMI

Post by hoglet » Sun Nov 16, 2014 10:14 am

Tricky,

In my view, doing any sort of HDMI from a Spartan 3 or 3E is going to be very challenging. It was only at the Spartan 3A and Spartan 6 generations that native TDMS signalling was added to the IO capabilities.

You've probably already read this, but here's the App note for the 3A:
http://www.xilinx.com/support/documenta ... app460.pdf

Can I ask what sort of TV or Monitor you are planning to connect to?

Does it support any computer modes over HDMI?

Have you considered the same project, but for VGA output. There are quite a few VGA monitors that will work a 50Hz. The HP ones I use do.

Finally, the LG 22MN43D Tv that Mark recommended here:
http://www.stardot.org.uk/forums/viewto ... 150#p77537
does a great job of handling BBC RGB over a Scart input, and scaling it up to 1920x1080 internally. If it's still available...It was selling at £99 last year.

Dave

User avatar
flynnjs
Posts: 826
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: RGB out through an FPGA to HDMI

Post by flynnjs » Sun Nov 16, 2014 11:24 am

I know the subject line says HDMI but the reason I suggested
the other resolutions is that many people might want to use
DVI computer monitor and not all of them support the TV type
resolutions which are available on HDMI.

User avatar
tricky
Posts: 3784
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: RGB out through an FPGA to HDMI

Post by tricky » Sun Nov 16, 2014 2:39 pm

The tv that I was thinking of was an early one and only supports 576p, 1080i and 720p.
Personally I would prefer square pixels than any kind of resampling.
I have made up a bunch of scart leads for my beebs that I use on CRTs, but wanted a solution for the long term that properly supported the crt type tricks you can play with the 6845.

User avatar
1024MAK
Posts: 9294
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: RGB out through an FPGA to HDMI

Post by 1024MAK » Sun Nov 16, 2014 3:02 pm

Um, the 6845 only does the timing and the RAM addressing. When not attached to the Acorn designed video ULA / video processor, the 6845 can be used for many other screen timing variations... Indeed Wikipedia says it was used in some older PC graphics cards. See here :mrgreen:

Mark

User avatar
retroclinic
Posts: 3032
Joined: Thu Jul 03, 2008 1:22 pm
Location: East Riding of Yorkshire
Contact:

Re: RGB out through an FPGA to HDMI

Post by retroclinic » Sun Nov 16, 2014 3:31 pm

when I looked into this a few years ago, my solution was a plug in to replace the Video ULA. That would allow, not only a replacement of the chip, but then you have almost all the signals right on that socket. The only ones missing are H and V sync, but you can regenerate them from the blanking signal, so there would be no extra flying leads.

That would give an internal solution for the Model B, however, the B+ and Master would need professional (or someone with a soldering iron and a court injunction against them for using a paint stripper) to remove the soldered in ULA and replace it with a socket.

Mark.
Image

User avatar
1024MAK
Posts: 9294
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...
Contact:

Re: RGB out through an FPGA to HDMI

Post by 1024MAK » Sun Nov 16, 2014 3:36 pm

Using a electric paint stripper is surprisingly effective :mrgreen:

Just have to be careful with parts that are made from soft plastic like E## keyboards :lol:

Mark

User avatar
flynnjs
Posts: 826
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: RGB out through an FPGA to HDMI

Post by flynnjs » Sun Nov 16, 2014 5:15 pm

If you're contempating a Spartan 6 size FPGA then
there is one other way that could make sense.
There's enough dual port Block RAM to build an
entire Shadow RAM unit and it could have it's own
CRTC and be clocked at a rate other than the standard
16MHz. With 60kB of block RAM you could have extra
shadow pages allowing mode 0 to have 8 colours and
even more in other modes whilst retaining backwards
compatibility.

User avatar
tricky
Posts: 3784
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: RGB out through an FPGA to HDMI

Post by tricky » Thu Oct 29, 2015 2:10 pm

Hi, I just saw the new scarab miniSpartan3 with HDMI out and it rekindled my interest in this subject.
Does anyone know of any progress in this area?

User avatar
george.h
Posts: 1030
Joined: Wed Apr 13, 2011 5:32 pm
Location: Chelmsford Essex
Contact:

Re: RGB out through an FPGA to HDMI

Post by george.h » Thu Oct 29, 2015 2:35 pm

Just to add to the "confusion", because CRT TVs (and early monitors) "overscanned" (TVs always did so the visible picture filled the screen, horizontally and vertically, otherwise the punters - sorry "customers" - complained), several of the lines at the top were commandeered for transmitting teletext data. The lines chosen would normally be "off screen" on a properly adjusted CRT TV.

I wouldn't be surprised if this was taken into account when the CRTC timings for the various modes were worked out.

:wink:
Pic Caption: "One day son, this will all be yours..."

User avatar
danielj
Posts: 7564
Joined: Thu Oct 02, 2008 4:51 pm
Location: Manchester
Contact:

Re: RGB out through an FPGA to HDMI

Post by danielj » Thu Oct 29, 2015 9:41 pm

John K was posting on the beeb mailing list about having had some success in this arena earlier in the year?

d.

User avatar
davidb
Posts: 2520
Joined: Sun Nov 11, 2007 10:11 pm
Contact:

Re: RGB out through an FPGA to HDMI

Post by davidb » Thu Oct 29, 2015 10:12 pm

CJE appear to be selling something that does RGB to HDMI (see about 3 minutes into Chris's RISC OS show theatre presentation).

User avatar
tricky
Posts: 3784
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: RGB out through an FPGA to HDMI

Post by tricky » Thu Oct 29, 2015 11:43 pm

I had forgotten about John K,I will have to dig through my old emails.
The cje one looks like a normal converter, so probably won't support the h-sync pulse width trick.

User avatar
hoglet
Posts: 8600
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: RGB out through an FPGA to HDMI

Post by hoglet » Fri Nov 06, 2015 9:10 am

danielj wrote:John K was posting on the beeb mailing list about having had some success in this arena earlier in the year?
For reference, here are John K's posts:
http://mdfs.net/Archive/BBCMicro/2015/07/22/222758.htm

User avatar
hoglet
Posts: 8600
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: RGB out through an FPGA to HDMI

Post by hoglet » Fri Nov 06, 2015 9:14 am

I'm going to have a play at adding a VGA scan doubler to BeebFPGA today.

I'll try both of there:
https://github.com/mist-devel/mist-boar ... ndoubler.v
https://github.com/makestuff/rgb2vga/bl ... level.vhdl

I'm expecting the VGA monitor will recognize the signal as 800x600 @ 50Hz.

The main difference is they run at difference VGA pixel clock rates (31.875MHz vs 25.000MHz).

Dave
Last edited by hoglet on Fri Nov 06, 2015 2:47 pm, edited 1 time in total.

User avatar
hoglet
Posts: 8600
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: RGB out through an FPGA to HDMI

Post by hoglet » Fri Nov 06, 2015 9:40 am

For HDMI, there is a clear output standard:
- 720x576p @ 50Hz with a pixel clock of 27MHz.
- the total geometry is 864x625
- the visible geometry is 720x576

For VGA, it's much less clear, assuming your monitor will sync to 50Hz (most won't):

This is the "official" SVGA geometry, with the 40.000MHz pixel clock scaled by (50.000/60.316)
- 800x600 @ 50Hz with a pixel clock of 33.1584MHz
- the total geometry is 1056x628
- the visible geometry is 800x600
This is what ElectronFPGA outputs in VGA mode, but for a scan doubler it would require buffering more than just two lines I think.

Reducing the number of vertical lines to 625 to match PAL:
- 800x600 @ 50Hz with a pixel clock of 33.000MHz
- the total geometry is 1056x625
- the visible geometry is 800x600

The rgb2vga scan doubler (above) I think outputs:
- ???x600 @ 50Hz with a pixel clock of 25.000MHz
- the total geometry is 800x625
- the visible geometry is ???x600
This is a strange set of timings; it will probably get detected as SVGA due to the number of lines.

The Mist scan doubler (above) I think outputs:
- 800x600 @ 50Hz with a pixel clock of 31.875MHz
- the total geometry is 1020x625
- the visible geometry is 800x600

Dave

User avatar
hoglet
Posts: 8600
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: RGB out through an FPGA to HDMI

Post by hoglet » Fri Nov 06, 2015 3:10 pm

Brief update, in case anyone has any suggestions or thoughts about how LCD monitors detect the format of VGA signals.

I've tried both scan doublers, and they both kind-of work.

Unfortunately, it turns out my favourite LCD monitor (the HP LP2065 that recognises 50Hz VGA signals) detects the signal as 1170x584

As far as I can tell from google this is:
- 1170x584 @ 50Hz with a pixel clock of 46.2MHz
- the total geometry is 1480x624
- the visible geometry is 1170x584

The problem is it's not easy to map the Beeb's 640x512 into this resolution, without getting scaling artefacts / moire effects creeping in.

I suspect I'm a bit stuffed here, because the monitor is probably using the number of scanlines per frame in it's signal detection, and that's the one parameter you can't change with a two-line memory scan doubler.

On a different LCD TV/monitor (a LG 22MN43) , this gets detected as 720x576@50Hz, which I suspect is because it's a more modern monitor that also has HDMI inputs.

On a different note, I was toying with the idea of trying DVI/HDMI, but unfortunately this is not possible on the Papilo Duo :(

Dave

User avatar
hoglet
Posts: 8600
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: RGB out through an FPGA to HDMI

Post by hoglet » Fri Nov 06, 2015 5:29 pm

For reference, here is a different RGB2VGA scan doubler:
https://sites.google.com/site/tandycocoloco/rgb2vga

It converts RGBs at 60Hz to 640x480 VGA at 60Hz. It support 3-bit RGB and has a full frame buffer implemented in SDRAM. It's implemented using a DE0 Nano plus a custom wing. There are lots of videos on youtube:
https://www.youtube.com/user/retrocanada76/videos

Dave

User avatar
flynnjs
Posts: 826
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: RGB out through an FPGA to HDMI

Post by flynnjs » Sat Nov 07, 2015 12:10 am

> in case anyone has any suggestions or thoughts about how LCD monitors detect the format of VGA signals.

A combination of the sync freq and the sync polarities.

> The problem is it's not easy to map the Beeb's 640x512 into this resolution, without getting scaling artefacts / moire effects creeping in.

Yep, see my posting from 15th Nov last year. Because of the very small ratio difference between 1:1 pixels on an LCD
and Beeb pixels you need an insanely high resolution monitor (i.e. one that doesn't exist) to be able to "upsample"
in both directions to use multiple LCD pixels as a single correct aspect Beeb pixel. If the pixels had been very non-square
like 4:3 or 3:2 the problem would have been much easier.
I still think doubling to 1280x1024 is the cleanest route and very widely compatible with VGA, DVI, HDMI etc.

User avatar
hoglet
Posts: 8600
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: RGB out through an FPGA to HDMI

Post by hoglet » Sat Nov 07, 2015 8:48 am

flynnjs wrote:> in case anyone has any suggestions or thoughts about how LCD monitors detect the format of VGA signals.

A combination of the sync freq and the sync polarities.
I'll try changing the sync polarity an see if that changes anything.
flynnjs wrote: > The problem is it's not easy to map the Beeb's 640x512 into this resolution, without getting scaling artefacts / moire effects creeping in.

Yep, see my posting from 15th Nov last year. Because of the very small ratio difference between 1:1 pixels on an LCD
and Beeb pixels you need an insanely high resolution monitor (i.e. one that doesn't exist) to be able to "upsample"
in both directions to use multiple LCD pixels as a single correct aspect Beeb pixel. If the pixels had been very non-square
like 4:3 or 3:2 the problem would have been much easier.
I still think doubling to 1280x1024 is the cleanest route and very widely compatible with VGA, DVI, HDMI etc.
My understanding was to sample square pixels from an analog PAL signal the sampling clock has to be 14.75MHz. The beeb pixel clock is 16MHz, so yes the Beeb pixel aspect ratio is "nominally" 14.75/16 which is very close to 12/13.

That said, on an analog monitor I tended to adjust the horizontal width so that circles would be round.

On a modern full-HD (1920x1080) monitor I'm getting good results from a VGA signal with a 27MHz pixel clock and the 576p timings posted above. There are no visible moire effects with alternating black/white vertical lines in Mode 0. I'll post a picture later. I'll check what the aspect ratio has ended up as in practice.

Dave

Edit: Another thought - do Beeb emulators show pixels at a 12/13 aspect ratio? I suspect not, and I bet no-one has noticed.

User avatar
flynnjs
Posts: 826
Joined: Tue Jul 06, 2010 9:33 pm
Contact:

Re: RGB out through an FPGA to HDMI

Post by flynnjs » Sat Nov 07, 2015 12:06 pm

> Edit: Another thought - do Beeb emulators show pixels at a 12/13 aspect ratio? I suspect not, and I bet no-one has noticed

Just fired up BeebEm to see how noticeable using square pixels is as you can choose a
variety of resolutions.
Mode0-6 looked just fine. I would be happy to live with the 12:13 / 1:1 mismatch.

Mode7 looks more awkward natively on an LCD.

User avatar
hoglet
Posts: 8600
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: RGB out through an FPGA to HDMI

Post by hoglet » Sat Nov 07, 2015 12:50 pm

hoglet wrote:On a modern full-HD (1920x1080) monitor I'm getting good results from a VGA signal with a 27MHz pixel clock and the 576p timings posted above. There are no visible moire effects with alternating black/white vertical lines in Mode 0. I'll post a picture later. I'll check what the aspect ratio has ended up as in practice.
Here's another data point.

With my 576p VGA signal the active part of the Beeb display ends up at 31.8cm x 23.9cm, which is an aspect ratio of 1.33:1 (4:3), where as it would be 1.25:1 (5:4) if the PAL pixels were square.

This stretching is down PAL pixels being 12/11 (or I guess more correctly 59/54 == 14.875/13.5)
i.e. 1.25 * 59/54 = 1.366.

The monitor is correctly sampling each pixel in the right place, as there are no obvious moire patterns, but it's making a bit of a mess when it then scales this to the full 1920x1080 resolution. This is Mode 0:
IMG_0134.JPG
That said, from a normal distance it looks quite good.

Also, increasing the "sharpness" control seems to help

Mode 7 looks awful though, which is I think expected.

Dave

User avatar
fordp
Posts: 1033
Joined: Sun Feb 12, 2012 9:08 pm
Location: Kent, England
Contact:

Re: RGB out through an FPGA to HDMI

Post by fordp » Mon Nov 09, 2015 11:51 am

Great work.

If HDMI is ever fixed what do you think about Acorn projects running on a board like this:
http://www.myirtech.com/list.asp?id=502

I would love to see a BEEB FPGA with a real Cortex A9 as a Second processor ;)

Cheers.

FordP
FordP (Simon Ellwood)
Time is an illusion. Lunchtime, doubly so!

Post Reply