PWM on 18-bit DAC to get 24-bit Color

Discussion of developmental aspects of the MiSTer Project.
Ruleset
Posts: 10
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 33 times

PWM on 18-bit DAC to get 24-bit Color

Unread post by Ruleset »

I have made a couple of builds that add PWM on the 18-bit DAC to get 24-bit color for the cores that need it. This is for any non-scaled signals that use the VGA port on the IO board. It works by quickly alternating between two different color values to get a color in between. The PWM happens very fast so it can be done even for 640 wide images.

We have been testing it on the Mister FPGA discord, here are some pictures:
RGB SCART:

MisterN64CoreRGBPWM.jpg
MisterN64CoreRGBPWM.jpg (448.63 KiB) Viewed 6837 times

Active Y/C S-video PWM off:

sotn-svid-01-a-pwm-off.jpg
sotn-svid-01-a-pwm-off.jpg (454.81 KiB) Viewed 6837 times

Active Y/C S-video PWM on:

sotn-svid-01-b-pwm-on.jpg
sotn-svid-01-b-pwm-on.jpg (391.52 KiB) Viewed 6837 times

I have included a build for N64, PSX and Saturn, PWM is always on in these builds, no settings needed.

Here is my fork of the N64 core with the PWM changes: https://github.com/Jokippo/N64_MiSTer_PWM

It seems to work quite well and may be a good alternative to using direct video or buying a new 24-bit IO board. For now, it looks like this won't be included in the MiSTer framework.

edit: Updated N64 core to most recent source. PSX core had some red color shift on component, might be a bit less on this build.
edit 13/02/2024: Update to latest N64 changes and disabled PWM for scaled output as it was causing jitter.
edit 15/02/2024: Added Groovy core with PWM.
edit 28/02/2024: Update n64 and add Saturn Core.
edit 14/03/2024: Update n64 core, PWM is included as standard in Groovy now so you can download that from the official Github.
edit 08/04/2024: Update of all 3 cores to latest source.

Attachments
SaturnPWM_20240408.rbf
(4.41 MiB) Downloaded 30 times
PSXPWM_20240408.rbf
(4.14 MiB) Downloaded 30 times
N64PWM_20240408.rbf
(3.64 MiB) Downloaded 32 times
User avatar
lagerfeldt
Posts: 158
Joined: Mon Jan 03, 2022 8:32 pm
Location: Denmark
Has thanked: 31 times
Been thanked: 79 times
Contact:

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by lagerfeldt »

Awesomeness

Patron of MiSTer + theypsilon + Jotego Team + Coin-Op Collection + Pierco + Nullobject

MiSTer RePlay website

Ultimate SID Collection website

Bas
Top Contributor
Posts: 550
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 71 times
Been thanked: 256 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Bas »

I'm not the sharpest tool in this shed... PWM?

FPGA64
Top Contributor
Posts: 771
Joined: Mon Mar 01, 2021 3:10 pm
Has thanked: 45 times
Been thanked: 330 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by FPGA64 »

Bas wrote: Sat Jan 13, 2024 9:17 pm

I'm not the sharpest tool in this shed... PWM?

Pulse width modulation

KennyL
Posts: 85
Joined: Sun May 24, 2020 11:40 pm
Has thanked: 61 times
Been thanked: 30 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by KennyL »

I tested it a bit and it's really awesome. I had a lot of trouble with direct video setup so this option is really great. Really nice to regain dual output in my setup also. Is it possible put PWM in Saturn core and Groovy_mister?

Here's comparison on my small consumer Trinitron. My phone does a lot of color processing so please ignore the color. In person, PWM looks better than direct video on my setup. Brighter and smoother. Real PS1 is smoother still. YMMV.

Analogue IO board VGA, active Y/C board composite, PWM off

sotn-01-a-vga-pwm-off.jpg
sotn-01-a-vga-pwm-off.jpg (791.81 KiB) Viewed 6751 times

Analogue IO board VGA, active Y/C board composite, PWM on

sotn-01-b-vga-pwm-on.jpg
sotn-01-b-vga-pwm-on.jpg (769.1 KiB) Viewed 6751 times

Direct video (Benfei CS5210 chip), active Y/C board composite

sotn-01-d-direct-video.jpg
sotn-01-d-direct-video.jpg (771.48 KiB) Viewed 6751 times

Real PS1

sotn-01-c-real-psx.jpg
sotn-01-c-real-psx.jpg (644.8 KiB) Viewed 6751 times
User avatar
limi
Top Contributor
Posts: 636
Joined: Sun May 24, 2020 6:53 pm
Has thanked: 145 times
Been thanked: 446 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by limi »

Looking great!

bricabrac
Posts: 27
Joined: Wed May 11, 2022 8:47 pm
Has thanked: 18 times
Been thanked: 5 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by bricabrac »

Ruleset wrote: Sat Jan 13, 2024 6:53 pm

I have made a couple of builds that add PWM on the 18-bit DAC to get 24-bit color for the cores that need it. This is for any signal that uses the VGA port on the IO board. It works by quickly alternating between two different color values to get a color in between. The PWM happens very fast so it can be done even for 640 wide images.

This looks great on the pictures. Have to check it tomorrow. Many thanks for doing this as PSX really needs that 24bit colour and N64 will too.

I terms of tech solution am I correct that you somehow have access to the original, i.e. 24bit colour value, and then are trying to simulate it on 18bit DAC "filling" the gaps in colour resolution by incorporation the PWM?

Ruleset
Posts: 10
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 33 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Ruleset »

bricabrac wrote: Sat Jan 13, 2024 10:43 pm
Ruleset wrote: Sat Jan 13, 2024 6:53 pm

I have made a couple of builds that add PWM on the 18-bit DAC to get 24-bit color for the cores that need it. This is for any signal that uses the VGA port on the IO board. It works by quickly alternating between two different color values to get a color in between. The PWM happens very fast so it can be done even for 640 wide images.

This looks great on the pictures. Have to check it tomorrow. Many thanks for doing this as PSX really needs that 24bit colour and N64 will too.

I terms of tech solution am I correct that you somehow have access to the original, i.e. 24bit colour value, and then are trying to simulate it on 18bit DAC "filling" the gaps in colour resolution by incorporation the PWM?

The original 24-bit color is already available for direct video and HDMI, PWM just pulses the right colors based on the 6 bits that are not sent to the 18-bit DAC.

Stinky
Posts: 84
Joined: Mon Nov 15, 2021 9:05 pm
Has thanked: 48 times
Been thanked: 9 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Stinky »

Great idea, real hacker solution!

User avatar
PistolsAtDawn
Posts: 340
Joined: Fri Feb 18, 2022 7:29 pm
Has thanked: 249 times
Been thanked: 90 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by PistolsAtDawn »

I love this! Thank you!

dyanand
Posts: 2
Joined: Mon Apr 10, 2023 3:31 pm
Has thanked: 1 time

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by dyanand »

Been trying out the PSX PWM core on my mister hooked up by component - what a huge difference! Awesome!

bricabrac
Posts: 27
Joined: Wed May 11, 2022 8:47 pm
Has thanked: 18 times
Been thanked: 5 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by bricabrac »

I confirm it is a night and day difference. Fantastic solution and something that truly deserves to be incorporated in MiSTer framework for all cores that can output 24bit colour to make use of its magic. Thank you for making it happen.

KennyL
Posts: 85
Joined: Sun May 24, 2020 11:40 pm
Has thanked: 61 times
Been thanked: 30 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by KennyL »

New updates (20210121) look great. Using PS1 240p Test Suite color bars, way less red shift on dark blues. Darkest reds and greens also look better. They looked kind of grayish previously. At least on my plasma tv via component.

User avatar
mapf
Posts: 153
Joined: Mon Aug 31, 2020 8:05 pm
Has thanked: 58 times
Been thanked: 51 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by mapf »

I tested the last version for the N64. I have two setups that I can switch between. It works without problems on my 15KHz CRT TV.

When I use the analog output with a VGA monitor in higher resolutions, the PWM still gets applied (and color banding still seems to be reduced), but the image shows interference. It looks similar to dot crawl on composite connections, with edges showing moving bright pixels. It is clearly visible in the OSD, where all letters are jittery. The effect is more visible the higher the resolution.

Ruleset
Posts: 10
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 33 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Ruleset »

mapf wrote: Mon Feb 05, 2024 8:42 pm

I tested the last version for the N64. I have two setups that I can switch between. It works without problems on my 15KHz CRT TV.

When I use the analog output with a VGA monitor in higher resolutions, the PWM still gets applied (and color banding still seems to be reduced), but the image shows interference. It looks similar to dot crawl on composite connections, with edges showing moving bright pixels. It is clearly visible in the OSD, where all letters are jittery. The effect is more visible the higher the resolution.

Yes, when using the scaler, PWM causes jitter. The scaler clock isn't fast enough to do PWM so it uses the video clock to do the modulation. But since the scaler and video clocks are different they don't align and end up jittering. I don't have a good solution for this yet, maybe PWM should just be disabled for the scaler output.

naylord
Posts: 46
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 12 times
Been thanked: 3 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by naylord »

wow this is sick. Why can't this be integrated into MiSTer main as an option for those that would want it?

Ruleset
Posts: 10
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 33 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Ruleset »

naylord wrote: Sat Mar 16, 2024 12:26 am

wow this is sick. Why can't this be integrated into MiSTer main as an option for those that would want it?

I made a PR but Sorgelig wasn't interested. He said he preferred people getting a new 24-bit board over adding complexity to the framework.

I personally don't think it is too complex, but Sorgelig can probably judge that better.

naylord
Posts: 46
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 12 times
Been thanked: 3 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by naylord »

Ruleset wrote: Sat Mar 16, 2024 11:46 am
naylord wrote: Sat Mar 16, 2024 12:26 am

wow this is sick. Why can't this be integrated into MiSTer main as an option for those that would want it?

I made a PR but Sorgelig wasn't interested. He said he preferred people getting a new 24-bit board over adding complexity to the framework.

I personally don't think it is too complex, but Sorgelig can probably judge that better.

That practically makes me tempted to put on a tinfoil hat that there's some sort of kickback arrangement on V2 board sales

Neocaron
Posts: 350
Joined: Sun Sep 27, 2020 10:16 am
Has thanked: 191 times
Been thanked: 71 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Neocaron »

It works great on a per core basis and it's transformative on Groovy, N64 and PSX core so you would think the feature should be part of the Mister framework, but since it doesn't stop the devs from integrating the feature anyway like Groovy did, it's not a terrible problem.

naylord
Posts: 46
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 12 times
Been thanked: 3 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by naylord »

Neocaron wrote: Sun Mar 17, 2024 1:42 am

It works great on a per core basis and it's transformative on Groovy, N64 and PSX core so you would think the feature should be part of the Mister framework, but since it doesn't stop the devs from integrating the feature anyway like Groovy did, it's not a terrible problem.

Right, though does this mean there has to be a new PWM release for every mainline N64/PSX/Groovy release that needs to be manually installed? Seems like a lot of maintence vs just integrating on main.

Neocaron
Posts: 350
Joined: Sun Sep 27, 2020 10:16 am
Has thanked: 191 times
Been thanked: 71 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Neocaron »

naylord wrote: Sun Mar 17, 2024 4:27 am
Neocaron wrote: Sun Mar 17, 2024 1:42 am

It works great on a per core basis and it's transformative on Groovy, N64 and PSX core so you would think the feature should be part of the Mister framework, but since it doesn't stop the devs from integrating the feature anyway like Groovy did, it's not a terrible problem.

Right, though does this mean there has to be a new PWM release for every mainline N64/PSX/Groovy release that needs to be manually installed? Seems like a lot of maintence vs just integrating on main.

Groovvy is fully integrated, but the N64 and PSX or Saturn isn't so yeah, It will need a constant update if you want it on the latest version.

User avatar
mapf
Posts: 153
Joined: Mon Aug 31, 2020 8:05 pm
Has thanked: 58 times
Been thanked: 51 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by mapf »

Ruleset wrote: Mon Feb 05, 2024 9:38 pm

Yes, when using the scaler, PWM causes jitter. The scaler clock isn't fast enough to do PWM so it uses the video clock to do the modulation. But since the scaler and video clocks are different they don't align and end up jittering. I don't have a good solution for this yet, maybe PWM should just be disabled for the scaler output.

Did you find a solution for this? Can PWM be selectively disabled if the scaler is active? (Should also be disabled for direct video, I guess).

Ruleset
Posts: 10
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 33 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Ruleset »

mapf wrote: Mon Mar 18, 2024 6:58 pm
Ruleset wrote: Mon Feb 05, 2024 9:38 pm

Yes, when using the scaler, PWM causes jitter. The scaler clock isn't fast enough to do PWM so it uses the video clock to do the modulation. But since the scaler and video clocks are different they don't align and end up jittering. I don't have a good solution for this yet, maybe PWM should just be disabled for the scaler output.

Did you find a solution for this? Can PWM be selectively disabled if the scaler is active? (Should also be disabled for direct video, I guess).

PWM is disabled for scaled output in all builds after 13/02/2024. Direct video doesn't go through the VGA port so it is not affected by PWM.

User avatar
mapf
Posts: 153
Joined: Mon Aug 31, 2020 8:05 pm
Has thanked: 58 times
Been thanked: 51 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by mapf »

Ruleset wrote: Mon Mar 18, 2024 8:02 pm

PWM is disabled for scaled output in all builds after 13/02/2024. Direct video doesn't go through the VGA port so it is not affected by PWM.

That is what I get for only looking at the latest post in threads - found the updates in the first post :D

naylord
Posts: 46
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 12 times
Been thanked: 3 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by naylord »

Hello, any chance we can also get an rbf for the PSX 2x core? That one was a oneoff so one benefit is not only the 2X cpu but also that since there are no more updates, if we get PWM for it the core is basically perfect forever.

I still usually use the default 1X core, but 2x speed for increased frame rates is nice in certain games. Still, I like my slowdown in most games oddly enough; like in r-type delta I just think of it as a dynamic bullet time.

Also I'm curious if there's any value to older cores. Like I guess Genesis doesn't have enough colors on screen at a time to make 24 bit worth it? Or would it add value?

Ruleset
Posts: 10
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 33 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by Ruleset »

naylord wrote: Tue Mar 19, 2024 1:44 am

Hello, any chance we can also get an rbf for the PSX 2x core? That one was a oneoff so one benefit is not only the 2X cpu but also that since there are no more updates, if we get PWM for it the core is basically perfect forever.

I still usually use the default 1X core, but 2x speed for increased frame rates is nice in certain games. Still, I like my slowdown in most games oddly enough; like in r-type delta I just think of it as a dynamic bullet time.

Also I'm curious if there's any value to older cores. Like I guess Genesis doesn't have enough colors on screen at a time to make 24 bit worth it? Or would it add value?

I am not sure if FPGAZumSpass ever released the 2x code.

Non 24-bit cores might benefit on YPbPr and S-Video/composite. I have seen some test on Discord that seem to show an improvement on these signals even when using non 24-bit color modes. I think this is because of how these signals are encoded.

A comparison that KennyL took on component, this was on the PSX core but the 240p test suite doesn't use 24-bit colors I believe. PWM off:

psx240p-01-a-component-pwm-off.png
psx240p-01-a-component-pwm-off.png (522.12 KiB) Viewed 2023 times

PWM on:

psx240p-01-b-component-pwm-on.png
psx240p-01-b-component-pwm-on.png (527.93 KiB) Viewed 2023 times

So it might be worth it for those signals.

KennyL
Posts: 85
Joined: Sun May 24, 2020 11:40 pm
Has thanked: 61 times
Been thanked: 30 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by KennyL »

It's a bit hard to see from the pictures I took above but psx 240p test color bars are not ramping smoothly via my analogue io board without PWM but they're much smoother with PWM. Very clear to see inperson. There are still spots that are not smooth but much better. It's impossible for me to tell the difference in actual psx in-game 15bit graphics though.

I have Misteraddons analogue io board and it would be interesting to see how smoothly color bars ramp on other analogue io boards.

naylord
Posts: 46
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 12 times
Been thanked: 3 times

Re: PWM on 18-bit DAC to get 24-bit Color

Unread post by naylord »

It blows my mind that something this awesome isn't the top of all the mister news outlets. Like how is this not the subject of a videogame esoterica video/ pixel cherry ninja video yet?

Post Reply