News:

Let's find out together what makes a PIC Tick!

Main Menu

MS5611

Started by joesaliba, Aug 15, 2023, 04:01 PM

Previous topic - Next topic

joesaliba

I am giving another try to the MS5611 pressure sensor.

Is it possible to get suitable readings using a PIC18F14K22?

It needs some 64 bit variable to do some calculations.

Has anyone got a good reading out of these devices?

Regards

Joe

trastikata

#1
Quote from: joesaliba on Aug 15, 2023, 04:01 PMIt needs some 64 bit variable to do some calculations.

Has anyone got a good reading out of these devices?

I did pressure sensors test couple years ago and made a new PCB where I placed all sensors on the same board with PIC18F4553:

MP3H6115A;MPL3115A2;BMP180;BMP280;MS5611;BMP85P;LPS25HB;MS5607;MS5637;BME280;SPL06-001

The purpose was to see how they behave compared to each other in different conditions, temperature drift etc- thus I needed a close to simultaneous pressure data.

Anyway MS5611 and neither of those require 64-bit computations, everything was done on a PIC18F4553. The code is quite old and written in a haste with no commenting but can serve you as a starting point.

Here are some screenshots from those tests, SPL06-001 was really crappy Chinese copy of BMP280 so I excluded it from the data table.

SETUP_SENSOR_MS5611:
    Low CS_MS5611
        spi_byte = $1E : GoSub SPI_SEND : GoSub CHOOSE_5MS_DELAY
    High CS_MS5611
   
    Low CS_MS5611
        spi_byte = $A2 : GoSub SPI_SEND
        GoSub SPI_READ : c1_MS5611.Byte1 = spi_byte
        GoSub SPI_READ : c1_MS5611.Byte0 = spi_byte
    High CS_MS5611
    Low CS_MS5611
        spi_byte = $A4 : GoSub SPI_SEND
        GoSub SPI_READ : c2_MS5611.Byte1 = spi_byte
        GoSub SPI_READ : c2_MS5611.Byte0 = spi_byte
    High CS_MS5611
    Low CS_MS5611
        spi_byte = $A6 : GoSub SPI_SEND
        GoSub SPI_READ : c3_MS5611.Byte1 = spi_byte
        GoSub SPI_READ : c3_MS5611.Byte0 = spi_byte
    High CS_MS5611
    Low CS_MS5611
        spi_byte = $A8 : GoSub SPI_SEND
        GoSub SPI_READ : c4_MS5611.Byte1 = spi_byte
        GoSub SPI_READ : c4_MS5611.Byte0 = spi_byte
    High CS_MS5611
    Low CS_MS5611
        spi_byte = $AA : GoSub SPI_SEND
        GoSub SPI_READ : c5_MS5611.Byte1 = spi_byte
        GoSub SPI_READ : c5_MS5611.Byte0 = spi_byte
    High CS_MS5611
    Low CS_MS5611
        spi_byte = $AC : GoSub SPI_SEND
        GoSub SPI_READ : c6_MS5611.Byte1 = spi_byte
        GoSub SPI_READ : c6_MS5611.Byte0 = spi_byte
    High CS_MS5611
Return

START_MS5611_PRESSURE:
    Low CS_MS5611
        spi_byte = $48 : GoSub SPI_SEND '4096 OS   
    High CS_MS5611   
Return

START_MS5611_TEMPERATURE:
    Low CS_MS5611
        spi_byte = $52 : GoSub SPI_SEND '512 OS
    High CS_MS5611 
Return

READ_MS5611_PRESSURE:
    Low CS_MS5611
        spi_byte = $00 : GoSub SPI_SEND
        GoSub SPI_READ : MS5611_pressure.Byte2 = spi_byte
        GoSub SPI_READ : MS5611_pressure.Byte1 = spi_byte
        GoSub SPI_READ : MS5611_pressure.Byte0 = spi_byte
    High CS_MS5611       
Return

READ_MS5611_TEMPERATURE:
    Low CS_MS5611
        spi_byte = $00 : GoSub SPI_SEND
        GoSub SPI_READ : MS5611_temperature.Byte2 = spi_byte
        GoSub SPI_READ : MS5611_temperature.Byte1 = spi_byte
        GoSub SPI_READ : MS5611_temperature.Byte0 = spi_byte
    High CS_MS5611
Return

CALCULATE_MS5611_PRESSURE:
    MS5611_X1 = c5_MS5611 * 256
    MS5611_X1 = MS5611_temperature - MS5611_X1 ' dT
    MS5611_X2 = MS5611_X1 / 8388608 
    MS5611_X2 = (MS5611_X2 * c6_MS5611) + 2000 
    MS5611_X2 = MS5611_X2 / 100
    s_temperature = MS5611_X2
   
    MS5611_B6 = c4_MS5611 / 16384
    MS5611_B6 = MS5611_B6 * c5_MS5611 
    MS5611_B5 = MS5611_temperature / 32768
    MS5611_B4 = c4_MS5611 / 128
    MS5611_B3 = c2_MS5611 * 2
    MS5611_X1 = MS5611_B4 * MS5611_B5
    MS5611_X1 = MS5611_X1 - MS5611_B6
    MS5611_X1 = MS5611_X1 + MS5611_B3
    MS5611_B6 = c5_MS5611 / 1024
    MS5611_B5 = c3_MS5611 / 32
    MS5611_B6 = MS5611_B6 * MS5611_B5
    MS5611_B5 = MS5611_temperature / 32768
    MS5611_B4 = c3_MS5611 / 256
    MS5611_B5 = MS5611_B5 * MS5611_B4
    MS5611_B4 = c1_MS5611 - MS5611_B6 + MS5611_B5
    pressure = MS5611_pressure / 2097152
    pressure = (pressure * MS5611_B4) - MS5611_X1
Return


PS1.jpg

PS2.jpg

joesaliba

Thanks Trastikata,

I will try change your code as I am using I2C and work with your calculations.

Thank you

Joe


joesaliba

Hi Trastikata,

If you find some time, can you please add what variable types are X1, X2 B4, B5, B6, s_temperature and pressure?

Thank you

Joe


trastikata

Quote from: joesaliba on Aug 16, 2023, 07:31 PMIf you find some time, can you please add what variable types are X1, X2 B4, B5, B6, s_temperature and pressure?

I realized you might need that, but forgot to add it yesterday, here it is:

Dim c1_MS5611 As Word
Dim c2_MS5611 As Word
Dim c3_MS5611 As Word
Dim c4_MS5611 As Word
Dim c5_MS5611 As Word
Dim c6_MS5611 As Word

Dim s_temperature As SByte
Dim MS5611_temperature As Dword
Dim MS5611_pressure As Dword

Dim MS5611_X1 As Float
Dim MS5611_X2 As Float
Dim MS5611_B3 As Float
Dim MS5611_B4 As Float
Dim MS5611_B5 As Float
Dim MS5611_B6 As Float

joesaliba

Thank you Trastikata.

Joe