2082 views|1 replies

1w

Posts

25

Resources
The OP
 

Approximate power functions using the extremum method [Copy link]

 

Because MakeCode has a problem calculating the power function, the altitude calculation result of the pressure sensor is always 0. Today, the MakeCode development team said that the power function requires 4K of program space and the chip space is insufficient, so it cannot be used ( https://github.com/microsoft/pxt-microbit/issues/2192#issuecomment-515120256 ). So I wonder if there is another way to calculate.

The formula for calculating height is as follows:

altitude = ((pow((101325 / pressure(Pa), 1/5.257) - 1.0) * (temperature(C) + 273.15)) / 0.0065

Because the atmospheric pressure ranges from 860-1060hPa, the power function part can be regarded as (1+x)^N, where x is close to 0, so the power function can be approximated using the extreme number method.

    function apow(x: number, n: number): number {
        let d = x - 1
        return 1 + (n * d) + (n * (n - 1) * d * d) / 2
    }

I made a simple comparison using this method and found that the error of the calculated height is very small. Please refer to the complete program:

https://github.com/makecode-extensions/LPS22


This content is originally created by dcexpert , a user of EEWORLD forum. If you want to reprint or use it for commercial purposes, you must obtain the author's consent and indicate the source

This post is from MEMS sensors
 
 

1w

Posts

25

Resources
2
 

When only the first-order polynomial is expanded, the calculation error is large. Using the second-order polynomial is almost sufficient for general calculations. If it doesn't work, you can calculate more orders.

This post is from MEMS sensors
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list