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

Discussion of developmental aspects of the MiSTer Project.
Ruleset
Posts: 26
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 100 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 22211 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 22211 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 22211 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.

If you want these build to be included in update_all then add these lines to downloader.ini:

Code: Select all

[Jokippo/MiSTer_PWM_Cores]
db_url = https://raw.githubusercontent.com/Jokippo/MiSTer_PWM_Cores/db/db.json.zip

A folder 'ConsolePWM' will be created with the PWM cores inside

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.
edit 04/05/2024: Update all 3 cores.
edit 07/05/2024: N64 core had some vertical green lines on HDMI output, should be fixed now.
edit 12/06/2024: Update PSX and Saturn
edit 19/07/2024: Update PSX and Saturn
edit 15/08/2024: Updated N64(fixes for Conker's Bad fur day, Star Wars Naboo, Gauntlet Legends, Zelda MM telescope transition) and Saturn.
edit 18/08/2024: Updated N64
edit 24/08/2024: Updated Saturn
edit 31/08/2024: Updated PSX
edit 02/09/2024: Add repository for custom update_all database.
edit 24/09/2024: Add PSX 2X (Turbo) Core.
edit 02/10/2024: Add N64 Turbo core and update regular core.
edit 15/10/2024: Update Saturn
edit 22/11/2024: Update Saturn

Attachments
Saturn_PWM_20241122.rbf
(4.41 MiB) Downloaded 10 times
N64_80MHz_PWM_20241002.rbf
(3.71 MiB) Downloaded 94 times
N64_PWM_20241002.rbf
(3.67 MiB) Downloaded 88 times
PSX2XCPU_PWM_20240924.rbf
(4.34 MiB) Downloaded 111 times
PSX_PWM_20240831.rbf
(4.14 MiB) Downloaded 149 times
User avatar
lagerfeldt
Posts: 170
Joined: Mon Jan 03, 2022 8:32 pm
Location: Denmark
Has thanked: 33 times
Been thanked: 85 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: 623
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 80 times
Been thanked: 324 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: 939
Joined: Mon Mar 01, 2021 3:10 pm
Has thanked: 49 times
Been thanked: 375 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: 121
Joined: Sun May 24, 2020 11:40 pm
Has thanked: 73 times
Been thanked: 50 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 22125 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 22125 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 22125 times

Real PS1

sotn-01-c-real-psx.jpg
sotn-01-c-real-psx.jpg (644.8 KiB) Viewed 22125 times
User avatar
limi
Top Contributor
Posts: 776
Joined: Sun May 24, 2020 6:53 pm
Has thanked: 180 times
Been thanked: 570 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: 21 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: 26
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 100 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: 99
Joined: Mon Nov 15, 2021 9:05 pm
Has thanked: 62 times
Been thanked: 14 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: 359
Joined: Fri Feb 18, 2022 7:29 pm
Has thanked: 307 times
Been thanked: 100 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: 21 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: 121
Joined: Sun May 24, 2020 11:40 pm
Has thanked: 73 times
Been thanked: 50 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: 164
Joined: Mon Aug 31, 2020 8:05 pm
Has thanked: 58 times
Been thanked: 56 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: 26
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 100 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: 53
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 20 times
Been thanked: 7 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: 26
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 100 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: 53
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 20 times
Been thanked: 7 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
Top Contributor
Posts: 375
Joined: Sun Sep 27, 2020 10:16 am
Has thanked: 209 times
Been thanked: 87 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.

Remastering Classic Game Cinematics: My new Youtube fun, check it out :D
https://www.youtube.com/@neocaron87

naylord
Posts: 53
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 20 times
Been thanked: 7 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
Top Contributor
Posts: 375
Joined: Sun Sep 27, 2020 10:16 am
Has thanked: 209 times
Been thanked: 87 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.

Remastering Classic Game Cinematics: My new Youtube fun, check it out :D
https://www.youtube.com/@neocaron87

User avatar
mapf
Posts: 164
Joined: Mon Aug 31, 2020 8:05 pm
Has thanked: 58 times
Been thanked: 56 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: 26
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 100 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: 164
Joined: Mon Aug 31, 2020 8:05 pm
Has thanked: 58 times
Been thanked: 56 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: 53
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 20 times
Been thanked: 7 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: 26
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 100 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 17241 times

PWM on:

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

So it might be worth it for those signals.

KennyL
Posts: 121
Joined: Sun May 24, 2020 11:40 pm
Has thanked: 73 times
Been thanked: 50 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: 53
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 20 times
Been thanked: 7 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?

naylord
Posts: 53
Joined: Sat May 21, 2022 11:55 pm
Has thanked: 20 times
Been thanked: 7 times

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

Unread post by naylord »

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 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
Active Y/C S-video PWM off:
sotn-svid-01-a-pwm-off.jpg
Active Y/C S-video PWM on:
sotn-svid-01-b-pwm-on.jpg

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.

Thanks so much for this! I've been really enjoying it. In particular I love it on the Saturn since the saturn supports scandoubler so it works perfectly on my 31khz crt (I find scandoubler so much better than scaling anyway, everything just works perfectly unlike trying to find the right resolution and even then I find there's weird borders often and whatnot; lack of scandoubler is a pain on psx/n64 when trying to use my 31khz crt but that's another issue)

Would you be able to do a final update on the Saturn core when the core gets buttoned up? Feels like were in the homestretch of development and it would be amazing to have PWM on the final or near final release so it could be the definitive way of playing Saturn games.
Thanks so much again!

Ruleset
Posts: 26
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 100 times

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

Unread post by Ruleset »

naylord wrote: Sat May 04, 2024 8:08 am

Would you be able to do a final update on the Saturn core when the core gets buttoned up? Feels like were in the homestretch of development and it would be amazing to have PWM on the final or near final release so it could be the definitive way of playing Saturn games.
Thanks so much again!

I'll make new builds probably about once a month if there are updates. Cores are updated to latest source today.

Post Reply