AVR Dx Idiosyncrasies

I really like the new AVR-DA, AVR-DB, AVR-DD series of microcontrollers from Microchip. They are like 3rd generation versions of the ATMEGA328P found in the original Arduino, but have more RAM, more Flash, more/better peripherals, and costs less. And Spence Konde’s Dx Core makes development a breeze using the Arduino IDE.

But there are a few general idiosyncrasies with these parts that I which Microchip did a better job of highlighting to users. The ones I’ve found that have bitten me in the bottom are listed below, so that you can avoid the mistakes that I made.

Clearing Interrupt Flags

In prior generations of these AVR MCUs, the peripheral’s interrupt flag (the flag that caused the interrupt) would be automatically cleared simply by executing the relevant Interrupt Service Routine. Not so with the Dx parts. For the Dx parts the user must include code in their ISR to clear that interrupt flag. If you don’t do that, you’ll get the same interrupt again immediately upon completion of your ISR.

DAC Drive Output

The issue with DAC output is that it behaves like a voltage source (voltage determined by the data value stored in the DAC output register) that can only source current and not sink current. The AVR-DB data sheet makes this issue clear, although it’s buried in the Electrical Characteristics for the DB part (section 39.19 DAC), but the data sheets for both the DA and DD parts are silent on this issue. To demonstrate this “can only source current” issue, if you connect a 10K resistor from the DAC output to VCC, the DAC output voltage will stay stuck at VCC, regardless of the data value stored in the DAC data register, since the DAC output can’t sink current. So my standard practice is to put a 4.7K resistor from the DAC output to ground and then ensure that whatever else loads the DAC output is relatively high impedance (relative to the 4.7K pull down resistor). Alternatively, using one of the OP-AMP blocks on the MCU as a voltage follower to buffer the DAC output is a good solution, but don’t forget to include the 4.7K pull down resistor on the DAC pin.

Looking a little bit further into this issue, in the second entry of Table 39-26. DAC Electrical Specifications of the AVR128DB32 data sheet (Microchip document number DS40002247B) it says that the DAC output can source 1 mA but can only sink 1 uA (ONE MICRO-AMPERE – which is pretty much the same as ZERO). Plus there’s a footnote for this table entry that states “The DAC output has a limited current sinking capability. It is designed to drive against resistive loads connected to ground. It is recommended to increase the sinking capability by placing a suitable resistor between the DAC output pin and ground if the DAC peripheral may sink current.” By “DAC peripheral” they mean your circuit that monitors that DAC output pin.