Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
12 years, 3 months ago.
Is there sample code of this implementation
Hello All,
I need a constant ADC running in the background. The FastAnalogIn seems like it will do the trick, but I keep getting a variety of errors.
Does someone have a working code example, or an example that I could look through?
Thanks
Question relating to:
1 Answer
12 years, 3 months ago.
Hey,
What kind of errors are you getting? I currently don't have a real HelloWorld program for it, since it should be pretty much drop-in replacement. But this one I still had in my workspace, I used it when developing the lib:
#include "mbed.h"
#include "FastAnalogIn.h"
DigitalOut myled(LED1);
FastAnalogIn ain(p20, true);
FastAnalogIn ain2(p19, false);
Timer timer;
int main() {
volatile float val[1000];
wait(1);
printf("\n\r");
timer.reset();
timer.start();
for (int i=0; i<1000; i++)
val[i]=ain.read_u16();
timer.stop();
printf("Took %dns per conversion\n\r", timer.read_us());
ain.disable();
timer.reset();
timer.start();
for (int i=0; i<1000; i++)
val[i]=ain;
timer.stop();
printf("Took %dns per conversion\n\r", timer.read_us());
ain2.enable();
timer.reset();
timer.start();
for (int i=0; i<1000; i++)
val[i]=ain;
timer.stop();
printf("Took %dns per conversion\n\r", timer.read_us());
printf("Start\n\r");
ain2.disable();
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
int value = ain.read_u16();
printf("%d\n\r",value);
}
}
Main question is which errors you are getting :)