Pages: [1]   Go Down
Author Topic: Analog-to-digital converter in Due  (Read 1189 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,


* Frequency_5Hz.png (53.55 KB, 1360x577 - viewed 55 times.)

* Frequency_50Hz.png (61.74 KB, 1360x577 - viewed 52 times.)
Logged

Brazil
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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. 
Logged

Ottawa,Canada
Offline Offline
Jr. Member
**
Karma: 0
Posts: 82
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset





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,
« Last Edit: November 09, 2013, 02:32:59 pm by m_lab85 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Best Wishes,

M,
« Last Edit: November 10, 2013, 02:56:44 pm by m_lab85 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try to add in setup code next line
Code:
REG_ADC_MR = (REG_ADC_MR & 0xFFF0FFFF) | 0x00020000;
this will make ADC much faster

and this function
Code:
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:
digitalWriteDirect(OutPin,a);
makes digitalwrite muuuuch faster
« Last Edit: November 18, 2013, 03:19:11 am by kortium » Logged

Pages: [1]   Go Up
Jump to: