Author Topic: Calculation with decimal point  (Read 10492 times)

scottsaunders

  • Guest
Calculation with decimal point
« on: April 14, 2003, 04:53:47 AM »
I want to do the calculation:

T = 25.57 - 0.01249A

I want to then store the value of T in to timer 1.

I read in the forum that only integer math is available so how do I do this?

« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re: Calculation with decimal point
« Reply #1 on: April 14, 2003, 12:27:05 PM »
You can use fixed point arithmatics. Assuming every unit represents 0.01:

T = 2557 - 1249*A/100000

(Make sure that  you multiply by A first before dividing by 100000)

The resulting value T is x 100.

You can store value of T in timer #1 S.V using SETTIMERSV.

You can store it in timer #1 P.V (present value using  TIMERPV[1] = T.

If you define timer #1 as High speed timer then each unit of T represent 0.01s.
« Last Edit: December 31, 1969, 04:00:00 PM by 1076562000 »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS