Reading the maximum value showed in the oscillator in AnalogIn

13 Mar 2012

Hey guys,

I want to know how I can get (in the MBED) the maximum value that I can see in the oscillator.

My signal is similar to the following image.

/media/uploads/alopes/result-osciloscope.jpg

I did a loop using the while(1) and saved 20 values in an array. But with this technique most of the times I can't get the maximum value, which is what I'm looking for.

How I can do that?

Regards

14 Mar 2012

What's the time scale?

14 Mar 2012

maximum value of what, please show code.

cheers Ceri

14 Mar 2012

Hi, reading the analogue input returns a float in the range 0 - 1. see here http://mbed.org/projects/libraries/api/mbed/trunk/AnalogIn#AnalogIn.read

14 Mar 2012

You could use a compare and keep algorithm *probably*,

PSEUDO CODE.

value = 0;

while(1);
  latest = inPin.read();
     if (latest > value) {
          value = latest;
     }
}

You could put the test on a ticker, so that the largest value is always kept in the background.

Questions to consider, are things like..

What's your timescale ? Do you need to zero it, do you need the value of each peak, or just between 2 times, or just ever ?

Watch out for random spikes, you'll need to find the "Good ADC practice" page. (set unused pins low etc etc). You might want to do some software filtering,

cheers,

Dave.

14 Mar 2012

Hello guys,

My time scale in the image is 10ms, but I need to measure the AnalogIn during 20 times (to get a total of 20 measures which is equal to 20ms) each 1ms. After that I'm going to see which value is the biggest and input via pc.printf.

In this moment I have a pretty good code, but what is missing now is how I can get the 20 measures with a exact time of 1ms. Also I know how to measure the AnalogIn value in Volts - just need to use a basic formula = myport.read()*3.3.

Regards

14 Mar 2012

Have a look at:

http://mbed.org/handbook/Ticker

You can attach a function at a specific interval (even microseconds) in which you can read the AnalogIn and determine if the value read is higher than the value read before. You can keep a counter to get exact 20 readings and then test for maximum.

21 Mar 2012

Dave Tech wrote:

You could use a compare and keep algorithm *probably*,

PSEUDO CODE.

value = 0;

while(1);
  latest = inPin.read();
     if (latest > value) {
          value = latest;
     }
}

You could put the test on a ticker, so that the largest value is always kept in the background.

Questions to consider, are things like..

What's your timescale ? Do you need to zero it, do you need the value of each peak, or just between 2 times, or just ever ?

Watch out for random spikes, you'll need to find the "Good ADC practice" page. (set unused pins low etc etc). You might want to do some software filtering,

cheers,

Dave.

I'm really getting random spikes sometimes which couldn't happen. Thanks for suggesting me the Good ADC practice.

When I finish my project in energy management I will post here the result and the How-to.

Gert van der Knokke wrote:

Have a look at:

http://mbed.org/handbook/Ticker

You can attach a function at a specific interval (even microseconds) in which you can read the AnalogIn and determine if the value read is higher than the value read before. You can keep a counter to get exact 20 readings and then test for maximum.

Thanks for the info. Now I'm reading each 1ms the value in the AnalogIn.

Regards,

Adriano

http://www.superdicas.net