(Noob question) Analog outs?

Hi, This is probably a pretty dumb question, but why do microcontrollers never have analog outputs Thanks

You mean genuine analog? I don't know, maybe some do?

The Arduinos do have PWM which is a sort of pseudo analog, being the average of a fast-changing digital 5-0-5-0V output. The percentage on-time gives the pseudo voltage, eg a 50% on, 50% off would average out at 2.5V

PWM pins are marked ~.

Thanks for the answer! After some further researching found that some microcontrollers actually do have a DAC output.

Thanks again

I think the main reason is that almost everything is done/can be done with PWM:

  • LED brightness
  • DC motor speed
  • the dimmer for your living room lights
  • the fuel injected into your car's engine (not talking about the carburator era)
  • the temperature in your washing machine (PWM at very low speed, on and off for several minutes)

you will rarely need a "real" analog voltage output

And if you do, you can filter a PWM signal to get a nice "analog" signal.

I actually needed a nice analogue voltage and I was also thinking of filtering the PWM output, but then I found the LTC2645. It's a four channel PWM→Analogue DC voltage circuit. It calculates on- and off-times internally and internal DACs provide (hopefully) nice analogue signals. It's available with 8-, 10- and 12-bit DACs. I guess the 8-bit one would work fine with the Arduino Uno at least (I don't know much about the other Arduinos), but more bits won't hurt, I guess…

I've not tried it myself yet, though…

I think the main reason is that DAC's are far more expensive to implement than PWM - and if you think about common use cases, PWM is typically more useful. Moreover, the same hardware used for PWM (hardware timers) are also useful for other things as well, if you're not PWMing with them

You typically can't, say, dim an LED with a DAC (not enough current output), and if you're controlling a larger fet, you also need to use PWM.

So it costs more and is less useful - it's hardly surprising that they're not a common feature!

The most common use case for a DAC is probably audio (which is why DACs often come in pairs - for stereo audio) - but the AVRs don't really have the resources to do that well, which is probably why they don't have DACs.