1 (edited by PROTODOME 2016-01-08 22:55:20)

Topic: Combining Software Channels to Single Hardware Pin Output

Firstly, hey 1-bit music forum. First post, long-time lurker.

Okay, so I'm trying to combine a bunch of software timers, generating variable width pulse functions, into a single output pin. I've posted the topic here because I'm currently using an ATMega128, but the question's probably hardware agnostic.

I can easily bit bang multiple pins and combine the output electronically (in the subsequent analog domain), just, it's a bit inelegant and I'm stumped as to combining them in software (without using PWM to emulate an analog waveform, which is cheating). The problem is, when I get multiple channels to flip the pin, I usually get a resultant single pitch with unwanted duty cycle modulation, which sounds cool but not really what I'm after. This is minimised with simple frequency ratios such as 2:1 or 3:2, but even 5:4 or 6:5 will fail to create polyphony.

How is this done on other 1bit platforms? Is there a solution? I personally cannot see how discrete pitches can be preserved when each interacts with the other, especially when I only have two states. The vital high-time of one wave is flipped to low for another, affecting the perceived pitch. I also have no idea how pulse and noise could be run simultaneously on a single pin without only noise audible.

Would XORing the channels help? Perhaps using pin pulse modulation to minimise duty cycle interaction?

Any thoughts would be much appreciated.

Re: Combining Software Channels to Single Hardware Pin Output

The mighty Protodome! Welcome to the board smile

Atmega is a very nice chip, and it's certainly capable of outputting polyphony on a single pin. Provided you're willing to program it in assembly, that is. A pin pulse routine might even be feasible in C, but I think what you'd rather want is a tight, timing-stable loop that alternates between the various software outputs (aka Pulse Interleaving). I suppose you have read the tutorial thread? That contains pretty much most of the known tricks, and should be applicable to Atmega as well.

If not, please specify a bit more what you want to do, I'm sure we can work something out smile

Re: Combining Software Channels to Single Hardware Pin Output

I GET IT. Spent some quality time deciphering your tutorial (not ASM fluent, even with the pseudo-code it took time). I got PFM working pretty easily, but it was only when I stumbled upon something you'd said on worldofspectrum.org that pulse interleaving finally clicked:

utz wrote:

What you do is alternate the outputs of ch1 and ch2 quickly, about every 20 ms or so.

THAT'S how you avoid interaction between the waveforms. It's so bloody simple (but brilliant), I'd been completely overcomplicating it.

Thanks for pointing me in the right direction. Going to try and implement some of your other tricks now. ;D

Re: Combining Software Channels to Single Hardware Pin Output

Ah, glad you were able to work it out. Once you get over the initial hurdle, it's indeed pretty simple wink Most of the trickery is getting your routines up to speed and getting the timing stable, but that should be less of an issue with ATmega. Anyway, keep us updated about your project, will ya?

5 (edited by garvalf 2016-01-15 15:49:21)

Re: Combining Software Channels to Single Hardware Pin Output

I have some Arduino at home, I'd be interested to make 1bit music with them... so please tell us more about what you can do with this...

6 (edited by PROTODOME 2016-01-16 00:35:07)

Re: Combining Software Channels to Single Hardware Pin Output

Yeah sure, if it'll help anyone I'll post some code at some point. It's nothing fancy whatsoever, just wrapping my head around the usual tricks in a relatively simple environment. (Cheers utz for the incredible documentation.)