Go Down

Topic: Analog-to-digital converter in Due (Read 1 time) previous topic - next topic


i wrote a code to convert an analog signal to digital  on Due. the results ,i am getting on the oscilloscope, of the ADC  as shown in Frequency_5Hz (attached) for analog square wave = 1v at the pin( A1). fre = 5Hz. 
and by increasing the frequency to 50Hz  at scope Frequency_50Hz, the ADC seems like it can't catch up with the input signal.
the code i wrote is:
const int InputPin = A1;
const int OutPin = 28;

void setup()
  analogReadResolution(12); // 12-bit!
  Serial. begin(9600);
void loop() {

  int a;

  analogReadResolution(12); // 12-bit!
a = analogRead(InputPin);

a confusing point is that in Frequency_5Hz i can see that ADC is responding but not correctly. i think that i should see a series of binaries not a plus looks similar to the input signal.

could anyone tell me why i am getting this

Best Wishes,



I've already experimented it.  I supose the ADC is not fast enough to do it because  it´s a hardware problem. In order to solve it you problaby should select a faster microcontroler family. 


the adc dac are both fast enough
take the print statement out the loop


Nov 09, 2013, 08:28 pm Last Edit: Nov 09, 2013, 08:32 pm by m_lab85 Reason: 1

the adc dac are both fast enough
take the print statement out the loop

i've tried that, but there was no change occur on the output




Nov 09, 2013, 08:34 pm Last Edit: Nov 10, 2013, 08:56 pm by m_lab85 Reason: 1
guys do you know if there is a testing code for ADC to Due.

Best Wishes,



Nov 18, 2013, 09:15 am Last Edit: Nov 18, 2013, 09:19 am by kortium Reason: 1
try to add in setup code next line
Code: [Select]
REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000;
this will make ADC much faster

and this function
Code: [Select]
inline void digitalWriteDirect(int pin, boolean val)  //fast writing to pin
 if(val) g_APinDescription[pin].pPort -> PIO_SODR = g_APinDescription[pin].ulPin;
 else    g_APinDescription[pin].pPort -> PIO_CODR = g_APinDescription[pin].ulPin;

and use it like
Code: [Select]
makes digitalwrite muuuuch faster

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131