best solution for 12 analog outputs (5 bits)

BenF:

Oldchatterman:

BenF:
Using a 16MHz mcu and bit-bang PWM at 20kHz, you would have 400 instructions available for each interrupt cycle (16e6 / 40e3). This may be achievable (not using the Arduino core), but it doesn't leave you with much for anything else. Direct port IO is 8 bit wide and requires two instructions only. Interrupt overhead is about 50 instructions.

You must help me with this calculation: 16e6/40e3 -> where is the 40e3 coming from.

For 20kHz PWM, you need a 40kHz interrupt (two half periods is one cycle). You will need to pre-compute the PWM patterns outside of the interrupt loop so all you need is a simple lookup of two bytes inside the timer interrupt handler. This will give you max 16 PWM channels (8 per byte). This is tricky code to write, but as I said it may be achievable with good coding skills.

Ok, thanks. I am just a beginner and this area is not my daily business, so I doubt that I have the required coding skills.