Background
I wanted to make a simple function generator with an ATmega328 and an R2R resistor network, similar to Jesper Hansen's Mini DDS (Direct Digital Synthesis).
To make the function generation firmware run fast enough, I believe I have to wire an entire PORT (all of its 8 output pins) on the ATmega328 to the R2R resistor network. This way I can write one full byte to the port with a single command, like so:
PORTD = B10101000;
On the ATmega328, I think PORT D is the only port I can use like that. ATmega328 pinout and port distribution is below.
The Problem
The problem I'm facing is that I also want to use the ATmega328 serial port for programming the board, but the serial port is also on PORT D (pins PD0 and PD1), thus creating a conflict.
Proposed Solution
After some research, I've decided that I could get away with the design below. The relevant part is circled in green.
With that circuit I think I'll be able to use the serial pins for programming the board and also, but not at the same time, drive the R2R network to produce a sine wave.
Considerations
The considerations I gathered so far, including contributions from comments, are the following:
R17 is required to protect whatever is connected to the RX line (e.g. MAX232 IC) when ATmega pin 2 is changed to an output to drive the R2R network. That will prevent a large current from being sourced by the MAX232 IC when the pin is driven low.
R17 value (1kΩ) will slow down RX line a bit (increase rise and fall times), but according to what I understood from this answer by Leon Heller - Resistors in series with Tx and Rx, it won't be enough to prevent serial communication (pending experiments to prove it).
I won't be able to use both functions at the same time, but that's ok, as I plan to switch between functions in the firmware.
RX and TX lines are linked to each other by a 50kΩ equivalent resistance, by R1, R2 and R3. That will create a 0.1mA current in and out of each pin, when they show different logic levels. I think that won't be a problem, but further experiments are required.
Questions
My questions are:
- Will my circuit work? If not, why not?
- Will this circuit burn or stress my ATmega or whatever I connect to the serial connector?
- Is there a better way to do it using an ATmega328 and the R2R network?
I know there are a lot of ADC chips out there that would help me solve this problem easily and would make my miniDDS more precise, but I wanted to start out with these requirements.