No announcement yet.

Help with math with large numbers - Interfacing the TSYS01 Temperature Sensor

  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with math with large numbers - Interfacing the TSYS01 Temperature Sensor

    I hope that someone can help me determine if this is possible using PBP.

    I am getting data from the TSYS01 sensor using I2C, but converting this data to a temperature value requires some math which generates numbers that I do not know how to handle in PBP. I am using an 8 bit PIC18F4620 part. I know how to use longs in PBP, but this goes beyond that I think...

    Here is the conversion taken from the data sheet (also attached). The data sheet also has an example.

    Click image for larger version  Name:	01.JPG Views:	1 Size:	7.1 KB ID:	7387Click image for larger version  Name:	02.JPG Views:	1 Size:	7.9 KB ID:	7388

    The k0 - k4 values can be up to 65535, and the ADC16 value could be up to 65535 as well.

    I appreciate any help finding a way to do this with PBP, thanks!

    Nathan Perry
    Attached Files
    Last edited by NathanPerry; 12-03-2018, 02:02 PM.

  • #2
    I don't think longs would help much.
    this is a seriously small number (-2) * k4 * 10-21 as are the next two terms but they are constants . you could read all the k[x] terms out for that particular chip convert each one to a suitably scaled 64bit constant then complete the calculation using 64 bit N-BIT math

    even doing it with 32bit fp would be challenging to get accurate results ,


    • #3
      I was wrong about using fp32 the result to two dp seems ok (for the ds example any way)

      xc8 version

      const float k[]={-611.715,0.032791,-7.2032e-7,9.9704e-12,-5.6892e-17};//k0 to k4 as constants
      float adc16=36636.0,tres;
      tres =k[4]*adc16*adc16*adc16*adc16;



      • #4
        Thanks for the input!
        I like the idea of hard coding the constants, and that will not be a problem for this particular application.
        I am still trying to do this with PBP though, so now my concern is about the constants that are still very small floating point values (for example k[4] would be -0.000000000000000056892).
        PBP can not do floating point, and I dont know if I can fake it, out to that many decimal places...

        Any ideas on how to get that working on PBP?


        • #5
          there is this thing called nbit math

          you can multiply 5.6892e-17 by 2^64 [the sign must be handled separately] and preload that into a 64 bit var [same idea as how pbp */ and ** commands work]
          then the adc16 value can be loaded into another nbit var
          the multiply can be done =k[4]*adc16*adc16*adc16*adc16 [this may overflow 64bits] [might need 72 bit vars?]
          the result then divided by 2^64 to scale back to normal

          adc16^4 will fit in a 64 bit var
          the other calcs can be done in a similar fashion and the results totaled with respect to their signs

          there are links around on incorporating microchip fp library into pbp code
          {might be 24bit floats though]


          • #6


            • #7
              Thank you for that link, I think I understand what needs to be done now. I will try it and report back soon.

              I have been using PBP for about 10 years now for many types of projects and prototypes and every time I think there is no way im gonna be able to do this with BASIC, I always find a way to do it using PBP...

              Thanks again for pointing me in the right direction!