cancel
Showing results for 
Search instead for 
Did you mean: 

How to interpolate and compare 2 sine waves

paul sauv
Associate III
Posted on February 28, 2018 at 22:23

Hi everyone,

With my STM32F103C8T6 I would like to receive the 2 signals I1 and I2 from the picture below in order to convert to

https://community.st.com/tags#/?tags=square%20signal

.

All the square part is already coded and working great.

Now I would like to learn how to use this

https://community.st.com/tags#/?tags=sine%20waveform

and

#

signal and interpolate them such as the file attached in order to have a decent precision. For example, in my case the step of the wave is 20 microns so I would like to interpolate it by 20 in order to have 20 pulses of 1 micron.

This is an optical ruler on a milling machine so the ruler can travel in both ways with numerous direction changes

I'm a hobbyist so any bite of code is very welcomed

Right now, I only use Std periph lib, not HAL libraries.

Thank you for your help

0690X00000609qZQAQ.png

#square-signal #sine-waveform #cosine

Note: this post was migrated and contained many threaded conversations, some content may be missing.
19 REPLIES 19
Posted on March 03, 2018 at 15:29

'

I followed advices above and bought an specific IC: IC-NV'

that's very unfortunate, as the article you linked to provided incredibly concise expression between the inputs and the outputs. it is quite easy to implement in a mcu.

Posted on March 03, 2018 at 15:31

yes but I have absolutey no idea how to proceed as a beginner

But I would be happy to understand if you explain piece of code

Posted on March 03, 2018 at 21:51

You have to start somewhere or you will forever be a beginner.

The paper you linked to is quite simple. And it takes no code to understand.

Posted on March 04, 2018 at 08:58

I totally agree. I understand the document quite well I think but stuck on the MCU part

What I'm looking for is the first step in order to know the position of the sine wave because I never saw this kind of example somewhere.

For example at time t1, where is sine wave and cosine wave, and then I will be able to store value and compare to value stored in t2 etc

Posted on March 04, 2018 at 11:04

Hi Paul

Can you consider using the STM32 ADC?

But first you must adapt your sinwave (convert 11uA current peak to peak to voltage) using a pair of operational amplifier.

Look to use a non-inverting circuit with the adapted gain. IMHO, this is the most complicated part.

Your ADC input signals need to be packaged to satisfy the ADC VREF range to obtain an acceptable SNR. DC offset must also be taken into account in order to transform the signals into positive ones.

Your ADC will configure 2 channels, it will be triggered by a GP Timer at the sampling rate of 1us.

Finally the DMA in circular mode will transfer the samples in 2 SRAM buffers of equivalent size to the number of points per period (20 sample / period)

You would get two tables of 20 samples, which will represent the sines.

Then it will remain the mathematical treatment for the calculation of the phases.

You can also use a device with an ADC with differantial input conversion (ie STM32L4)

Hope my method will give you a starting point.

KR

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

AVI-crak
Senior
Posted on March 04, 2018 at 12:12

Industrial optical encoders give the data in a crude form, but without delays. With a slow movement - they manage to give the full result.

The data from the optical encoder in its raw form is not a sound !!!, it can have a constant voltage in the static state.

How to make a rapid rough conversion - to translate the analogue into a digital form, and submit to a free timer in encoder mode. You will have a momentary value for the position of the ruler.

Separately monitor the rate of change in the readings of the ruler, as soon as the rate of change becomes sufficiently small - the result of the ADC measurement becomes relevant, and it can be used together with the encoder readings.
Posted on March 04, 2018 at 11:44

'

Can you consider using the STM32 ADC?'

that's the 2nd method mentioned in the paper.

it's key, however, isn't about adc but how to quickly convert the adc numbers to positions.

pretty innovative, I have to say.

Posted on March 04, 2018 at 14:10

Using à Cordic algorithm.

http://www.st.com/content/ccc/resource/technical/document/design_tip/group0/9c/20/c6/67/50/10/4e/9d/DM00441302/files/DM00441pdf/jcr:content/translations/en.DM00441pdf

Regards

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on March 05, 2018 at 13:15

Encoder interpolation is highly proprietary, thus no examples.

If you had followed through on this project, you stand a good chance of commercializing your end product.

Too bad that you gave up so early.

Posted on March 05, 2018 at 17:02

Perhaps the patent is still active, but the work of the algorithm can be seen visually!

Industrial electronic rulers with digital output - give the result in a rough form with a quick move. There is always a serial port, one data line, the first checksum, and then the data. The highest bit of data is transmitted first, the youngest is the last.

During a quick move, the lower order bits lose relevance, so they are always zero. While there is data transfer - the ruler has time to significantly shift. This can be fixed using an oscilloscope.

Thus, industrial digital rulers give a completely accurate result at a very low speed of movement. And yet, often there is an ancient microprocessor, cost literally cents. And he does all the work.

You can get a more accurate quick result if you use a timer in encoder mode.