Go Down

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

m_lab85

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,

zeluiz

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. 

ralphnev

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

m_lab85

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




Quote
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,

m_lab85

#4
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,

M,

kortium

#5
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]
digitalWriteDirect(OutPin,a);
makes digitalwrite muuuuch faster

Go Up