Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PingDetect/PingDetect.cpp
- Committer:
- tummastt
- Date:
- 2012-08-21
- Revision:
- 1:227db871d328
- Parent:
- 0:efb27fbc92c0
File content as of revision 1:227db871d328:
/*
Program to control the system.
*/
#include "PingDetect.h"
#define ClearBuffer LPC_UART0->FCR | 0x06
int PingDetect::Search() {
// pc.printf("s\n\r");
for (i=0; i<SAMPLES; i++) {
//Measure pin 19
adc.select(p19);
//Start ADC conversion
adc.start();
//Wait for it to complete
while (!adc.done(p19));
//Measure pin 20
adc.select(p20);
//Start ADC conversion
adc.start();
//Wait for it to complete
while (!adc.done(p20));
DataFront[i] = adc.read(p19);
DataBack[i] = adc.read(p20);
}
if (fft.DetectSignal(DataFront) == found) {
return found;
} else {
return notFound;
}
}
void PingDetect::Run() {
// if (no <10) {
for (i=0; i<noOfSamples; i++) {
//Measure pin 19
adc.select(p19);
//Start ADC conversion
adc.start();
//Wait for it to complete
while (!adc.done(p19));
//Measure pin 20
adc.select(p20);
//Start ADC conversion
adc.start();
//Wait for it to complete
while (!adc.done(p20));
DataFront[i] = adc.read(p19);
DataBack[i] = adc.read(p20);
}
pc.printf("!");
for (i=0; i<noOfSamples; i++) {
pc.printf("%X,%X,", DataFront[i], DataBack[i]);
}
pc.printf("\n\r");
}
void PingDetect::CalculateFFT() {
for (k=0; k<NO_OF_FFT; k++) {
for (i=0; i<SAMPLES; i++) {
//Measure pin 19
adc.select(p19);
//Start ADC conversion
adc.start();
//Wait for it to complete
while (!adc.done(p19));
//Measure pin 20
adc.select(p20);
//Start ADC conversion
adc.start();
//Wait for it to complete
while (!adc.done(p20));
DataFront[i] = adc.read(p19);
DataBack[i] = adc.read(p20);
}
fft.CalculateFFT(DataFront);
printf("!");
for (i=0; i<SAMPLES; i=i+2) {
printf("%X,", abs(fft.my[i]));
}
}
}
// If data available on the serial buffer. Flip the NewInput flag to indicate
// New data received. Read in new data, write back received inputs.
// then clear the serial buffer to get rid off any rubbish data such as characters.
int PingDetect::ReadSerial(int cmd) {
// If data received from PC
if (pc.readable()) {
TempCmd = pc.getc();
pc.printf("%c\n\r", TempCmd);
if (TempCmd == '1')
return start;
else if (TempCmd == '2')
return calcFFT;
else
return stop;
}
return cmd;
}
void PingDetect::SendSerial(int cmd) {
pc.printf("Cmd = %i\n\r", cmd);
}