Go Down

Topic: Arduino DUE ADC to DAC Piezo 30 Khz-100Khz (Read 926 times) previous topic - next topic


Jul 06, 2017, 11:03 am Last Edit: Jul 06, 2017, 03:47 pm by miaz
I am working on project for providing Echo response to ultrasonic sensors. Piezo facing opposite to an ultrasonic sensor,with foam material in between to damp the ultrasonic signal reflecting back to sensor.

Event based,Read the piezo signal[(+) --> A0,(-) --> GND on Arduino Due] and after a delay(5 ms) drive the same piezo through DAC0 [(+)---> DAC0,(-)--> GND)

So that Ultrasonic sensor receives the signal (30 KHz-100 kHz) after a delay,thereby calculating distance after Time of Flight of 5 ms.

int in_ADC0,out_DAC0;  //variables for ADC,DAC values (ADC0, DAC0)

void setup()
  //ADC Configuration
  ADC->ADC_MR |= 0x80;   // DAC in free running mode.
  ADC->ADC_CR=2;         // Starts ADC conversion.
  ADC->ADC_CHER=0x80;  // Enable ADC channels 0   
  //DAC Configuration
  analogWrite(DAC0,0);  // Enables DAC0
void loop()
  //Read the ADCs
  while((ADC->ADC_ISR & 0x80)!=0x80);// wait for ADC0 conversion complete.
  in_ADC0=ADC->ADC_CDR[7];               // read data from ADC0
  //map(x,a,b,c,d)  -->an example  ...= map(val,0,1024,0,100);
  //Write the DACs
  dacc_set_channel_selection(DACC_INTERFACE, 0);       //select DAC channel 0
  dacc_write_conversion_data(DACC_INTERFACE, out_DAC0);//write on DAC

But am unable to receive the same,Can anyone help me out where am I going wrong?


The problem is that you are mixing direct register access (BTW don't use magic numbers), arduino specific language (analogRead(), analogWrite()), and Libsam/ASF functions (dacc_set_channel_selection(),dacc_write_conversion_data()).

Once a setup is done via direct registers access for ADC, if you use analogRead() there is a good chance that your previous code will be scratched.

I suggest that you read sections 43 (ADC controller) and 44 (DAC controller) and use only a direct register programming.

And use code tags to show your code (</>)

Go Up