Announcement

Collapse
No announcement yet.

Floating point variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Floating point variables

    Hi,
    Is it possible to declare floating point variables or large integers / double words.

    Regards,
    Bobby

  • #2
    I have the exact same question.
    Thanks for any help,

    Regards
    Katy

    Comment


    • #3
      No, Goldelox can only handle 16 bit integers.

      But there is usually a way around any issues in that area.

      What is the calculation you are trying to perform?
      Mark

      Comment


      • #4
        Hi Mark.
        I want to use a BOSCH BME280 combined temp/pressure/humidity sensor on a Diablo 70-DT.
        The math is a combination of everything it seems. signed/unsigned/double words/floats, etc.
        Is there any kind of add-on library or routine for Diablo16 to do complex math?

        http://www.mouser.com/ds/2/621/BST-B...-09-521021.pdf

        Thanks very much!
        Katy

        Comment


        • #5
          You posted this in the Goldelox processor forum.

          Diablo is completely different, it can do floats and large integers, you should be able to do it with the internal functions reference
          Mark

          Comment


          • #6
            Thanks Mark:

            Being very new to 4DGL.. Just not sure how to code a C statement like this in Diablo..
            var1 = (((int64_t)calibration.dig_P9) * (p_acc>>13) * (p_acc>>13)) >> 25;

            But you are helping trying to figure this all out.
            Thanks again.

            Katy

            Comment


            • #7
              Hmm, what a statement.

              So that can be 'simplified' to.

              var1 = (((int64_t)calibration.dig_P9) * (p_acc/ 8192) * (p_acc/8192)) / 33554432;

              and then
              var1 = (((int64_t)calibration.dig_P9) * (p_acc/ 8192)^2) / 33554432;

              Now you need to split everything up and do it in pieces.

              It would be best to try and do everything in float, so check out the various float flt_* functions

              You might be using flt_LTOF() to convert calibration.dig_P9 and p_acc to floats, I have no idea what format they are now.

              flt_VAL to convert the 3354432.

              You can use flt_ITOF() to convert the 8192 to a float, flt_DIV to to the division, flt_MUL to square the number and flt_MUL again to get the left side before a final flt_DIV
              Mark

              Comment


              • #8
                Thanks again Mark.
                I'm thinking of putting the pressure sensor code on an Arduino since there are some good examples of BME280 on GitHub which seem to work pretty well.
                I'm still learning so not sure yet.. Can I write all the graphical stuff in 4DGL/DIABLO and just pass the data serially from Arduino to the display?
                Sounds like a strange way of doing it, but might save time. Diablo16 is a very powerful CPU. A bit sad the compiler does not have different data types without having to resort to making your own arrays by hand.

                All that said, I really appreciate all the help.
                Katy

                Comment


                • #9
                  Seems like a waste of an Arduino.

                  Sure you can do that on Diablo, Genie would probably be easiest.

                  Sure the compiler makes you think about your data type usage more than some compilers, but the net result, hopefully, is that you produce better code.

                  Put in lots of print statements and you can develop your code pretty quickly as you can see all the intermediate results
                  Mark

                  Comment


                  • #10
                    Hi Mark.
                    I'm still struggling on how to get the 64-bit math to work.
                    var2 = var2 + (((int64_t)calibration.dig_P4)<<35);
                    var1 = ((var1 * var1 * (int64_t)calibration.dig_P3)>>8) + ((var1 * (int64_t)calibration.dig_P2)<<12);

                    Wish I was smart enough to write my own "sub-compiler" for Diablo16.

                    Any thoughts?

                    Thanks.
                    Katy

                    Comment


                    • #11
                      Can you give me the full formula 'as in c', as well as a few values and expected answers for me to test with and I'll have a go?

                      Might take a few days for me to get to it though.
                      Mark

                      Comment


                      • #12
                        Hi Mark.
                        Here is one of examples I've been playing with on an Arduino.

                        https://github.com/sparkfun/SparkFun...es/Arduino/src

                        Comment


                        • #13
                          And some 'input' values with the expected answers? (and also the 'calibration values used)
                          Mark

                          Comment


                          • #14
                            Hi again Mark. Do you ever sleep?
                            Seems like every time I post you're always there.
                            Thanks so much for that.

                            Calibration data is a mix of 16-bit signed/unsigned numbers factory programmed into the sensor. So they change sensor to sensor.
                            Raw sensor data is all 8-bit unsigned ( I believe) split up into 8 different registers.

                            I've been searching very hard, and any kind of example I can find wants to use 64-bit math to get the final numbers.

                            Data Sheet of BME 280
                            http://www.mouser.com/ds/2/783/BST-B...-11-844833.pdf

                            Comment


                            • #15
                              Sure, but I'd like some sample figures, as I don't have a BME280 so I can't run any test data through the routines I write.

                              So can you produce some using the ardiono?

                              A few values by creating different temp and humidity values using hot air dryers, ice, boiling water etc.
                              Mark

                              Comment

                              Working...
                              X