View previous topic :: View next topic |
Author |
Message |
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Feb 04, 2024 3:32 pm Post subject: |
|
|
The following constant holds contradictory settings, while the datasheet does not tell about negative effects. Code: | Max_31865_config_register = &B11100011 |
At least the Python code from the link below does it logically and differently.
First readout in the shown code is a POR- and no temperature-value. For a temperature-value there must be 62.5ms from start till readout.
Python lib for reference:
https://github.com/adafruit/Adafruit_CircuitPython_MAX31865/blob/main/adafruit_max31865.py
To test the SPI-interface, connect MOSI and MISO of the ATM328 and use SPIMove() |
|
Back to top |
|
|
murmel
Joined: 13 Oct 2014 Posts: 17
|
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Tue Feb 06, 2024 8:46 pm Post subject: |
|
|
And this epiphany took you a month.
Interestingly the error was not in the code you've copied from:
https://www.roboternetz.de/community/archive/index.php/t-75139.html
Code: | Dim Element As Integer
Dim Element_l As Byte At Element Overlay
Dim Element_h As Byte At Element + 1 Overlay |
Looks you fooled yourself and anyone else believing that communication μC <> Max doesn't work.
However you got a bonus by admitting it.
And btw.
MWS wrote: | The following constant holds contradictory settings, while the datasheet does not tell about negative effects. Code: | Max_31865_config_register = &B11100011 |
|
For auto sampling mode Configuration Register VBias (D7) must be ON/1 and Conversion Mode (D6) must be Auto/1, but 1-shot (D5) has to be 0, as this is for starting a single shot conversion.
One of my qualms was whether 1-shot (D5) returning to 0 may affect Conversion Mode (D6) switching to single shot, giving the impression to have a dead bug, the datasheet did not tell about.
Init for auto conversion with 50Hz filter and fault clear thus has to be:
Code: | Max_31865_config_register = &B11000011 |
For single shot mode Register VBias (D7) is OFF/0 and Conversion Mode (D6) Normally off/0.
This way the init byte would look like:
Code: | Max_31865_config_register = &B00000011 |
To trigger a readout:
- Switch VBias ON, D7 = 1
Code: | Max_31865_config_register = &B10000011 |
- Wait 10ms for VBias to stabilize
- Set 1-shot, D5 = 1
Code: | Max_31865_config_register = &B10100011 |
- CS must return to high after the 1-shot bit D5 is written, as this triggers conversion.
- Wait 65ms for end of conversion
- Read RTD
- Switch VBias OFF, 1-shot D5 clears to 0 automatically.
Code: | Max_31865_config_register = &B00000011 |
Single shot is beneficial for power consumption and can improve accuracy, as then bias current does less heating of the PT-sensor.
It becomes important if the sensor is thermally only loosely coupled to the medium to measure. |
|
Back to top |
|
|
murmel
Joined: 13 Oct 2014 Posts: 17
|
Posted: Sun Feb 11, 2024 8:07 am Post subject: |
|
|
I translated the Arduino library to BASCOM. Another thermometer gives almost the same values.
The problem is now solved. Another tip, some MAX31865 modules had an incorrect R-Ref.
I would like to thank everyone who made helpful contributions.
Here is the working code.
Code: |
'**************************************************************************************************
'
' Programmcode z.T. von H.Kipnik https://www.roboternetz.de/community/archive/index.php/t-75139.html
'
' https://www.analog.com/media/en/technical-documentation/data-sheets/max31865.pdf
' https://www.arduino.cc/reference/de/
'
'**************************************************************************************************
$regfile = "m32def.dat" ' CPU
$crystal = 16000000 ' Frequenz
$baud = 19200 ' use baud rate
$hwstack = 80 ' HW stack
$swstack = 80 ' SW stack
$framesize = 80 ' Frame space
Config Lcd = 20x4
Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7 , E = Portc.7 , Rs = Portc.6
Config Lcdbus = 4
Cursor Off : Cls
Config Portb.1 = Output ' Backlight LCD
Portb.0 = 1
Config Portb.2 = Output
Max_cs Alias Portb.2
Max_cs = 1
Config Portb.4 = Output ' SPI Master einschalten
Portb.4 = 1
Waitms 500
Config Spi = Hard , Interrupt = Off , Data_order = Msb , Master = Yes , Polarity = High , Phase = 1 , Clockrate = 4 , Noss = 1
Spiinit
Const Rtd_a = 3.9083e -3
Const Rtd_b = -5.775e -7
Const Rnominal = 1000
Const Rref = 4300
Dim Rtd As Integer 'Integer
Dim Rtd_l As Byte At Rtd Overlay
Dim Rtd_h As Byte At Rtd + 1 Overlay
Dim Temperatur As Single 'Single
Dim Z1 As Single : Dim Z2 As Single
Dim Z3 As Single : Dim Z4 As Single
Dim Rt As Single
Dim Rpoly As Single
Dim Hv As Single ' Hilfsvariablen
Dim Hv2 As Single
Dim Max_31865_write_address As Byte
Dim Max_31865_read_address As Byte
Dim Max_31865_config_register As Byte ' config register
Max_31865_write_address = &B10000000 ' Config writeaddress
Max_31865_read_address = &B00000001 ' RTD Read Address
Max_31865_config_register = &B11100011 ' MAX-configuration
Max_cs = 0
Spiout Max_31865_write_address , 1 ' write config register
Spiout Max_31865_config_register , 1
Max_cs = 1
'******************** Mainloop ***********************
Do
Max_cs = 0 ' read RTD
Spiout Max_31865_read_address , 1
Spiin Rtd_h , 1
Spiin Rtd_l , 1
Max_cs = 1
Shift Rtd , Right , 1 ' 16bit -> 15Bit
'************* Temperature calculation *************
Rt = Rtd
Rt = Rt / 32768
Rt = Rt * Rref
Z1 = Rtd_a * -1
Z2 = Rtd_a * Rtd_a
Hv = Rtd_b * 4
Z2 = Z2 - Hv
Z3 = Rtd_b * 4
Z3 = Z3 / Rnominal
Z4 = Rtd_b * 2
Temperatur = Z3 * Rt
Temperatur = Temperatur + Z2
Temperatur = Sqr(temperatur )
Temperatur = Temperatur + Z1
Temperatur = Temperatur / Z4
If Temperatur < 0 Then
Rt = Rt / Rnominal
Rt = Rt * 100
Rpoly = Rt
Temperatur = -242.02
Hv2 = 2.2228 * Rpoly
Temperatur = Temperatur + Hv2
Rpoly = Rpoly * Rt
Hv2 = 2.5859e -3 * Rpoly
Temperatur = Temperatur + Hv2
Rpoly = Rpoly * Rt
Hv2 = 4.8260e -6 * Rpoly
Temperatur = Temperatur - Hv2
Rpoly = Rpoly * Rt
Hv2 = 2.8183e -8 * Rpoly
Temperatur = Temperatur - Hv2
Rpoly = Rpoly * Rt
Hv2 = 1.5243e -10 * Rpoly
Temperatur = Temperatur + Hv2
End If
Locate 1 , 8 ' Display for checking the variables
Lcd " "
Locate 2 , 8
Lcd " "
Locate 3 , 8
Lcd " "
Locate 4 , 6
Lcd " "
Locate 1 , 1
Lcd "RTD_h: " ; Rtd_h
Locate 2 , 1
Lcd "RTD_l: " ; Rtd_l
Locate 3 , 1
Lcd "RTD : " ; Rtd
Locate 4 , 1
Lcd "Temp: " ; Temperatur
Waitms 500
Loop
|
greetings
Murmel |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Feb 11, 2024 9:27 am Post subject: |
|
|
murmel wrote: | some MAX31865 modules had an incorrect R-Ref. |
I would expect it, simply because of the R's limited precision, for calibrating the sensor the constant Rref has to be adjusted.
In case this incorrect value exceeds its specs, what inaccuracy you are talking about?
Ah, one more hint, even I'm not sure it will fall on fertil ground, as your reaction to hints is rather slow or nonexistent.
Did you notice Z1..Z4 never change?
These can be pre-calculated as constants, spares some SRam and processor cycles. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|