Add PWM with user selected output device PWM integrator #89
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Warning, this is a very lengthy PR comment since this PR contains a fairly complicated new feature that took me quite some time to (i hope) understand.
Context
When I played with Twilight Zone, I stumbled upon 2 problems:
When I experimented with XMen, I had the same problem with (LED) flashers that I solved by pushing their power to unrealistic values but giving visually ok results. Lately, I played with CFTBL and the GI seemed broken needing hacks, and the flashers were not true to the real thing either. This added up with Guns'n Roses were flashers bulbs are directly visible to the player, and did not look about right.
After investigation, GI implementation in pinmame WPC only worked when a single light was dimmed. If more than one is dimmed at the same time, it woud break. So it was a controller emulation bug which is now (mostly) solved.
For the flashers, it is far more difficult and hence all the maths and tests made here. My understanding of the problem is the following:
Pulse Width Modulation used in Pinball hardware as I understand it
PWM is used with Triac/Thyristor/Darlington Transistor driven outputs for :
The effect on a device of PWM is entirely different depending on the connected device and its physical characteristic.
For example, an incandescent bulb is a varying resistor with resistance depending on filament temperature. It has a non linear heating/cooling curve. We measured a specific 44 bulb to ramp up from <10% visible emission to >90% in around 37ms. Its behavior (light flow & color) depends on the filament temperature.
On the other hand, LEDs have more or less instantaneous switching time (below 1µs). Online ressources state that most humans will not perceive flashing on/off LED above 50 cycles per second (100Hz) as flicker/flashing but only its strobscopic effect (lik wheel not moving in a movie), below this it depends on each human, finally, around and under 10 cycles per second (20Hz) most people will see the LED as flashing.
So the frequency limits between flashing and dimming for these 2 type of lights will be different as well as their visible emission outputs.
Another example are solenoids or shaker motors where the time constant are fairly larger than for LED & incandescent bulbs.
One point to note is that the connected devices can vary for a given table (for example, some tables have been shipped with 44 incandescent bulbs, but may be ran with 47 in a custom version).
Pinmame WPC PWM implementation
Pinmame WPC driver samples every 2 IRQ, then smooths lineary other the 28 samples. Therefore, the smoothing is performed over 56 IRQ, meaning every 56*8192/8000000 = 57,344ms (17 times per second).
This seems to work well for inductive outputs like solenoids but has a few drawbacks for others since it is not tied to the effective connected output device:
Each other driver implements a custom and different behavior.
Proposed fix
To account for these, the overall implementation needs to be aware of the connected device and simulates its dedicated response on the effective output device. Therefore it needs to take in acount :
3 ways for implementing it were investigated:
The first solution would need a large change of the code, with some challenge regarding backward compatibility, and would not solve the problem of taking in account the effective user output device, so it was not pursued. The second was initially attempted but was not satisfying for client application that access PinMame through low throughput communication (PPUC), it was not pursued either but the intent was (somewhat) kept for the proposed fix which is based on the third solution.
The proposed PR has the following features:
The PR rely on the following set of integrators:
Regarding light integrators :
How to use
The PR adds ModOutputType property to VPinMame Controller, but since it is usely accessed through B2S, it also extends SolMask property which is already used to setup modulated outputs:
Controller.SolMask(1000) = 301
will setup Solenoid 0 to use a 89 bulb wired like a flasher in a WPC system,Controller.SolMask(1200) = 100
will setup GI 0 to use a 44 bulb wired to 6.3V AC.Bulbs characteristics and wiring
Here are some findings on bulbs characteristics and wiring that were used to design this fix. These are just observation and will vary from boards to boards but give some hints on how the different values were chosen.
Example outputs
The graphics below are a plot of the PWM integration at 1ms (so not the one that would be rendered at 60FPS, therefore 16ms period). White lines are the output digital state, blue line is the PWM integration (44 & 89 bulbs).
Twilight zone has one of the most complex PWM diming light show I found so far. For example (during Clock Millions) with full power flasher pulse but also short low power ones (Sol 28), sequences of flashes of different power (Sol 19) or GI dimming waves:
Tales of the Arabian Night also exhibits some complex dimming, like the genie flasher which is constantly slowly pulsed at mid power (Sol 25) or waves of GI fading when skillshot is succeeded like below: