Implementing a linear function...


Results 1 to 5 of 5

Threaded View

  1. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    "Almost" is a relative term, and I guess it depends on how much "Almost" your application can tolerate.

    From this excel graph you can see there's quite a bit of "curve" to it. But it may not be that bad.

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1880&stc=1&d=118535245 1">

    Converting the formula excel came up with to this...
    Code:
    TempC  VAR WORD
    ADval  VAR WORD
    
    TempC  = ADval * 396
    TempC  = DIV32 1000
    TempC  = 67 - TempC  
    
    LCDOUT "Temp C = ", SDEC TempC,"  "
    You should get these results
    Code:
           8-bit
    Volts	A/D	Temp	PIC reads
    -----	---	-----	---------
    3.45	175	0	-2
    2.84	144	10	10
    2.3	117	20	21
    1.81	92	30	31
    1.36	69	40	40
    1.02	52	49	47
    It's off by 2 degrees at the top and bottom of the scale, 1 degree in the middle, and is very close in the areas of 10 and 40 deg.

    If that's not within the "Almost" for your program, then Sayzer's idea of a Stepped Linear Interpolation using Select or Lookup/down, will get you closer.

    HTH,
    Attached Images Attached Images  
    DT

Similar Threads

  1. Single button function
    By DynamoBen in forum mel PIC BASIC Pro
    Replies: 40
    Last Post: - 4th April 2020, 18:33
  2. ARCSIN function
    By mjphillips1981 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 5th March 2009, 20:19
  3. Hash function
    By Ioannis in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 7th September 2007, 10:09
  4. ATAN2(,) function
    By vk2tds in forum PBP Wish List
    Replies: 0
    Last Post: - 25th November 2005, 02:52
  5. Random function - How to limit it ??
    By martarse in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 30th November 2004, 14:05

Members who have read this thread : 0

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