FIRST POST-UNDERSTANDING WHICH OUTS FOR AN R2R

Hey there

This is my first post on this great forum! I have been reading up on Arduino and C for a week or so now and I am starting to think I can maybe do some interesting things with this platform. BUT I have so many questions.

For now the biggest involves sound.

Let's say there is a program that I want to use, but it is set up to output its sound through the PWM pins.
However, I would like to use the proper pins for a resistor ladder (R2R) DAC.

I am under the impression that I am supposed to use the DIGITAL pins. But it seems like most audio related things in Arduino are setup to
use the PWM pins. Is it possible to start a sketch using the PWM Pins for testing and then move its output to the digital pins for R2R?

Eventually I would like to read an input, perform operations on it, and then get it to come out of the DIGITAL OUTS.

it all seems so confusing. but the DIGITAL OUTS seem like the best way to get around 256 steps.

( a big specific goal would be to have a wave table oscillator take advantage of the DIGITAL PINS)

thanks so much for any answers or links or books , etc. I will read all of it!!

I would like to use the proper pins for a resistor ladder (R2R) DAC

You can use any pins for an R2R, just choose those not used for PWM. BTW that includes the analogue pins, you can use them for digital.

Is it possible to start a sketch using the PWM Pins for testing and then move its output to the digital pins for R2R?

I don't quite get this, the R2R and PWM are totally seperate things albeit with similar outcomes. At first glance it looks like you only need PWM, what is the R2R for?


Rob

If you want to output 8 bits in parallel you will need to use 8 data pins that all belong to the same data port.

Port B:
Bit 0 -> D8
Bit 1 -> D9
Bit 2 -> D10
Bit 3 -> D11
Bit 4 -> D12
Bit 5 -> D13
Bit 6 -> Xtal1 (not available as a data pin)
Bit 7 -> Xtal2 (not available as a data pin)

Port C:
Bit 0 -> D14/A0
Bit 1 -> D15/A1
Bit 2 -> D16/A2
Bit 3 -> D17/A3
Bit 4 -> D18/A4
Bit 5 -> D19/A5
Bit 6 -> Reset (not available as a data pin)
Bit 7 -> (not available as a data pin)

Port D:
Bit 0 -> D0 (a.k.a. Receive Data)
Bit 1 -> D1 (a.k.a. Transmit Data)
Bit 2 -> D2
Bit 3 -> D3
Bit 4 -> D4
Bit 5 -> D5
Bit 6 -> D6
Bit 7 -> D7

Looks like Port D is your only choice for a full 8 bits in parallel. Using it would mean you can't use hardware Serial.

If you want more than 8 bits of output you will need to use more than one register. If you don't use all available pins of a particular register you will need to read the register, modify it (with & and | operations) and write the modified version out. That will slow your output a little bit.

You could also use SPI to shift out 16 bits to get around 256 steps.
SPI is hardware-based shiftout and can go really fast.
See section 18 of the ATMega datasheet.

Is it possible to start a sketch using the PWM Pins for testing and then move its output to the digital pins for R2R?

To correct one of your concepts, all PWM output pins ARE digital pins, It's just that not all digital pins are PWM pins, that is some digital pins don't have internal connections to the hardware timers that generate pwm pulses.

So a digital pin that supports PWM is only an active PWM if you are using analogWrite() statements in your sketch. If you change your application sketch to not use analogWrite() PWM commands, then you are free to use those pins in any manner you wish, as input pins, as general output pins.

Lefty

PS: I just recently received my 2 channel SPI 12 bit DAC module, works great and only needs 3 output pins to run.

http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&item=270632079322&ssPageName=STRK:MEWNX:IT

The arduino environment isn't well set up to output multi-bit values to a given set of pins. @JohnWasser's advice all looks good if you want to go for "direct port access", although I'll add a comment that it's "obviously" easier to do a 6-bit R2R ladder; that way you can use any of the pin groups. Whether 6 bits is enough is a separate question.