Using floating point


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: Using floating point

    Henrik, I just had a thought. How is the fact that I changed my temperature value to a long going to affect your PID routine? Specifically, pid_error and my set point are words, the actual temperature is a long.

    I've never used longs before, can you mix them with words? And I guess that I will have to use C_TEMP / 10 to get the integer portion in the equation: pid_error = setpoint - temperature?
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    967


    Did you find this post helpful? Yes | No

    Default Re: Using floating point

    Andy, your code looks workable. To simplify things, I use a tool from http://www.miscel.dk called miscellaneous electronic calculations. In that you will find an integer math module that tells you 1.64 is same as 41/25 if you want to use 8 bit math. It's a nice tool to augment your collection and I suggest you give it a try

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Using floating point

    Henrik, I just had a thought. How is the fact that I changed my temperature value to a long going to affect your PID routine? Specifically, pid_error and my set point are words, the actual temperature is a long.
    It doesn't really matter as long as you make sure that you don't overflow the pid_Error variable. And remember that pid_Error is a two's complement variable so anything above 32767 is considered negative.

    I've never used longs before, can you mix them with words?
    Yes, a LONG minus a LONG can still fit a WORD or even a BYTE. There MAY be some differences when it comes to multiplications because LONGs are signed while WORDS and BYTES are not - I'd take a look at the manual in case it's mentioned there.

    And I guess that I will have to use C_TEMP / 10 to get the integer portion in the equation: pid_error = setpoint - temperature?
    The general rule is to have the PID routine work with your raw numbers as long as the raw numbers aren't big enough to risk overflowing. There's no need for "empty resolution". The PID routine is just crunching numbers, it doesn't know what the numbers mean or represent so there's no need to have the values scaled to degrees C or whatever. As long as YOU remember to have the setpoint and actual temp variable scaled equally when you calculate pid_Error it'll be fine - then you can scale those value up or down all you want for humans to be able to make sense out of them ;-)

    /Henrik.

Similar Threads

  1. Using floating point
    By andywpg in forum PBP3
    Replies: 0
    Last Post: - 24th February 2015, 16:42
  2. Floating point math
    By Glenn in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th January 2009, 03:47
  3. Getting out of floating point
    By jcb344 in forum General
    Replies: 3
    Last Post: - 5th August 2008, 21:18
  4. Floating Point
    By jrudd in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th May 2005, 14:19
  5. help floating Point!
    By Eric in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 7th December 2003, 21:18

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts