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

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

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

MisterN64CoreRGBPWM.jpg
MisterN64CoreRGBPWM.jpg (448.63 KiB) Viewed 3434 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 3434 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 3434 times

I have included a build for N64 and PSX, 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/Mister64PWM

It seems to work quite well and may be a good alternative to using direct video or buying a new 24-bit IO board. Hopefully these changes can be added to the Mister framework at some point, but I am still doing some testing for now.

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.
edit2 13/02/2024: Update to latest N64 changes and disabled PWM for scaled output as it was causing jitter.
edit3 15/02/2024: Added Groovy core with PWM.

Attachments
GroovyPWM_20240215.rbf
(3.6 MiB) Downloaded 16 times
N64CoreWithPWM_20240213.rbf
(3.59 MiB) Downloaded 19 times
PSXCoreWithPWM_20240121.rbf
(4.12 MiB) Downloaded 93 times
N64CoreWithPWM_20240121.rbf
(3.61 MiB) Downloaded 84 times
User avatar
lagerfeldt
Posts: 150
Joined: Mon Jan 03, 2022 8:32 pm
Location: Denmark
Has thanked: 31 times
Been thanked: 75 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: 489
Joined: Fri Jan 22, 2021 4:36 pm
Has thanked: 55 times
Been thanked: 210 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: 733
Joined: Mon Mar 01, 2021 3:10 pm
Has thanked: 43 times
Been thanked: 319 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: 75
Joined: Sun May 24, 2020 11:40 pm
Has thanked: 57 times
Been thanked: 26 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 3348 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 3348 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 3348 times

Real PS1

sotn-01-c-real-psx.jpg
sotn-01-c-real-psx.jpg (644.8 KiB) Viewed 3348 times
User avatar
limi
Top Contributor
Posts: 600
Joined: Sun May 24, 2020 6:53 pm
Has thanked: 126 times
Been thanked: 409 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: 3
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 15 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: 80
Joined: Mon Nov 15, 2021 9:05 pm
Has thanked: 44 times
Been thanked: 7 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: 335
Joined: Fri Feb 18, 2022 7:29 pm
Has thanked: 225 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: 75
Joined: Sun May 24, 2020 11:40 pm
Has thanked: 57 times
Been thanked: 26 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: 150
Joined: Mon Aug 31, 2020 8:05 pm
Has thanked: 56 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: 3
Joined: Fri Dec 01, 2023 1:45 pm
Been thanked: 15 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.

Post Reply