Analog-to-digital converter in Due

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()
{
pinMode(InputPin,INPUT);
pinMode(OutPin,OUTPUT);
analogReadResolution(12); // 12-bit!
Serial. begin(9600);
}
void loop() {

int a;

analogReadResolution(12); // 12-bit!
a = analogRead(InputPin);
digitalWrite(OutPin,a);
Serial.println(a);
while(0){
}
}

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,

M,

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

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

regards,

M,

guys do you know if there is a testing code for ADC to Due.

Best Wishes,

M,

try to add in setup code next line

REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000;

this will make ADC much faster

and this function

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

digitalWriteDirect(OutPin,a);

makes digitalwrite muuuuch faster