# generating audio with 14bit data on dual PWM channels with 7 bits per channel.

I'd like to use 14-bit phase corrected PWM to generate some audio from stored tables. I understand I can use two PWM channels with some external resistors to add them together to produce a higher bit depth signal. If it were two 8 bit channels to give me 16 bit audio that would be easy since sending the high 8 bits of the int to the High channel and the low 8 bits to the Low channel.

Where I'm stumped is how to split it up for anything else. I'm interested in 14 bit audio divided into two 7 bit channels. if I start with a int and limit it to 16383 how do I split that between two 7 bit channels. 16383 is 14 one bits so I'll put them in two PWM registers do they go 01111111 01111111 or 01111111 11111110, or 00111111 11111111 (straight move) a straight move doesn't seem to work. I've been playing around with it and the sine wave is very jittery which means I'm not splitting the data properly Since I'm generating the tables if I need to move the bits around in the int to allow me to do straight moves into the registers that would make things less complicated and hopefully run faster.

I understand I can use two PWM channels with some external resistors to add them together to produce a higher bit depth signal

Only if you have very tight tolerance resistors which you can not buy.

The int splitting is the very easy part

``````int sample;
lowerBits = sample & 0x7F;
upperBits = ( sample >> 7) & 0x7F;
``````

many thanks on the code. I was overthinking it. My problem looks like I was limiting the data to 14 bits but not arranging it in the table so it would feed in directly.

I do have 1% resistors that I bought online. I got 20 of each value and will choose the ones that closest fit ideal. These are axial leads for my testing. I have some surface mount with a little better precision for my next step in development.