Author Topic: FMD88, AN20MA and Keyence Lasers  (Read 15740 times)

ondercin

  • Newbie
  • Posts: 4
  • I'm a llama!
    • View Profile
FMD88, AN20MA and Keyence Lasers
« on: January 09, 2017, 06:43:11 AM »
Okay, I've gotten so far and things looked good but it's just not working right

Keyence thinks the PLC might not be accurate enough... But I'm not giving up that easy!
I've got 3 Keyence lasers model # LR-TB5000

They are connected to FMD88-10 via AN20MA-2 interface.

On the AN20MA the lasers are connected as follows
Laser 1 (white wire (50ma analog OUT) connected to AD5, Laser 2 -> AD6, Laser 3 -> AD7
All Lasers - Brown wires (0-30v DC) connect to 24v on the AN20MA
All Lasers - Black wires (50mA) connected to AGND on the AN20MA

Using VB to connect to the FMD88, and TriLogicClient.GetStream
   Sending a command of “@01RA01085B*”, I get a returned result for all the Analog ports:
      = @01RA08002E0031002D002C05A005670587003352*

   Since I am only interested in AD5->7
      AD5 Hex 05A0 = 1440 decimal
      AD6 Hex 0567 = 1383 decimal
      AD7 Hex 0587 = 1415 decimal

I have the lasers mounted about 37” above the floor, and the response times are set to 1000ms
Looking at only Laser 2 (AD6) the Keyence digital output reads 74mm which is correct as I measured it.

Running the send command every 100ms for 2 minutes and measuring the lowest and highest numbers
   Low = 1382 decimal and High = 1395 decimal

Now I have removed my 74mm block and just measuring to the floor which is 0, but due to my carpet maybe the laser is flickering between 0mm & 1mm
Again running the send command for another 2 minutes and measuring the lowest and highest numbers
   Low = 1430 decimal and High = 1439 decimal

Blocking the laser with tape to max it out and running the send command for another 2 minutes
   Low = 817 decimal and High = 826 decimal

How can I accurately have the TriLogic PLC respond so that I can convert that decimal number into an accurate millimeter reading?

I’ll admit I am new the TriLogic PLC boards and thought I’d give them a shot because of the price point and the good things I’ve heard about them.

I’ve attached images of the boards and wiring

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:FMD88, AN20MA and Keyence Lasers
« Reply #1 on: January 09, 2017, 02:27:41 PM »
I think that you are asking how to get ADC readings converted to mm readings.  You provided ADC readings for 2 distances:
   74 mm, 1388 ADC counts average
   0 mm, 823 ADC counts average

With those 2 points the calculation is as follows:
   y = 0.1131x - 107.8
where:
   y is the distance in mm
   x is the ADC count value
   0.1131 is the slope of the line
   107.8 is the offset (y intercept) of the line

I have attached a spread sheet that I used to calculate this stuff.  I'd be happy to send you a copy of the spreadsheet.

If you are requiring an accuracy of 1 mm or better over a range of 0..5000 mm you will not achieve this with the FM88 ADC.
There are some real world limitations with the PLC's analog to digital conversion (ADC) hardware.  Most of these limitations are by design.  The FMD88's ADC is a 12-bit ADC takes a 0..5V DC input and converts it to a number between 0 and 4095.

You have chosen to use the Keyence's 4..20 mA with the AN20MA interface. This interface translates the 4..20 mA sensor output to 1 to 4 volts which translates to ADC readings of 819 to 4095.  With the 4..20 mA sensor you can only get an ADC resolution of 3276 (4095-819).  So if the Keyence sensors range of 0..5000 mm is mapped to 4..20 mA, then each of the ADC counts will represent about 1.5 mm  (5000mm/3276).

The measurement uncertainty is greater than +/- 1.5 mm because of analog and conversion noise. I will address this issue a bit latter. There are things that you can do improve the resolution of the PLC's ADC:

1. Rescale the analog output of the Keyence sensor.  Let's say that you are only interested in measuring from 1000 to 2000 mm, then adjust the lower level of the analog output to represent 1000 mm and the upper level to 2000.  Now the PLC's ADC will see 1000 mm of difference over 3276 ADC counts.  In this case each ADC count represents 0.305 mm.
2. Switch the Keyence sensor to use it's 0..10V output.  This will allow you to use the full 0..4095 ADC count range and could improve the resolution of the system by about 20%.  You would need to replace the AN20MA board and add resistors to scale the 0..10V sensor output to 0..5V to work the ADC inputs.

OK now that you have matched the sensors' output to the PLC with a combination of rescaling the output and using the 0..5V sensor input we need to address the ADC noise issues. Your ADC measurements show a certain amount of randomness (variability) from sample to sample. This is typical for this PLC.  The source of the ADC variability is noise on the analog input signal and conversion noise of the the ADC on the main PLC. You numbers suggest a noise of about +/- 6 ADC counts.

Fixing the noise issues are complicated and you will have to be very disciplined with power supply wring, sensor wiring and may need to add additional circuitry to bypass the sensor noise at the input the the PLC ADC.

If you still have too much randomness int the ADC readings you need to work on filtering algorithms for the ADC readings. There is support built into the PLC to perform a "moving average" of the last several readings.  I prefer using a different algorithm that allows me to both filter the signal and double the ADC's apparent resolution from 12 to 13 bits at the same time.

I'll be happy to share the filtering algorithms with you when you are ready.

Best regards,

Gary D*ckinson
« Last Edit: January 09, 2017, 02:29:33 PM by garysdickinson »

ondercin

  • Newbie
  • Posts: 4
  • I'm a llama!
    • View Profile
Re:FMD88, AN20MA and Keyence Lasers
« Reply #2 on: January 09, 2017, 02:51:34 PM »
WOW Gary! Awesome response..
I'll check things over tomorrow when I return to my office

Thanks and I'll keep you updated if I require the files you have to share!

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:FMD88, AN20MA and Keyence Lasers
« Reply #3 on: January 09, 2017, 04:38:26 PM »
Thank you Gary. That is a great response.

Ondercin, a few other notes of importance.

1) On the FMD88-10, ADC #1-6 are high impedance with no internal pull down resistors, whereas ADC #7-8 are pulled down to 0V via on-board 20k resistors.

2) Since ADC channels 1-6 are all high impedance, they will float high when disconnected. In order to reduce the effects of electrical noise, we recommend that you connect any of these unused inputs to common (0V).

3) Since ADC channels 7-8 are internally pulled down via 20k resistors, you will need to follow the recommended resistor wiring in section 5.2.2 of the FMD88-10 user manual when interfacing to 4-20mA analog sensor signals. I would recommend using any of channels 1-6 instead so that the resistor wiring is simplified.

4) If you follow Gary's recommendation to use 0-10V sensor outputs, then it will be easier to use ADC #7-8 for the voltage divider since you only need to add a 20k resistor in series with each of the two ADC inputs. You would then need to add a full 2 resistor voltage divider for the 3rd sensor that would connect to any of ADC #1-6 since these do not have any internal pull down resistor.

5) Adding software filtering is highly recommended. If you want to apply some simple software filtering first, you can use the following to take the average of 100 readings on each ADC channel you are using.

-----------------------------
FOR I = 5 TO 7
  A = 0
  FOR J = 1 TO 100
    A = A + ADC(I)
  NEXT

  DM = A/100
NEXT
-----------------------------

This will store the averaged ADC readings in DM[5] to DM[7] corresponding to ADC(5) to ADC(7). The above code takes about 35ms to execute, so there is plenty of time to take new averaged readings every 100ms (assuming the rest of your program is not overly large and doesn't contain delay statements).

I'm sure Gary's software will provide more sophistication, but the above code will help a lot.

Email: support@triplc.com
Tel: 1-877-TRI-PLCS

ondercin

  • Newbie
  • Posts: 4
  • I'm a llama!
    • View Profile
Re:FMD88, AN20MA and Keyence Lasers
« Reply #4 on: January 10, 2017, 03:28:43 PM »
I wasn't able to get back to this today due to other urgent year end work issues... hopefully I can get back to this tomorrow afternoon.

ondercin

  • Newbie
  • Posts: 4
  • I'm a llama!
    • View Profile
Re:FMD88, AN20MA and Keyence Lasers
« Reply #5 on: January 17, 2017, 06:20:49 AM »
Okay, so I've managed to get some very promising results using Gary's suggestions!
I've been focused on ADC8 mainly and am getting pretty good results, but I'm going to add some resistors and see if I can get even better readings.
Thanks in advance, and don't worry I'll reach out again if I run into issues!

Thanks!!