<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Thank you very much for that, David.<div class=""><br class=""></div><div class="">Not only is that a fantastic way to visualise what's going on and the difference between these different techniques (vastly different as your images show - and also why staying away from the last few percent top and bottom helps quite a lot, as I mentioned), but it also gave me one of those "AHA!" moments about other NCO things that I've been muling over for a long time. I hadn't thought of laying it out in the way you've done, but that makes everything far clearer, so thank you for that too!</div><div class=""><br class=""></div><div class="">Tom</div><div class=""><br class=""><div class=""><div class="">
<div>==================<br class="">       Electric Druid<br class="">Synth & Stompbox DIY<br class="">==================</div><div class=""><br class=""></div><br class="Apple-interchange-newline">

</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On 10 Dec 2023, at 19:36, David Kantowitz <<a href="mailto:dkantowitz@gmail.com" class="">dkantowitz@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">The carry-bit NCO technique is also equivalent to a 1-bit first order sigma delta DAC.  Probably doesn't make it much easier to understand, but it does make the design conclusions from sigma delta usable.  Ex. noise shaping curves, required Over Sampling Rates vs ENOB, reconstruction filtering (see: <a href="https://en.wikipedia.org/wiki/Delta-sigma_modulation" class="">https://en.wikipedia.org/wiki/Delta-sigma_modulation</a>).<div class=""><br class=""></div><div class="">To help myself visualize this, I plotted the output bit patterns for each input level.  Both modulation algorithms (1-bit carry NCO and SD-1) produced the same chart.</div><div class=""><br class=""></div><div class="">DC level is y-axis, time is x-axis.</div><div class=""><span id="cid:ii_lpzvn1o40"><image.png></span><br class=""></div><div class="">Repeated 4 times to help imagine the oversampling:</div><div class=""><span id="cid:ii_lpzvncti1"><image.png></span><br class=""></div><div class=""><br class=""></div><div class="">For comparison basic PWM looks like:</div><div class=""><span id="cid:ii_lpzvp9sz2"><image.png></span><br class=""></div><div class=""><br class=""></div><div class="">By looking across a horizontal line, you can easily see the carry-bit approach has a vast reduction in low frequency content compared to PWM.  That is, the digital signal 'noise' is being pushed into higher frequencies.  However, there's still plenty of repeating pattern in the NCO/SD-1 </div><div class=""><br class=""></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 8, 2023 at 1:43 PM Tom Wiltshire <<a href="mailto:tom@electricdruid.net" class="">tom@electricdruid.net</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Honestly, it's not. It's just that damn simple. The version I actually wrote was all hardware module set-up specific to the device, and basically nothing else, so wouldn't tell you anything. Turning it all into software loses a lot of the benefit, so doesn't make much sense, except to explain it.<br class="">
<br class="">
Play with some NCOs a bit, and then get them to make a single pulse when they wrap. And then - Bingo! You're there!<br class="">
<br class="">
If you thought something was missing, what exactly? Ask a more specific question and perhaps I can help fill in a blank. I well remember how weird this stuff seemed when I first met it, so I think I understand the position you're in now.<br class="">
<br class="">
<br class="">
> On 8 Dec 2023, at 21:18, cheater cheater <<a href="mailto:cheater00social@gmail.com" target="_blank" class="">cheater00social@gmail.com</a>> wrote:<br class="">
> <br class="">
> I don't get it. Most of the algorithm is missing.<br class="">
> <br class="">
> On Fri, Dec 8, 2023 at 10:07 PM Tom Wiltshire <<a href="mailto:tom@electricdruid.net" target="_blank" class="">tom@electricdruid.net</a>> wrote:<br class="">
>> <br class="">
>> <br class="">
>> <br class="">
>> On 8 Dec 2023, at 20:30, cheater cheater <<a href="mailto:cheater00social@gmail.com" target="_blank" class="">cheater00social@gmail.com</a>> wrote:<br class="">
>> <br class="">
>> On Fri, Dec 8, 2023 at 5:06 PM Tom Wiltshire <<a href="mailto:tom@electricdruid.net" target="_blank" class="">tom@electricdruid.net</a>> wrote:<br class="">
>> <br class="">
>> <br class="">
>> <br class="">
>> <br class="">
>> On 8 Dec 2023, at 14:41, Matthew Skala via Synth-diy <<a href="mailto:synth-diy@synth-diy.org" target="_blank" class="">synth-diy@synth-diy.org</a>> wrote:<br class="">
>> <br class="">
>> If PDM means PWM with bit-reversal before the comparison (such as Richie<br class="">
>> describes), then it does indeed lock you into a lower sampling rate, and<br class="">
>> that's one reason I skipped describing *that* technique.  But PWM with<br class="">
>> bit-reversal seems not to be what you mean when you say PDM.<br class="">
>> <br class="">
>> <br class="">
>> That's not what I meant when I said PDM, certainly.<br class="">
>> <br class="">
>> The way I generated it is using an NCO. The NCO generates a single-shot output pulse everytime the phase accumulator wraps.<br class="">
>> <br class="">
>> Now consider what happens with a simple 8-bit NCO. If our frequency increment is 2, for example, we get a single output pulse every 128 clocks, or 2 pulses per 256 clocks. Notice that they will be nicely spaced apart, not next to each other like PWM. The output frequency would be (clock frequency / 128) in this situation.<br class="">
>> If the increment is 8, we get a output pulse every 32 clocks, 8 pulses per 256 clocks, and again, they're nicely spaced out. The output frequency is now up to (clock /32) so there's been a big improvement, just by getting away from those extreme values a little bit.<br class="">
>> As the increment climbs, the accumulator wraps more and more often. At freq=128, every other clock is an output and we reach our maximum output frequency of (clock/2). As the increment goes above half, we start staying high for more than a single pulse, and the waveform effectively turns the other way up and we get a mirror image of the effect we've seen from 0-128.<br class="">
>> <br class="">
>> HTH,<br class="">
>> Tom<br class="">
>> <br class="">
>> <br class="">
>> I've read this a few times but I'm struggling to understand what's<br class="">
>> going on. Can someone type out an algorithm or something like that?<br class="">
>> Would appreciate it a lot. Thanks.<br class="">
>> <br class="">
>> <br class="">
>> Ok, it'd look something like this:<br class="">
>> <br class="">
>> phase: 16-bit variable (for example)<br class="">
>> freq: 16-bit variable (same as phase)<br class="">
>> <br class="">
>> So we do:<br class="">
>> <br class="">
>> // Increment phase accumulator<br class="">
>> phase = phase + freq<br class="">
>> <br class="">
>> // Did phase wraparound?<br class="">
>> If (phase>65535) { // There are probably better ways to do this test, if it's even required.<br class="">
>> // Ok, phase wrapped<br class="">
>> phase = phase % 65536<br class="">
>> // output a pulse a single clock in length<br class="">
>> <this is implementation dependent!><br class="">
>> }<br class="">
>> <br class="">
>> All you need to do is run this code at a fast clock rate and you're off. Of course, the better way is if you can hand some of this overhead to hardware, and some modern uPs include NCOs as a peripheral and can be set up for this "single shot pulse output" mode, which means that the while thing boils down to simply updating the "freq" frequency increment variable with your current output. It's dead simple.<br class="">
>> <br class="">
>> <br class="">
>> There's a page about NCOs in general on my website:<br class="">
>> <br class="">
>> <a href="https://electricdruid.net/direct-digital-synthesis/" rel="noreferrer" target="_blank" class="">https://electricdruid.net/direct-digital-synthesis/</a><br class="">
>> <br class="">
>> HTH,<br class="">
>> Tom<br class="">
>> <br class="">
>> <br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
Synth-diy mailing list<br class="">
<a href="mailto:Synth-diy@synth-diy.org" target="_blank" class="">Synth-diy@synth-diy.org</a><br class="">
<a href="http://synth-diy.org/mailman/listinfo/synth-diy" rel="noreferrer" target="_blank" class="">http://synth-diy.org/mailman/listinfo/synth-diy</a><br class="">
Selling or trading? Use <a href="mailto:marketplace@synth-diy.org" target="_blank" class="">marketplace@synth-diy.org</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></body></html>