10 years, 10 months ago.

Reading data from internal ADC of Mbed NXP LPC1768 and display result on pc via teraterm

Hi life savers Pls I need urgent help. Am to use the internal ADC of Mbed NXP LPC1768 and display its output on a pc via tera term. the system has two sampling frequencies which is controlled by a on and off switch i.e. when the switch is on, the sampling frequency is 20KHz and when it is off , it is 200Hz. the voltage from the signal generator to the mbed is 4.5volt for on state and 1.20v for off state.

please could someone help or give me a guide.

thanks

What have you tried yourself? In general it is nice if people show what they tried and where they got stuck when they ask help, but this really looks like a homework question, which you were asked to do for a reason, that reason is not to ask others to do it for you.

Anyway some starting locations: AnalogIn, Ticker, DigitalIn and printf.

posted by Erik - 05 Jul 2013

Sorry that I asked such question. it's only that am new to c programming. the coding is part of my MSc project which am currently working on. I don't have any idea on it that's why. Hope you could understand my prob. thanks

posted by Alhassan umar 05 Jul 2013

I think with those starting locations you should get quite far: Read input with AnalogIn, use Ticker to sample at a certain rate, DigitalIn for the switch between sampling frequencies, and with printf send it over serial.

By the way, what is the goal of sending data at 20kHz to teraterm? Besides that you need to significantly increase the serial baudrate to be able to send data at that speed, it isn't like you can read 20,000 numbers per second.

posted by Erik - 05 Jul 2013

hi erik, please could you help with c code. i did understand the theory, my problem is that i can't even interpret c code let alone writing one for the ADC conversion. I sincerely appreciate your precious time and advise.

posted by Alhassan umar 08 Jul 2013

So you are going to do an MSc, then you must surely be able to get a book on programming. Is this the first programming language you are learning?

posted by Ad van der Weiden 08 Jul 2013

2 Answers

10 years, 10 months ago.

,

10 years, 10 months ago.

By reading some examples on this site you really should be able to find some basic information about how to do it. But a simple beginning (which I didn't test for typos):

#include "mbed.h"

AnalogIn ain(p19);
Serial pc(USBTX, USBRX);

int main() {
  pc.baud(115200);
  
  while(1) {
    printf("%f\n", ain);
    wait_ms(1);
  }

}

  1. include "mbed.h"

Serial uart(USBTX, USBRX); tx, rx volatile int result[LENGTH_RESULT]; AnalogOut tri(p18); AnalogIn P15(p15); AnalogIn P16(p16); AnalogIn P17(p17);

AnalogIn RxNoise(p19); AnalogIn RxSig(p20);

int main() while(1) {

wait_ms(1000); float rx_noise = RxNoise; uart.printf( "%8.4f\n", rx_noise ); }

} } }

Thanks to you Erik. I was able to read some input from my hardware to teraterm. But the problem is, I need to read voltage levels. 4.5V as signal, and when reduced to 1.2v, it should be read as noise using any of Analogin pins. Pin18 is not used despite it's been declared in the code above. secondly, in the last code you sent, please what does the "pc.baud(115200); do?

posted by Alhassan umar 12 Jul 2013

You can search the Serial documentation...

But pc.baud sets the speed of the serial connection, you also need to change it in teraterm. It is done to send data faster. And AnalogIn can only read up to 3.3V. If you only need to know if it is 4.5V or 1.2V you don't need AnalogIn.

posted by Erik - 12 Jul 2013