RGB to HDMI using a Pi Zero and a small CPLD

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by tricky » Sun Jan 28, 2018 7:53 am

This was how I wanted to build a palette extender for the beeb, but as I don't do CPLDs yet, I doubt it would have been any good.
I'm sure I posted it somewhere around here, when I was asking if the h-sync pulse was still sent during vblank, so that I could use it for one way communications to set the palette, border colour and other effects like horizontal scrolling or sprites by maybe using extra hidden lines for high bandwidth data.

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by hoglet » Sun Jan 28, 2018 9:09 am

tricky wrote:Hoglet, I'm sorry, I'd like to add a proviso to my answer.
If counting at half rate means changing the sampling positions, it isn't right, but may be near enough.
I also realised last night that this would likely mess up the carefully calibrated pixel sampling, as there would be no guarantee that half the sync width would be a multiple of six 96MHz cycles.

It might be possible to implement this on the Pi side in software, as the sync signal is passed directly through the CPLD to the Pi. The ARM assembler code could easily measure the sync width. Unfortunately, the system is currently using a 4 bits/pixel 672x540 framebuffer and is writing 8 pixels at a time with a single 32-bit write. Shifting things by just one pixel is actually not straightforward, but at least ARM does have a barrel shifter.

Edit:

Another (better) way might be to make use of the "Set Virtual Offset" command, which we are already using to implement the double buffering:
https://github.com/hoglet67/RGBtoHDMI/b ... dmi.c#L680

This allows for an X offset in pixels.

Is it sufficient to set the position once per field?

Dave
Last edited by hoglet on Sun Jan 28, 2018 2:21 pm, edited 2 times in total.

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by hoglet » Sun Jan 28, 2018 1:30 pm

leenew wrote: This game scrolls in all directions: http://www.bbcmicro.co.uk/game.php?id=1310 (Press escape to pass the annoying instructions).
Thanks for this Lee. I've just tried it and the combing (and occasional tearing) is unfortunately quite visible when scrolling horizontally, which is a shame.

I've also just tried with the TV's SCART input and the picture is noticeably softer / more blurred (compared with HDMI). There is no combing, but it does seem like some of the definition is lost when scrolling horizontally.

So, it seems like it would be worth trying alternative strategies of de-interlacing for MODE 7.

Dave

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by hoglet » Sun Jan 28, 2018 2:07 pm

IanB wrote: Bob does reduce the effective vertical resolution a bit but not by half and it does introduce interlace twitter (like a real CRT).
I've just tried a quick test and enabled the line doubling (and double buffering) for Mode 7.

As you say, it does introduce the twitter that you get on a real CRT (which I find quite distracting), but the combing and tearing are now gone.

So it seems like there is a place for both modes of operation.
IanB wrote: Proper bob deinterlacing is done by interpolating the lines in between the missing ones for each field when converting to a frame, not just line doubling as follows:

frame1 frame2
1.........1i
2i........2
3.........3i
4i........4
5.........5i
6i........6
7.........7i

The 'i' lines above are interpolated and the non 'i' lines are the original lines from each field.
Interpolation can be as simple as an average of the line above and below but better quality can be achieved by using weighted values from four lines or even more. (This means that RGB intensities will not just be on or off so you would need to have multiple bits per pixel for intermediate intensities)

This results in most of the resolution of the video being retained but it introduces interlace twitter on horizontal edges as the interpolated values don't 100% match the real values in the next de-interlaced frame.

An even better solution would be motion adaptive de-interlacing which switches between bob and weave in parts of the frame depending on their motion. i.e. moving areas are bobbed and stationary areas are weaved. Normally this is quite complex as determining the extent of a moving area is quite difficult but in the case of mode 7, the characters can only be in a cell and so it might be possible to switch between bob and weave on a per character cell basis depending on whether that cell had changed in the last frame (It might be possible to use simple line doubling bob under those circumstances as well)
I doubt there is the memory bandwidth to do anything more complicated than line doubling in software as data is written in to the frame buffer.

I can think of a couple of possible paths forward:

- In Mode 7 have the Pi output 576i@50 and allow the TV/monitor to do the de-interlacing / scaling. I'm not sure if this is a commonly supported mode on HDMI monitors (it's probably there on most TVs though). But I'm wondering whether this would be any better than using SCART.

- Make use of the GPU to do the de-interlacing. This is certainly possible from an OS (many Raspberry Pi video players use the GPU in this way, I believe through OMX). I've very little experience of this, and I'm not sure it's possible from a bare-metal application.

Dave

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by tricky » Sun Jan 28, 2018 4:38 pm

hoglet wrote: Is it sufficient to set the position once per field?

Dave
One per frame would be enough as half the frames would require one mid frame and one off screen.
It would probably be better to do what you were thinking in the first place and just ignore mode 7.

IanB
Posts: 179
Joined: Sun Sep 04, 2011 7:28 pm
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by IanB » Sun Jan 28, 2018 7:02 pm

hoglet wrote: I've just tried a quick test and enabled the line doubling (and double buffering) for Mode 7.
As you say, it does introduce the twitter that you get on a real CRT (which I find quite distracting), but the combing and tearing are now gone.
I doubt there is the memory bandwidth to do anything more complicated than line doubling in software as data is written in to the frame buffer.
Interpolation helps to reduce the twitter. You currently output mode 7 to 504x540 with line doubling, how about reducing that to 504x270 and allow the GPU to scale that up giving some interpolation. You would need to be able to introduce the appropriate amount of vertical shift (half a line @270) between the odd and even fields to get things to line up and it might not work very well if you can't do that.
hoglet wrote: I can think of a couple of possible paths forward:
- In Mode 7 have the Pi output 576i@50 and allow the TV/monitor to do the de-interlacing / scaling. I'm not sure if this is a commonly supported mode on HDMI monitors (it's probably there on most TVs though). But I'm wondering whether this would be any better than using SCART.
Yes that certainly is an option. As you say, it would likely work on modern TVs and you would get the best results as most of them do high quality motion adaptive or better de-interlacing but it might not work at all on most HDMI monitors.

atcurtis
Posts: 45
Joined: Fri Apr 08, 2016 9:47 am
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by atcurtis » Mon Jan 29, 2018 6:20 am

Lardo Boffin wrote:Just noticed this one - it looks awesome! There is something similar for the speccy:-

https://www.sellmyretro.com/offer/detai ... trum-27558

I have a SpectraScart so don’t have one of these to know how well it works but there are some review links on the website.
I have one of those and it works really well. It's not quite the same thing because it is only looking at the ZX Spectrum IO bus to generate the image in the Raspberry Pi without sampling the output of the video circuits. An equivalent would be to have something in place of the VIDPROC but also feed it the HSYNC/VSYNC data.

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by fordp » Mon Jan 29, 2018 9:47 am

It would be great to try this on my Beeb FPGA DE1, without the need for a CPLD ;)
FordP (Simon Ellwood)
Time is an illusion. Lunchtime, doubly so!

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by tricky » Mon Feb 19, 2018 12:36 pm

tricky wrote:
hoglet wrote: Is it sufficient to set the position once per field?

Dave
One per frame would be enough as half the frames would require one mid frame and one off screen.
It would probably be better to do what you were thinking in the first place and just ignore mode 7.
If you mean once for the whole frame, no as it needs to change part way, between the play area and the control panel.

I don't mean to tread on Rob's toes, but a small hack to most games to change them from say mode 2 to mode 0 (or 1) would allow the PI to get the flashing bit and allow the same sort of 16 colour enhanced palettes although, amusing that the PI can handle the palette in the mode you are using, it would probably require four one byte look-ups to do the conversion so may not fit in timing. The colours would also need to be communicated, possibly using the h-sync pulse for one-way serial communication.

Is it possible to buy the CPLD board, or if not, are the designs available?

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by hoglet » Mon Feb 19, 2018 2:55 pm

tricky wrote: Is it possible to buy the CPLD board, or if not, are the designs available?
The CPLD board I'm currently using with all the wires (picture in the first post) is this one:
https://www.seeedstudio.com/s/XC9572XL- ... p-799.html

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by tricky » Mon Feb 19, 2018 5:21 pm

Thanks, I ordered a nearly identical board with a 5v to 3.3v converter onboard (I'll report when it arrives from China).
I really want to try some CPLD/FPGA programming and this looks like a good place to start.
Now, if I could find another 20 or so hours per day, I might get to try all the things I want to!

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Sun Apr 22, 2018 9:08 pm

myelin wrote:Just chiming in to confirm that I am indeed planning on helping out with the PCB (although I haven't started yet). Hoglet has actually already designed a pretty nice PCB for it, so my job is to shrink it down a little and move some stuff around to make it easier to design an enclosure for. I've been looking forward to building one of these for a long time!
Is there any update on the production of the pcb or making the design available ?

Many thanks

User avatar
myelin
Posts: 410
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by myelin » Mon Apr 23, 2018 5:44 pm

Budgie wrote:Is there any update on the production of the pcb or making the design available ?
I overpromised a bit there :) Came down with shingles in January, and that derailed my retro hardware efforts for a while.

Hoglet put up his current designs here; if you're feeling adventurous, I think the V2 PCB would probably work. You're probably planning on making one for an Electron, which means you'll need the 74LS08 chip to amplify the signal, so breadboarding it may be a bit tricky.

I'll have a look at this tonight. From what I can see, it should be possible to simplify it a bit by removing the 3.3V regulator (seeing as the Pi will power the 3V3 rail) and moving the JTAG header out of the way of the signals that go to the Pi. I'll report back once I've had a go at it!
SW/EE from New Zealand, now in San Francisco, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Mon Apr 23, 2018 5:49 pm

myelin wrote:
Budgie wrote:Is there any update on the production of the pcb or making the design available ?
I overpromised a bit there :) Came down with shingles in January, and that derailed my retro hardware efforts for a while.

Hoglet put up his current designs here; if you're feeling adventurous, I think the V2 PCB would probably work. You're probably planning on making one for an Electron, which means you'll need the 74LS08 chip to amplify the signal, so breadboarding it may be a bit tricky.

I'll have a look at this tonight. From what I can see, it should be possible to simplify it a bit by removing the 3.3V regulator (seeing as the Pi will power the 3V3 rail) and moving the JTAG header out of the way of the signals that go to the Pi. I'll report back once I've had a go at it!
Thanks Myelin, I'm probably going to hack something together first just to see how well it works. I have a few FPGA/CPLD boards I can probably test against. I'm certainly interested in buying a complete board when/if they become available

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by hoglet » Mon Apr 23, 2018 6:02 pm

Andy,

This project probably isn't ready for prime-time yet, but if you are interested in prototyping then everything is on github.

What issue is your Electron?

If it's an issue 6, then you don't need the 74LS08, and prototyping becomes a bit easier.

Dave

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Mon Apr 23, 2018 6:47 pm

hoglet wrote:Andy,

This project probably isn't ready for prime-time yet, but if you are interested in prototyping then everything is on github.

What issue is your Electron?

If it's an issue 6, then you don't need the 74LS08, and prototyping becomes a bit easier.

Dave
Thanks Dave. It's an issue 6. I'll let you know how I get on once I get some time to try it out.

User avatar
myelin
Posts: 410
Joined: Tue Apr 26, 2016 9:17 pm
Location: San Francisco, CA, USA
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by myelin » Thu Apr 26, 2018 8:18 pm

myelin wrote:I'll have a look at this tonight. From what I can see, it should be possible to simplify it a bit by removing the 3.3V regulator (seeing as the Pi will power the 3V3 rail) and moving the JTAG header out of the way of the signals that go to the Pi. I'll report back once I've had a go at it!
So that turned out to be a total lie... I did not have a look at it at all :) I will at some point (I'm hoping to have at least one of these operational before the Vintage Computer Federation event in early August) but it'll probably be a while, so I'd recommend prototyping one with an XC9572XL board if you want it any time in the next few months. I'll absolutely be posting out some PCBs... once I actually make them!
SW/EE from New Zealand, now in San Francisco, making BBC/Electron hardware projects for fun.
Most popular: fast serial port, FX2+PiTubeDirect Tube/Cartridge adapter, USB cart interface.

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Thu Apr 26, 2018 9:55 pm

myelin wrote:
myelin wrote:I'll have a look at this tonight. From what I can see, it should be possible to simplify it a bit by removing the 3.3V regulator (seeing as the Pi will power the 3V3 rail) and moving the JTAG header out of the way of the signals that go to the Pi. I'll report back once I've had a go at it!
So that turned out to be a total lie... I did not have a look at it at all :) I will at some point (I'm hoping to have at least one of these operational before the Vintage Computer Federation event in early August) but it'll probably be a while, so I'd recommend prototyping one with an XC9572XL board if you want it any time in the next few months. I'll absolutely be posting out some PCBs... once I actually make them!
Thanks Myelin. I’ll continue to play with this and see how I get on. I’m actually using a board I created for the RC2014 board which has a XC95144XL on it.

User avatar
richardtoohey
Posts: 3563
Joined: Thu Dec 29, 2011 5:13 am
Location: Tauranga, New Zealand
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by richardtoohey » Fri Apr 27, 2018 6:48 am

I've added this to my HUGE interesting-projects-to-look-at-one-day pile, so interested in seeing how it goes for you guys (sure you won't procrastinate as much as me.)

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Wed May 02, 2018 8:20 pm

Hi Dave

How do I compile the Pi source code. I’m running Windows. Do I need to download CMake and then play with the scripts. Just asking now in case I start installing all this and it’s not the correct process.

Thanks !

Andy

dp11
Posts: 797
Joined: Sun Aug 12, 2012 8:47 pm
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by dp11 » Wed May 02, 2018 8:31 pm

Under windows use the bash shell . Roughly follow the instructions here :https://github.com/hoglet67/PiTubeDirec ... pendencies

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Wed May 02, 2018 8:48 pm

dp11 wrote:Under windows use the bash shell . Roughly follow the instructions here :https://github.com/hoglet67/PiTubeDirec ... pendencies
Thanks. Just looked there now after remembering PiTubeDirect was also based on a bare metal solution.

Will give this a go

Andy

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Thu May 03, 2018 5:56 pm

Think I now have the pi code compiled and working.

It comes up with

INFO: RGB to HDMI booted
INFO: Nominal clock = 384000000 Hz


Hope thats correct. Now onto the CPLD. I'm away this weekend so maybe sometime next week...

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by hoglet » Thu May 03, 2018 6:58 pm

Budgie wrote:Think I now have the pi code compiled and working.

It comes up with

INFO: RGB to HDMI booted
INFO: Nominal clock = 384000000 Hz
That seems OK - does it hang at that point?

The next thing it does it to try to do some measurements of the VSYNC frequency, and I'm not sure what happens if there is no VSYNC signal.

Dave

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Thu May 03, 2018 10:48 pm

hoglet wrote:
Budgie wrote:Think I now have the pi code compiled and working.

It comes up with

INFO: RGB to HDMI booted
INFO: Nominal clock = 384000000 Hz
That seems OK - does it hang at that point?

The next thing it does it to try to do some measurements of the VSYNC frequency, and I'm not sure what happens if there is no VSYNC signal.

Dave
Yes just those two lines displayed on the serial console but nothing hooked up to the CPLD or Beeb yet.

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Thu May 10, 2018 11:37 pm

Well I've programmed the CPLD and after some messing it works !

I've used a CPLD board I had which creates a Spectrum ULA for the RC2014 board. Just something I had which allowed me to use a XC95144XL CPLD.

Well for anyone else who may be messing around with this I have found the following

1. If you just connect the Pi to a TV without the CPLD you get the usual Pi "Rainbow" screen only. The serial terminal will display "RGB to HDMI booted"
2. Once the CPLD is connected and working but no BBC is connected you still get the same "Rainbow" screen
3. Essentially the Pi doesn't move on from the "Rainbow" screen until it receives a Sync signal from the BBC via the RGB connector
4. Once the BBC is connected and powered on the usual "BBC Computer 32K" will be displayed

Note that if you have any issues with the CPLD and particularly the clock you will just get a black blank screen. If you remove the clock from the Pi to the CPLD the screen freezes on what it was last displaying. I guess this is expected given the Pi will just be sending what ever was last written to the screen buffer.


Just some things I noticed while trying to get it working.



Cheers

Andy
Attachments
RGBtoHDMI_1.jpg
RGBtoHDMI_2.jpg

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by hoglet » Fri May 11, 2018 5:58 am

Hi Budgie,

Great that you have made some progress with this.

I had quite a few problems with getting a prototype working reliably. I found the earth between the Pi and the CPLD board needs to be very good. I also needed to add a resistor into sp_clk line to prevent ringing causing unwanted clock transitions.

A couple of questions.

1. Are you using the DEBUG build?

Code: Select all

./clobber
./configure_rpi.sh -DDEBUG=1
there is lots more useful output on the serial port with this.

2. Have you tried the auto calibration feature (i.e. pressing the push button)? You need plenty of static text on the screen when running this. It takes just a few seconds and the image should wobble slightly then be rock steady with no twittering pixels. You need to do the separately in MODE 7 and MODES 0-6 (i.e. twice).

3. After calibration, how stable is the image over time. I sometimes find a re-calibration is necessary after the machine has been on for an hour. MODE7 is by far the most challenging, and I would be surprised if this was perfect.

4. What monitor are you using, and what is it's native resolution? It should be possible to tweak the video settings in config.txt to give accurate pixel mapping, with no moire. I can work out the best values if you tell me the native resolution.

A good test screen is:

Code: Select all

10 MODE 0
20 FOR X%=0 TO 1279 STEP 4
30 MOVE X%, 0
40 DRAW X%, 511
50 NEXT
60 FOR Y%=512 TO 1023 STEP 8
70 MOVE 0,Y%
80 DRAW 1279, Y%
90 NEXT
test.png
I really must get my act together and finish the PCB for this.

Dave

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Fri May 11, 2018 2:46 pm

hoglet wrote:Hi Budgie,

Great that you have made some progress with this.

I had quite a few problems with getting a prototype working reliably. I found the earth between the Pi and the CPLD board needs to be very good. I also needed to add a resistor into sp_clk line to prevent ringing causing unwanted clock transitions.

A couple of questions.

1. Are you using the DEBUG build?

Code: Select all

./clobber
./configure_rpi.sh -DDEBUG=1
there is lots more useful output on the serial port with this.

2. Have you tried the auto calibration feature (i.e. pressing the push button)? You need plenty of static text on the screen when running this. It takes just a few seconds and the image should wobble slightly then be rock steady with no twittering pixels. You need to do the separately in MODE 7 and MODES 0-6 (i.e. twice).

3. After calibration, how stable is the image over time. I sometimes find a re-calibration is necessary after the machine has been on for an hour. MODE7 is by far the most challenging, and I would be surprised if this was perfect.

4. What monitor are you using, and what is it's native resolution? It should be possible to tweak the video settings in config.txt to give accurate pixel mapping, with no moire. I can work out the best values if you tell me the native resolution.

A good test screen is:

Code: Select all

10 MODE 0
20 FOR X%=0 TO 1279 STEP 4
30 MOVE X%, 0
40 DRAW X%, 511
50 NEXT
60 FOR Y%=512 TO 1023 STEP 8
70 MOVE 0,Y%
80 DRAW 1279, Y%
90 NEXT
test.png
I really must get my act together and finish the PCB for this.

Dave
1. Just enabled this now.

2. Yes. The results are mixed. I'm finding mode 0-6 work pretty well. Mode 7 varies. It seems better when the Pi is rebooted. If I use the calibration it tends not to work too well. i.e. twitching pixels and red fringes around characters. This could easily be down to my wiring though ! I tried this with your test pattern.

3. I'll monitor this but seems to stay pretty stable over time

4. I've moved to a BenQ. Resolution is 1920 x 1080

Did you find until you changed the ground wire and added the resistor things were very poor or just didn't work or things slightly improved ? Only asking because as yet I haven't made these changes. For some reason I'm having trouble seeing the SP_CLK on the scope.

Thanks

Andy

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

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by hoglet » Fri May 11, 2018 3:11 pm

Budgie wrote: Did you find until you changed the ground wire and added the resistor things were very poor or just didn't work or things slightly improved ?
I wasn't able to get a consistently stable picture until I shortened the ground wire to about 5cm. The main clock (not SP_CLK) from the Pi to the CPLD is 96MHz, which is actually pretty fast for the type of construction we both currently have.
Budgie wrote: Only asking because as yet I haven't made these changes. For some reason I'm having trouble seeing the SP_CLK on the scope.
The SP_CLK signal is used to clock the serial scan chain, which is used to load pixel sampling offset into the CPLD. It will only be active for a brief period after the Pi is reset, and also again during the calibration. The problem is, just one extra spurious clock edge on this signal will completely mess up all the sampling offsets. The picture will still be there, but there will be lots of pixel missampling.

When you press the calibrate button with the test image up in Mode 0, you should definitely see some change. Over a few seconds it will run through all six possible sampling offsets. At each offset it will measure the stability of the image by looking for differences between frames. It then picks the most stable position. The debug log file should show you some details:

Code: Select all

INFO: Calibrating modes 0..6
DEBUG: sample point 0: diff:  sum = 0 mean = 0, min = 0, max = 0
DEBUG: sample point 1: diff:  sum = 9280 mean = 928, min = 86, max = 1842
DEBUG: sample point 2: diff:  sum = 7132 mean = 713, min = 330, max = 2486
DEBUG: sample point 3: diff:  sum = 5668 mean = 566, min = 290, max = 884
DEBUG: sample point 4: diff:  sum = 0 mean = 0, min = 0, max = 0
DEBUG: sample point 5: diff:  sum = 0 mean = 0, min = 0, max = 0
INFO: Setting sp_default = 0
It would be interesting to see what you get:
a) With the test image
b) With a screen just showing a small amount of text, e.g. a LIST of the test image program

There is room for improvement here in the software. In the above, the best sampling offset would be 5, but it has picked zero. I wonder if a better algorithm would be to look for the worst point, and then choose the position three away from that.

Anyway, as someone else is taking an interest in this, my motivation to get a PCB made I think will increase!

Dave

Budgie
Posts: 73
Joined: Mon Nov 02, 2015 9:14 pm
Location: Manchester, UK
Contact:

Re: RGB to HDMI using a Pi Zero and a small CPLD

Post by Budgie » Fri May 11, 2018 4:42 pm

Yes I've monitored the log and it does everything you say. What resistor size did you use in the clock wire ? and was this the 96Mhz clock of the SP_CLK ?

The test pattern (especially the bottom half of the screen) definitely makes a difference when testing. If you just look at text it can all look okay but the pattern shows up the issues much more.

See below the test pattern (bottom only) after switch on and then after a calibration (i.e. pushing the button). Not sure why it doesn't calibrate on switch on ?

After switch on the log just shows

INFO: COPRO : 0
DEBUG: enable_MMU_and_IDCaches
DEBUG: Setting up divisor
DEBUG: A GP_CLK1_DIV = 00028000
DEBUG: B GP_CLK1_CTL = 00000200
DEBUG: C GP_CLK1_CTL = 00000005
DEBUG: D GP_CLK1_CTL = 00000005
DEBUG: E GP_CLK1_CTL = 00000005
DEBUG: F GP_CLK1_CTL = 00000015
DEBUG: G GP_CLK1_CTL = 00000095
DEBUG: H GP_CLK1_DIV = 0000c000
DEBUG: Done setting up divisor
DEBUG: Setting mode7 = 0
DEBUG: Setting up frame buffer
INFO: Framebuf struct address: 0x8010000
INFO: Initialised Framebuffer: 672x540
INFO: Pitch: 336 bytes
INFO: Framebuffer address: DF9A2000
DEBUG: Done setting up frame buffer
DEBUG: Entering rgb_to_fb


Interestingly or not so interestingly I've just zapped my CPLD switching the beeb off of all things. I've only got RGB and SYNC connected not GND and 5V from the RGB connector. Not sure whether some suppression would be worth having on the PCB from the connector. May have been a one off as I do mess around a lot with this board.

I've fitted a new CPLD and all now working again.

I think this is a great product and well worth making boards for. Let me know when you have a final KiCAD PCB layout to test and I'll be happy to order a few and test accordingly.

Andy
Attachments
RGBtoHDMI_5.jpg
RGBtoHDMI_4.jpg

Post Reply