Welcome to WebmasterWorld Guest from 54.145.117.60

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

# Textbox comparison on a webserver running on a Ethernet

#### Matthew1980

7:57 pm on Oct 8, 2012 (gmt 0)

#### Senior Member

joined:Feb 22, 2009
posts:1396

Hi there People,

I've got a math probelm, and I can't fathom it out; Id be greatful if I could bounce it here to see if there is anyone who can shed light on this issue.

I have two textbox's that get populated via ethernet to development PCB, and read voltages that are scaled to 250.00V (32767 (16BIT)), and the other textbox is the requested value ie 125.00V (16383 scaled).

As this is a website driven PCB - from webserver, I would like to know how I can present the maths so that I can detect when the read value is +/- 1% of request.

To be honest it's just the maths side of this I can't fathom.

I'd appreciate any ideas,

Thanks,
MRb

#### phranque

11:21 pm on Oct 8, 2012 (gmt 0)

joined:Aug 10, 2004
posts:11080

do you need the formula to calculate the percentage?
it's the difference between read and requested divided by requested.
multiply that by 100 to get percentage.
use an absolute value function too capture +/-.
compare the result to 1.0

#### Matthew1980

6:28 pm on Oct 9, 2012 (gmt 0)

#### Senior Member

joined:Feb 22, 2009
posts:1396

Hi there Phranque,

Thanks for the idea, sounds promising; I'm not brilliant at maths, so it's nice to get another perspective/set of thoughts on this.

I'll be having a play with this before the end of the week, so I'll post back and let you know how I've got on.

*Pseudo code*

Putting the margin of error there I think is wrong.. but I've got code here that looks similar to this that I use the work out the scaling including the margin of error

Somthing like that would be comparing the the result to the 1% margin of error wouldn't it?

Feeling a bit daft now really, somthing this simple, and it's cost me more time than calculating 16bit CRC's!

Cheers,
MRb

#### swa66

8:27 pm on Oct 9, 2012 (gmt 0)

#### Senior Member

joined:Aug 7, 2003
posts:4783

expected value: X

1%: 1*X/100

bottom: X - X/100 = 99X/100
top: X + X/100 = 101X/100

if 99X/100 <= Y and Y<= 101X/100 then it's within 1% of X

To speed things up: forget about dividing by 100 (division is slow compared to multiplication):

if ( ( 99*X <= 100*Y) and (100*Y <= 101*X) ) then Y is within 1% of X

#### Matthew1980

7:37 pm on Oct 12, 2012 (gmt 0)

#### Senior Member

joined:Feb 22, 2009
posts:1396

@Swa66,

Cool, thanks for this. I appreicate your input :)

Cheers,
MRb

PS: I'll test this on Monday & report back