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
analogReadResolution(12);
analogWriteResolution(12);
//DAC Configuration
analogWrite(DAC0,0); // Enables DAC0
Serial.begin(9600);
}
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
out_DAC0=map(in_ADC0,0,4095,695,3425);//4095(0.56,2.76)
//map(x,a,b,c,d) -->an example ...= map(val,0,1024,0,100);
delay(5);
//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
Serial.println(out_DAC0);
}
But am unable to receive the same,Can anyone help me out where am I going wrong?