Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 09:57 20 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : BME280 'horrible' expression.

Author Message
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1326
Posted: 04:57am 24 Jan 2023
Copy link to clipboard 
Print this post

Back in 18/2/2016 here Peter deciphered the "ridiculous" (his expresion) programming interface for the BME280 Bosch pressure sensor and wrote MMBasic code for it. I've been running it successfully on the PicoMite for some time but whenever I want to modify the main program I have trouble loading one very long line in the code from Teraterm using either AUTOSAVE or XMODEM. Here's the culprit line:

v_x1=(((((adc_H<<14)-((H4)<<20)-(H5*v_x1))+16384)\ q(15))*(((((((v_x1*H6)\ q(10))*(((v_x1*H3)\ q(11))+32768))\ q(10))+2097152)*H2+8192)\ q(14)))

I've tried to reduce it to shorter lines using some dummy variables but it's not obvious where the line can be 'broken'. I also wonder whether there's a problem with the brackets because by my count there are 23 of "(" but only 22 of ")". It runs properly though so maybe the spare or missing one is redundant.

Can someone have a go for me to reduce this line to say three lines or so.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1094
Posted: 06:47am 24 Jan 2023
Copy link to clipboard 
Print this post

@paceman

The following may be helpful.


' pseudo code showing indentation

v_x1=(
       (
          (
             (
                (adc_H<<14)-
                    (
                       (H4)<<20
                    )-
                       (H5*v_x1)
             )+16384
          )\ q(15)
       )*
       (
          (
             (
                (
                   (
                      (
                         (v_x1*H6)\ q(10)
                      )*
                      (
                         (
                            (v_x1*H3)\  q(11)
                         )+32768
                      )
                   )\ q(10)
                )+2097152
             )*H2+8192
          )\ q(14)
       )
    )
' end pseudo code

' original split into 3 shorter segments
'  - Note: you need two temporary variables v-tmp1 and v-tmp2
 
v-tmp1= ((((adc_H<<14)-((H4)<<20)-(H5*v_x1))+16384)\ q(15))

v-tmp2= (((((((v_x1*H6)\ q(10))*(((v_x1*H3)\ q(11))+32768))\ q(10))+2097152)*H2+8192)\ q(14))

v_x1 = v-tmp1 * v-tmp2



The number of opening and closing parenthesis is correct at 23 for both.

The only anomaly I can see is in the second statement (v-tmp2), which I have highlighted in red -  I don't know if the order of the multiply followed by addition is correct (just don't know enough about the BME280)
Regards,
Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
paceman
Guru

Joined: 07/10/2011
Location: Australia
Posts: 1326
Posted: 11:03am 24 Jan 2023
Copy link to clipboard 
Print this post

Doug, you're my saviour. That works perfectly, or at least it gives the same pressure as Peter's original code so that'll do me!
I counted the opening/closing brackets twice and came up with the 23/22 split both times. Just blind somewhere I guess but your pretty 'staircase' is nice and I hadn't thought of doing that. The order of the multiply and divide was my problem too so I think we'll stick with your solution that works. It's a horrible expression though isn't it, I'm glad Peter sorted it so I didn't have to!  
Greg
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024