Maths question

Designer

Member
Join Date
Mar 2005
Location
Essex, UK
Posts
20
I'm sure someone must have done something like this before (i'm sure i have too at some point but cant remember), anyways. I'm working on a project for home (no i'm not a student) which involves using an analog to digital converter hooked up to my PC. Now I want (in visual basic) an analog gauge and a digital gauge (the analog is done).

OK, my AD input range is 0 - 255, I want to make a value of 0 to return a value of -20 and a value of 255 to return a value of +20, therefore a value of 126.5 to give a value of 0. I can do this if it were ranging from 0 upwards as it's just straightforward division but havnt a clue how to do it where the returned values are +/- figures. I just cant figure what maths are involved to return the correct values.

Any help would be greatly appreciated.
 
(ValueIn * (Scale_Max - Scale_Min) / (Raw_Max - Raw_Min)) + Scale_Min

Check: (128 * ( 20 - (-20)) / (255 - 0)) + (-20) =
(128 * (40 / 255)) + (-20) =
(128 * 0.15686) + (-20) =
20.078 - 20 = 0.078
 
[edit] little mistake, this should give -20 till + 20

(analog input/6.4)-20

[/edit]
 
Last edited:

Similar Topics

Hi, I've been asked to add a "Products per minute" value to a text display. The machine is running an S5 115U and, at first, I thought it would...
Replies
9
Views
3,176
I have a dataword ,each bit is actually an alarm, No i have to program a condition that shut down the installation when more than two bits are set...
Replies
42
Views
8,768
Hi Folks I hope this is not a dumb question,I am a newbie . I want to perform simple math functions like multiplication, addition etc in TIA...
Replies
6
Views
2,813
Hi all, I am trying to copy paste a routine from rs logix500 into rs logix5000, I get an error on rung where they are searching for scada values...
Replies
1
Views
1,852
Hi I am fairly new to PLC programming and I am self learning. I have written a simple program to detect and store the RPM and ultimately the...
Replies
0
Views
1,413
Back
Top Bottom