Access All 16 Analog Channels

The Arduino Due features 12 analog ADC, however the AT91SAM3X8E chip has 16 analog pins.

Is it possible to access the 4 omitted ADCs from the Due headers and program them in the IDE? Thank you.

In typical Atmel marketing-BS the SAM only has 15 usable ADC inputs because the 16th is dedicated to the internal temp sensor.

AD0:7 and AD10:13 are the official analogue inputs.

Here is a list of the non-official ADC inputs

AD8 - PB12 - SDA - D20
AD9 - PB13 - SCL - D21
AD14 - PB21 - D52
AD15 - internal temp

So you can get access to them (except AD15) but bear in mind that D20 and D21 have pullup resistors for the I2C.


Rob

Thanks for the response.

Are the I2C pull-ups on the Due board or the chip? If on the chip, can they be disabled to make a proper ADC channel?

The resistors are on the board, you would have to physically remove them. Alternatively drive the inputs with a low-impedance source like an opamp, I doubt that would be affected by the 1k5 resistor.


Rob

AD15 - internal temp

So you can get access to them (except AD15) but bear in mind that D20 and D21 have pullup resistors for the I2C.

That AD15, can it be used to collect entropy to seed the random generator?

investigated something similar for the UNO long ago - http://forum.arduino.cc/index.php/topic,38091.0.html - but it was not noisy enough. Maybe the Due is?

I don't know if this helps, but the Due's processor has a "True Random Number Generator" built into it. Chapter 43 of the SAM3X manual discusses it: Smart | Connected | Secure | Microchip Technology. I'm not really knowledgable about how good the various randomness specs are, but the manual claims the SAM3X's generator passes the NIST Special Publication 800-22 and the Diehard Random test suites.

I stumbled across that chapter while reading about the timer counters and USARTs in the microcontroller.

  • Madeline

Thanks Madeline,

Didn’t find time to read much about the Due so I’m a noob on that board/processor.

The control register has a 24 bit key - do you know if it works as a seed?

robtillaart:
[…] The control register has a 24 bit key - do you know if it works as a seed?

That key is actually just for write-protecting the register. Many of the SAM3X8E’s built-in peripherals require a security key (to protect against run-away code overwriting the registers?). With the Timer Counters, for example, one of the peripheral’s registers is the Write Protect Mode Register. You need to write the security key to that register before you can write to most of the other registers in that peripheral.

The True Random Number Generator has so few registers that, rather than having a separate one for controlling the write-protection, they combined the security key and the bit for enabling the TRNG in the Control Register. For the TRNG, the key is always 0x524E47 (which is “RNG” if viewed as ASCII characters). So, to enable the TRNG you write 0x524E4701 to that register, and to disable it, you write 0x524E4700.

Hope that helps!

  • Madeline

Madeline:

robtillaart:
[...] The control register has a 24 bit key - do you know if it works as a seed?

That key is actually just for write-protecting the register. Many of the SAM3X8E's built-in peripherals require a security key (to protect against run-away code overwriting the registers?). With the Timer Counters, for example, one of the peripheral's registers is the Write Protect Mode Register. You need to write the security key to that register before you can write to most of the other registers in that peripheral.

The True Random Number Generator has so few registers that, rather than having a separate one for controlling the write-protection, they combined the security key and the bit for enabling the TRNG in the Control Register. For the TRNG, the key is always 0x524E47 (which is "RNG" if viewed as ASCII characters). So, to enable the TRNG you write 0x524E4701 to that register, and to disable it, you write 0x524E4700.

Hope that helps!

  • Madeline

To generate TNRG you can use this: is somewhere from this forum I can't remeber at this time.

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(trueRandom());
  delay(500);
}

uint32_t trueRandom() {
    static bool enabled = false;
    if (!enabled) {
        pmc_enable_periph_clk(ID_TRNG);
        TRNG->TRNG_IDR = TRNG_IDR_DATRDY;
        TRNG->TRNG_CR = TRNG_CR_KEY(0x524e47) | TRNG_CR_ENABLE;
        enabled = true;
    }

    while (! (TRNG->TRNG_ISR & TRNG_ISR_DATRDY));
    return TRNG->TRNG_ODATA;
}