It is currently Fri Nov 17, 2017 12:34 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sat Oct 07, 2017 11:51 pm 
Offline
User avatar

Joined: Mon Apr 04, 2011 11:49 am
Posts: 1917
Location: WhereverIparkIt, USA
Quote:
I would like to directly attach a 0-5V PWM signal from a microcontroller

Did some testing of my own because I'm looking to do the same thing!

My test is pretty simple. I've attached it in case anyone else want to try. The rom only runs from $E000-FFFF so it should be fairly mapper independent assuming the last bank is fixed. Visually it doesn't display anything worthwhile, just some junk from my CICOp register test.

Only SQ1 & SQ2 channels are enabled, SQ1 is set to C4 (middle C) and SQ2 is set to E4. Both have 50% duty and max volume.

I did not find any negative voltage. I found a max output level of 350mV (note 10x probe used in scope shot) this is when both channels are active (summed). When only one channel was pulsing high, it's output is 200mV.

I can run some other simple tests like this if it's of interest, but this pretty much answered my questions.


Attachments:
File comment: 10x probe, 2a03 pin 1 scope shot
APU vol test CPU_pin1 sq1C4 sq2E4 max vol 10xprobe.JPG
APU vol test CPU_pin1 sq1C4 sq2E4 max vol 10xprobe.JPG [ 90.2 KiB | Viewed 282 times ]
File comment: test rom
inltest.nes [40.02 KiB]
Downloaded 9 times

_________________
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers
Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 12:21 am 
Offline
User avatar

Joined: Sun Nov 25, 2012 5:28 am
Posts: 23
Location: Adelaide, Australia
infiniteneslives wrote:
Did some testing of my own because I'm looking to do the same thing!


Great minds :wink:

...and you plan on adding 313K of resistance to compensate? or you have a better solution in mind?


Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 1:00 am 
Offline
User avatar

Joined: Mon Apr 04, 2011 11:49 am
Posts: 1917
Location: WhereverIparkIt, USA
uXe wrote:
...and you plan on adding 313K of resistance to compensate? or you have a better solution in mind?


What's your thinking on 313K? 0-5v signal from mcu, trying to get down to 200mV is a factor of 25. Thus you need 20k * (25 - 1) = 480K..?

Being a PWM DAC, it's fairly easy to reduce the synthesized channel to less than 5v. In an 8bit DAC a simple implementation would be for a square channel to have 4 bits of volume similar to the APU/VRC6/etc. So the channels max would be a DAC level of 15 out of 255 equates to 5.9% of 5v = 295mV for that channel without tweaking anything. A little beyond the target 150-200mV per channel to match the APU.

Couple ways to tweak things to match. An added 20K resistor would work, but I kinda like/have to assume many people simply soldered in a 47k for the audio mod. That's my preferred condition, and then adjust the PWM levels to match. So 67k divides that channel by 3.35, so 295mV -> 88mV equavalence if I'm understanding everything.

To get to a volume comparable to the APU, the level needs doubled bringing it to ~175mV. That can be done in the mcu by shifting the final output volume left by 1 bit. Sort of cuts an 8bit DAC down to 7bits in terms of number of total full volume channels prior to clipping, but that's manageable. 7bits would provide room for quite a few full volume channels at once. The lower bit really isn't lost either, channels could simply have 5 bits of volume to equal an APU square if they've got a use for the extra resolution.

P.S. I'm guessing I've made an error in my math/knowledge somewhere..

_________________
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers


Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 3:48 am 
Offline
User avatar

Joined: Sun Nov 25, 2012 5:28 am
Posts: 23
Location: Adelaide, Australia
infiniteneslives wrote:
What's your thinking on 313K? 0-5v signal from mcu, trying to get down to 200mV is a factor of 25. Thus you need 20k * (25 - 1) = 480K..?


Was just going on lidnariq's numbers from earlier in this thread:

viewtopic.php?f=9&t=56&start#p205492

Both CPU pin 1 and Expansion Port pin 3 feed into separate 20K resistors in the audio mixing / amplification circuit, so to match CPU pin 1's 0.3V as I understand it: 5V / 0.3V = 16.666666667 * 20 = 333.333333333 minus the 20K already in place equals 313K?

My problem is that I would not be using a DAC with amplitude settings, and be able to just reduce the signal down that way. I'm looking at a PWM pin on an 8-bit AVR, or likely just software PWM on a digital pin, so it's either on or off, 0 or 5V, full stop.


Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 4:28 am 
Offline
Formerly WheelInventor

Joined: Thu Apr 14, 2016 2:55 am
Posts: 1009
Location: Gothenburg, Sweden
It may actually be a benefit if an ext audio synth is a bit quieter than the internal APU.

This is because the steps between the 15 audio levels are quite coarse. Less full volume = finer steps, leading to smoother envelopes; something the APU can't* offer but a synth with a similar 4-bit interface can. That would enable using slow-moving envelopes (in a satisfactory/transparent way) more readily.

The max volume of the APU squares aren't very useful, IMO. There's many times i've wished for an "x.5" setting but i've never felt the need for maxing the squares. Rather, i avoid it.


*There's a workaround for the apu wich is chorusing two square channels and then you can kind of get doubly fine volume steps at the expense of independent movement/having the sound to be slightly detuned. Sometimes, you can even hide the coarse stepping in a second square voice at another interval than unison, but it is circumstantial (dependent on the harmonics of the tone, i presume).

_________________
http://www.frankengraphics.com - personal NES blog


Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 9:05 am 
Offline
User avatar

Joined: Mon Apr 04, 2011 11:49 am
Posts: 1917
Location: WhereverIparkIt, USA
uXe wrote:
Was just going on lidnariq's numbers from earlier in this thread:
313K assumes the APU channels have a max volume of 300mV. Take it for what it's worth, but based on my testing a single APU square @ max volume is more like 150-200mV. 300-350mV is both squares summed, I'm guessing that is what your and lidnariq's tests were measuring.

Quote:
My problem is that I would not be using a DAC with amplitude settings, and be able to just reduce the signal down that way. I'm looking at a PWM pin on an 8-bit AVR, or likely just software PWM on a digital pin, so it's either on or off, 0 or 5V, full stop.
Oh my bad, I read too far into your statement, I thought you were implementing a PWM DAC too. Your single square channel with invariable volume will be pretty limited.. Why not add a cap to your resistor to unlock your 8bit AVR's PWM DAC ability.? Give yourself ability to adjust the channel's volume, even allows multiple channels of varying shape if you want to get fancy. Obviously up to you, but just wanted to make sure you were aware of how simple a PWM DAC is to implement on a 8bit mcu. Open music labs has a pretty good article that showed me the light, along with an arduino sketch tutorial.

FrankenGraphics wrote:
The max volume of the APU squares aren't very useful, IMO. There's many times i've wished for an "x.5" setting but i've never felt the need for maxing the squares. Rather, i avoid it.
As always, thanks for the insight, these are the types of things I don't have a good sense for.

_________________
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers


Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 10:14 am 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6437
Location: UK (temporarily)
infiniteneslives wrote:
313K assumes the APU channels have a max volume of 300mV. Take it for what it's worth, but based on my testing a single APU square @ max volume is more like 150-200mV. 300-350mV is both squares summed, I'm guessing that is what your and lidnariq's tests were measuring.
Exactly.

If the OEM pulse channels are 150mV each into 20kΩ, then that's 7.5µA at max; 5V and 7.5µA is 670kΩ. To match the NES's built-in 20kΩ and the typical 47kΩ added, I'd assume you'd want a ≈600kΩ resistor out of the PWM DAC ... if it's still only one channel being mixed in.

Personally, I'd be tempted to mix multiple channels.

uXe wrote:
My problem is that I would not be using a DAC with amplitude settings, and be able to just reduce the signal down that way. I'm looking at a PWM pin on an 8-bit AVR, or likely just software PWM on a digital pin, so it's either on or off, 0 or 5V, full stop.
It's completely ridiculous, but you could add an external resistor DAC to add volume control without having to manage the IRQs from a PWM DAC.

Something like:
Code:
 PWM ---R---+
 PA0 ---R---+
 PA1 --2R---+
 PA2 --4R---+
 PA3 --8R---+---500k---expansion port


And you could then toggle bits in DDRA to adjust the volume.


I say "ridiculous" because in practice, your microcontroller is probably not too busy to manage updating the PWM value to serve as a DAC.


FrankenGraphics wrote:
The max volume of the APU squares aren't very useful, IMO. There's many times i've wished for an "x.5" setting but i've never felt the need for maxing the squares. Rather, i avoid it.
In thinking about this, it occurs to me that we could sink current out of the mixing node to add software-controlled master volume control.

If we had something like this:
Code:
                              ||
                   +--- expansion port --- 20k --- mixing node
                  /           ||
 PWM ---R-+-+---|< npn        ||
          | |     \           ||
          R C      |          ||
          | |      |          ||
          +-+------+--gnd     ||
although it might be more useful to pull the mixing node up to 5V (instead of pulling it down to ground as in this schematic) for greater dynamic range.


Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 11:05 am 
Offline
Formerly WheelInventor

Joined: Thu Apr 14, 2016 2:55 am
Posts: 1009
Location: Gothenburg, Sweden
lidnariq wrote:
master volume control

:shock: Sounds like it could be useful for:
-fade in/out
-half-mute (for example in a menu).
-tri envelope when playing solo
-super-exponential decays/swells of squares/noise/samples playing solo or with shared rythm
-maybe even improved dynamic range and/or fizz reduction of samples

Quote:
to pull the mixing node up to 5V.


For one thing, many studio synthesizers use a swing of 5v or even greater for audio prior to the output stage - this to keep the noise floor down relative to the signal on analog audio lines. This becomes increasingly important when mixing a large number of signals; effectively raising the noise floor.

Consumer-grade outputs however have a nominal swing of 0.447V peak-to-peak using a single sine, or more importantly 0.316V root mean square (pretty close to the NES?)

Studio equipment should have a nominal output of 1.228Vrms.

I think Sunsoft 5B audio breaks the consumer-grade nominal levels by quite a bit. It has one benefit, though:
using its coarse, loud squares as the reference point, it'll relatively push the full APU dynamic range into useful range and make its steps seem finer by comparison. Use Sunsoft for quick and loud envelopes, and the APU's for "quiet" and more nuanced/slow ones. This has the unfortunate side effect of the hypothetical game/music becoming the loudest in the nes library and will see users reaching for the volume control of their tv/speakers/laptop, but fwiw it almost works like having a finer envelope range.

Then the sunsoft synth has that 5-bit internal hardware envelope to mitigate its coarseness, but no game has ever used it...

_________________
http://www.frankengraphics.com - personal NES blog


Last edited by FrankenGraphics on Sun Oct 08, 2017 11:12 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 11:12 am 
Offline
User avatar

Joined: Mon Apr 04, 2011 11:49 am
Posts: 1917
Location: WhereverIparkIt, USA
lidnariq wrote:
we could sink current out of the mixing node to add software-controlled master volume control.

If we had something like this:
Code:
                              ||
                   +--- expansion port --- 20k --- mixing node
                  /           ||
 PWM ---R-+-+---|< npn        ||
          | |     \           ||
          R C      |          ||
          | |      |          ||
          +-+------+--gnd     ||


This ability would be significantly more limited if operating with the assumption of a fixed 47k EXP port audio mod right? Gives more reason to include the pot in my EXP port dongle..

I'm a little confused how one would integrate expansion audio channels and master volume at the same time in terms of the PWM DAC's output level calculation.

_________________
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers


Top
 Profile  
 
PostPosted: Sun Oct 08, 2017 12:17 pm 
Offline

Joined: Sun Apr 13, 2008 11:12 am
Posts: 6437
Location: UK (temporarily)
Rather than BJT tomfoolery, it's probably better to just pretend we're going to use a digitally controlled potentiometer. Then it's a lot easier to see what's going on:

Code:
pin1 -- 20k --+
pin2 -- 12k --+-- 1uf -- rest of audio hardware
              |
    +-- 20k --+
    |
   pot
    |
   gnd


Quickly playing around with falstad's circuit simulator, assuming pin1 is a 150mV(max) square wave and pin2 is just 100Ω to ground, adjusting the pot between 0 and ∞ yields 41mVpp to 56mVpp ... that's not very good, only a couple dB

That 20k resistor is a pain.

Fine, so we add a negative impedance converter to undo the 20k that we can't get rid of. It'll require that we synthesize a negative voltage, but this already crazy analogland, so whatever.

And, yup: that lets us get an arbitrary volume attenuation. Synthesizing a different regulated choice of "ground" for the NIC other than 0V should make it possible to not need sophisticated power circuitry to create a negative voltage:

Code:
pin1 -- 20k --+
pin2 -- 12k --+-- 1uf -- rest of audio hardware
              |
    +-- 20k --+
    |
    +-- pot --+
    |         |
    |  |\     |
    +--|+ \   |
       |    >-+
    +--|- /   |
    |  |/     |
    |         |
    +-- 10k --+
    |
    +-- 10k -- Vreg
A 20k pot here would become a -20k pot. When set to -20k, we've magically made a 0 ohm resistor and attenuation is ≈infinite. When set to 0, it's only 3dB (20·log10(56÷41)) quieter than without this add-on hardware.


Quote:
I'm a little confused how one would integrate expansion audio channels and master volume at the same time in terms of the PWM DAC's output level calculation.
The math becomes gross but it should still be doable. An electrically super simple and lazy option would be to replace Vreg with the external mixed in audio signal, but the mixing equation becomes a little weird.



If we're going to be even more completely ridiculous, a NIC allows us to multiply the complex reactances of three different passives. By changing some of them to have some imaginary component (e.g. a capacitor or inductor) we can instead have a programmatically controlled high-/low- pass audio filter.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 25 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group