Arduino Due - using built in ADC as a DSO causes issues at high frequencies (kHz

I am trying to use the inbuilt ADC of the Arduino Due to measure voltage signals. The frequency range I’m interested in measuring is up to about 30 kHz.But I’m observing a strong capacitor behaviour as I increase the frequency ( from 10kHz onwards this is quite visible).

This is most visible when measuring a square wave. When I get close to 30 kHz the signal looks exactly like the text book capacitor charge/discharge wave and nothing like a square wave. Even at around 15 kHz, the square wave looks more like a sine wave/ ramp signal than a square wave.

Based on the behaviour my guess is that a capacitor in the Arduino Due ADC is causing this (as the frequency increases, the capacitor cannot charge/discharge fast enough). But I’m not sure whether I’m correct about this. Even if I’m correct, how can I fix this?

Any help would be much appreciated.

Thanks.

This is how the 30kHz square wave looks like.

Screen Shot 2016-08-02 at 4.31.46 pm.png

Show us your circuit.