Interpreting analog signal from incremental encoder

I am using a Renishaw LM10 encoder read head with only analog output. It has two sine wave channels: V1, V1- and V2, V2-. Then there is a 3rd reference signal that pulses at my specific reference mark, which is at 1cm in my case. Here is the data sheet (Go to "Analog output signals (1Vpp)"):

[https://www.rls.si/eng/fileuploader/download/download/?d=1&file=custom%2Fupload%2FLM10D01_16EN_datasheet.pdf]

I currently am attempting to use multiple if statements to look for specific cases, so that i can attempt to keep adding to the length total. Currently the code just keeps adding no matter where I am on the scale. My code I have tried is:

int V = 0;
int V2 = 0;
int V11 = 0;
int V12 = 0;
float VoltageV = 0;
float VoltageV2 = 0;
float VoltageV11 = 0;
float VoltageV12 = 0;
float lengthmm = 0;
float lengthin = 0;
float mmmeasured = 0;


void setup() {
  Serial.begin(9600);

}

void loop() {
  V = analogRead(A2);
  V2 = analogRead(A3);
  V11 = analogRead(A0);
  V12 = analogRead(A1);
  Serial.println(V);
  //Serial.println(V2);
  //Serial.println(V11);
  //Serial.println(V12);
  VoltageV = V * 0.00193;
  VoltageV2 = V2 * 0.00193;
  VoltageV11 = V11 * 0.00193;
  VoltageV12 = V2 * 0.00193;
  if (V11 > 406 && V11 < 545) {
    mmmeasured = V11 * 0.01438849;
    lengthmm = lengthmm + mmmeasured;
    Serial.println("Length = ");
    Serial.println(lengthmm);
  }
  else {
    if ( V = 414) {
      lengthmm = 10; //reference mark at 1cm;
      Serial.println("At Reference");
    }
  }

    delay(1000);
  }

I'm seeing if anyone can give me advice on how to fix this if statement or provides suggestions for other loops I can use.

Fixed data sheet download link https://www.rls.si/eng/fileuploader/download/download/?d=1&file=custom%2Fupload%2FLM10D01_16EN_datasheet.pdf

The encoder outputs an AC signal, but the Arduino cannot read negative voltages, and may be damaged if you try.

What signal conditioning circuitry are you using? Post a schematic diagram.

I currently am just plugged directly into the analog ports of the arduino uno. I'm assuming I am going to need to make a divider of some sort to keep the voltages between 0-5 volts.

There's no reason to convert the A2D readings to voltages. Given the tiny numbers you are multiplying by they probably end up so close to zero as to be useless. Just do your comparisons with the A2D results directly.

Also, your code probably runs in about 1mS or something similarly quick, then you do nothing for 1 second, meaning your code is only doing anything useful for 0.1% of the time, is this what you want?

I'm attempting to have this read as fast as possible all the time. This was my test program to get all of the stuff ironed out before I placed it in my larger sketch. I have realized those voltage calcs don't really matter that why I was just using the raw analog output for the logic.

An op amp with gain and offset for each channel would work, but would require precision components and careful calibration.

If you care about accuracy, buy the manufacturer's interface.

Gotcha, I will go and look their website for any interfaces they have because I definitely can't replicate the precision that is required.

There might be something helpful in here: Using Operational Amplifiers in your Arduino project

@johnerrington knows a lot about op-amp circuits and might have additional advice.

I would start by just reading the analogue inputs and printing them to see what you get. Although you've not shown how it's wired I infer from what you have shown that it's wrong and not likely to work, or could cause damage.

Ill give this a read. Currently I have each analog output pin from the encoder plugged into the various analog ports on the board. The signal is not passing through anything. To avoid damaging the arduino due to the negative output voltage I will do some more research.

I suspected as much. Then neither one of them is referenced to ground, making the readings you take meaningless. I've not looked at the data sheet but I'm guessing it's something magnetic, coils of wire maybe?

Edit:
A quick look at the data sheet, not as I thought. Not as you think either! Please post a schematic when you have done some reading and worked out what you need. Much of what I am saying is based on guess work because I don't really know what you have done.

Yeah it's magnetic, and there is a GND wire on the sensor output, but I definitely need something else. Thanks for the recommendation.

Do you have access to an oscilloscope? I'd want to see what is on the outputs before designing circuitry for it.

The data sheet makes that clear.

1 Like

I believe there is one somewhere and I can try and get access, but I won't be able to check that until tomorrow.

1: you havent said WHICH arduino you are using?

The outputs are not grounded. SO you can bias them to Vcc/2
image

if you make a 1:1 voltage divider you can connect the V0- V1- and V2- lines to it.
To keep the ac impedance down I'd suggest you choose resistor values (say 220 - 470 ohm) to allow a current of a few mA down the chain; and also place capacitors across both the resistors. That reduces glitches at switch-on.

Alternatively you can make a mid-point voltage with an op amp, a dedicated rail splitter like this

or use a voltage reference to give around half of the supply voltage.

You can then connect V0+ V1+ and V2+ to analog inputs, with terminating resistors to the "common" point (V0- V1- and V2- ). Increasing the value of the terminating resistors will give you a larger signal.

Hi,
Were you asked to use this encoder?
Why not the quadrature output version?

The bottom of that data page has how to terminate the output.

Tom.. :smiley: :+1: :coffee: :australia:

The arduino I am using to test this encoder is an UNO, but for the actual project I will have it hooked up to a MEGA.

We were thinking it would be simpler to receive an analog signal and find the voltage to length ratio. In hindsight we should've chosen one of their other versions of this read head because the manufacturer sells interfaces to use for them. It's all been a huge learning experience.

Both use a 5V supply, so you can use the "default" adc reference of Vcc = 5V.
use a rail splitter to get 2.5V for your "virtual earth" for the V- connections and V0, V1, V2 to the adc inputs.
Job done.

Hi, @atrainer

If you got a pulsed output encoder, then all you would be doing is counting pulses, something that a microcontroller is expert at.
In fact there are specific libraries for reading quadrature encoders.

Converting a voltage level to position will take software and that will slow down your overall code. If the speed of the encoder changes, that is even more code.

Tom... :smiley: :+1: :coffee: :australia: