# Sinewave measurement

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?

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)

``````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;
}
}
``````

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;

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 :~

Rob

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?

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

I'd like to measure the falling and rising edge

OK.

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?

I do not know how to do that

Do what?

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.

:~ :~

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

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.

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.

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.

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: (Samples)Comparator circuits with Hysteresis Design Tool - results -

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?

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

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

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