8 years, 4 months 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:

  1. 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

8 years, 4 months 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)