Analog math

rpoet

Member
Join Date
Jun 2008
Location
New York, NY
Posts
536
Hi All,
I'm having a mental block when it comes to some analog math:

Using a DL-06 PLC from AutomationDirect with a 12-bit analog combo input/output card (0-4095).

I have a joystick connected to the input that reads ~2045 when centered, ~220 when full left, and ~3960 when full right. I need to scale the signal so that when the joystick is moved off center, I get a 0-4095 output on my analog output, no matter the direction of the joystick. 0-4095 output either full left or full right.


(full left) 220 ------ 2045 ----- 3960 (full right)
joystick
center


(full left) 4095 ------- 0 ----- 4095 (full right)
analog
output

I will handle joystick direction (and thus, motor direction) with comparative contacts.

I've done plenty of scaling when going from 0-4095 to engineering units, but this midpoint application has me stumped.

EDIT:
I've found this app note from AD, and I think it may help with the joystick-to-the-left math, but I'm still stuck:

http://www.automationdirect.com/static/manuals/t1krsssm/appxb.pdf


Thanks,

-rpoet
 
You just need a preliminary step where you calculate the difference from center position. I would just subtract 2045 from whatever the current reading is and take the absolute value.

Roughly you should end up with a number between 0 and 1800. Then you can scale the 0-1800 to output to 4095 the way you normally would.
 
You just need a preliminary step where you calculate the difference from center position. I would just subtract 2045 from whatever the current reading is and take the absolute value.

Roughly you should end up with a number between 0 and 1800. Then you can scale the 0-1800 to output to 4095 the way you normally would.

While I understand the concept of subtracting a constant and taking the absolute value, I'm having trouble getting this into code. The DL-06 doesn't seem to deal with negative numbers very elegantly, or at least I don't know how to make it.

The joystick-to-the-right part was easy, since it's all positive numbers. I've got that part worked out no problem.

See the attached screenshot for what I've got so far. I've slightly adjusted the center value to K2110, as that's where it's settled after some use of the joystick.


Thanks,

-rpoet

Untitled.jpg
 
Add another rung with the test of the value being less than the center point. In your math blocks just swap the first two - LD CenterPoint, SUB InputValue. Keep the others the same.
 
Add another rung with the test of the value being less than the center point. In your math blocks just swap the first two - LD CenterPoint, SUB InputValue. Keep the others the same.

Thank you, Bernie. I knew it was that simple... it was just eluding me. It's been a long week, and it's only Tuesday.

Bernie, you've helped me out on several DirectLogic math-related questions over the years. If you're ever in the NYC area, beers are on me. Thank you.


-rpoet
 

Similar Topics

Hello - you folks were kind in helping me the other day so I'm back for more... My program is finished however the end customer hasn't provided...
Replies
4
Views
1,933
Hello, I'm working with a 1747-NI4 analog input module (for the first time) on a SLC503 processor. I noticed in the IO configuration within...
Replies
13
Views
4,763
Hello guys; I'm ashamed to admit it but I can't wrap my head around the proper math to tell a customer what type of accuracy I can get between...
Replies
7
Views
2,839
I was wondering if you wanted to average four analog inputs in the program, would the best way be to do three add instruction and a divide to a...
Replies
9
Views
2,419
Hello Guys,Any one please tell me how to scale an analog sensor which is 0-10v and it has to be scaled to 0-8v or something using math...
Replies
7
Views
3,689
Back
Top Bottom