Pages: [1] 2   Go Down
Author Topic: Sinewave measurement  (Read 3066 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 1
Posts: 140
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I have the following problem:.

From a OP Amp I receive four signals with squarewave form of each max 16kHz with a max voltage of 5V. I'd like to measure the falling and rising edge of it (but no frequency measurement). The issue is that the form of the square is not "ideal" but has a slight oscillation at the end and beginnng.
I do not know how to do that, because a simple voltage comparison over time doesn't work. Hence the falling edge is detected the Arduino does something with it. No analog results required.

I suspect I need to get the signals in by the analog inputs. But how to continue?

Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


YOu might connect the signal to the Arduino interrupt - http://www.arduino.cc/en/Reference/AttachInterrupt -
and as you know the max freq is 16Khz, you can ignore samples that come faster (bouncing/oscillations)

you need something like this (not tested)
Code:
int pin = 13;
volatile int state = LOW;

void setup()
{
  Serial.begin(115200);
  pinMode(pin, OUTPUT);
  attachInterrupt(0, myIRQ, FALLING);
}

void loop()
{
  digitalWrite(pin, state);
}

volatile unsigned long previous = 0;
volatile unsigned long duration = 0;

void myIRQ()
{
  unsigned long t = micros();
  if (t - prev > 62)      // 62 micros ~~ 1sec/16.000 
  {
    duration = t - prev;
    prev = t;
    state = !state;
    // do your thing
  }
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Montreal
Online Online
Faraday Member
**
Karma: 27
Posts: 2569
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think you can do it with analog inputs, as they not fast enough. I assume falling / rising edges would occupy ~20% of the pulse. If it true, than t < 1 x 0.20 / 16 x 10 ^3 = 12.5 usec.
To get more or less accurate measurements, sampling has to be at least 10x times faster.
Solution would be :
use faster external ADC, with sampling 1 MHz ;
external two comparators (set at 10% at 90% of amplitude) for each signal;
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't quite understand what you want to measure, am I correct in saying that you want to measure the rise and fall times and/or the overshoot/ringing of an opamp output that has a square wave input?

If so you better go and get a good scope unless you're using the worlds slowest opamps.

Or have I got the wrong end of the stick?

EDIT: I know the title says sine wave but the post says square wave smiley-confuse

______
Rob
« Last Edit: October 09, 2011, 09:13:15 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Full Member
***
Karma: 1
Posts: 140
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
thanks for the hint with interrupt.

Reading the Reference ist says the interrupt is used hence the signal goes from high to low. I know that the "high" ist 5V and a perfect "low" 0V. The voltage signal I will see is between 2.5 and 5V. Will Arduino detect 2.5V als "low" as well?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Will Arduino detect 2.5V als "low" as well?
No.
According to the data sheet the maximum value for a logic 0 when working at 5V is:-
 0.3 * 5 = 1.5V
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'd like to measure the falling and rising edge
OK.

Quote
the square is not "ideal" but has a slight oscillation at the end and beginnng.
Does that have any bearing on the rise and fall times?

Quote
I do not know how to do that
Do what?

Quote
a simple voltage comparison over time doesn't work
smiley-confuse

Quote
Hence the falling edge is detected the Arduino does something with it.
Quote
No analog results required.
smiley-confuse smiley-confuse

Sorry soulid but I'm lost with this and you didn't answer my previous questions so I'll assume I'm the only one that is and move on.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Full Member
***
Karma: 1
Posts: 140
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Graynomad,
thanks for advising me to my bad formulation.

May I answer with a better formulation:
From a OP Amp I receive four signals with squarewave form of each max 16kHz with a max voltage of 5V. I'd like to measure the falling and rising edge of it as quick as possible and giving the status to a digital pin. The issue is that the form of the square is not "ideal" but has a slight oscillation at the end and beginng.
I do not know how to analyse the signal as there is a sinosoidal part at the end of the square waveform. The falling/rising edge of the sinusoidal waveform is may confusing the micro.


Later Grumpy_Mike noted the threshhold value of the interrupt function is 1,5V. So the micro will not be confused by a few mV sinewave at the end of the squarewave signal- which is good!

Now it is to me adjusting an OPAmp to voltages clearly below and above 1,5V.
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11718
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The circuit component you need to be aware of is the comparator - bit like an op-amp but the output is logic-level and negative feedback is not used.  Basically if the + input is at a higher voltage than the - input the output goes HIGH.   Be careful, you'll need a low-voltage device, and many devices require pull-up resistor on the output.
Logged

[ I won't respond to messages, use the forum please ]

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The issue is that the form of the square is not "ideal" but has a slight oscillation at the end and beginng.

The definition of rise time is the time taken to go from 10% to 90% of full amplitude. The slight oscillation you are seeing is known as ringing. This can either be real or an artifact of the measurement process. In the latter case it is often the inductance in a scope probe that is causing it.

Assuming your ringing is outside the 10% to 90% region then as MarkT says you need to use two comparators set to trigger at these thresholds. Then you need to measure the time interval between edges on the comparator outputs.

Is this a one off measurement, if so you are better off using a scope. If you need to measure this on an ongoing basis then get some good quality comparators and perhaps even a precision voltage reference.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 140
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I thought about the problem and have the following solution:
1) Amplify the signal coming from a voltage divider (OpAmp- LM348)
2) Use a standart comparator (LM339) to read out the signal. A hysteresis circuit will make sure that any signals beside the wanted is filtered. A good design tool for component selection is here: http://sim.okawa-denshi.jp/en/rercal.php

This will lead to a proper 4,95V to 0,05V rectangular signal I can easily use with Arduino interrupt method.

What do you think?
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 126
Posts: 8473
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have a 2v5-5v signal you don't have to amplify it, just set the comparator trip point to somewhere about half way between those two values.

What is the input? Do you need the opamp at all?

I gather we're not measuring rise times any more?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Montreal
Online Online
Faraday Member
**
Karma: 27
Posts: 2569
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What is arduino doing in this setup with OPA filtering/comparing?
I 'm lost, what OP try to measure, btw.
Logged

0
Offline Offline
Full Member
***
Karma: 1
Posts: 140
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@Magician:
No arduino required any more hence comparator used- and this is far quicker than arduino (sorry to say in this forum)

@Graynomad
You're right...no opamp required any more
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 603
Posts: 33408
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So what is it that you actually want to measure?  smiley-confuse
Logged

Pages: [1] 2   Go Up
Jump to: