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.
9 years, 1 month ago.
Reading analog input
i connected a sine wave generator to pin 20 of the mbed1768 and just read the analog values and printed them on teraterm, the received values are 0.6- or 1.-, no other values, the frequency is only 1 Hz and the voltage between min = 0 and max = 3V. Can anyone help why this happen? why dont i get all the values between 0-3V?
here is my code:
- include "mbed.h"
Serial pc(USBTX, USBRX); AnalogIn Ain(p20);
int main(void) { while (1) { for (i = 0; i<64; i++) { dummy = Ain.read(); pc.printf("%f\r\n", dummy); } } }
1 Answer
9 years, 1 month ago.
The for() loop samples the input fairly quickly. you might want to put a delay after the pc.printf
wait(1.0 / 64); 64 samples over 1 second (1 Hz)