Menu

Thermometer on MAX6675

Vladimir
2022-03-14
2022-03-15
  • Vladimir

    Vladimir - 2022-03-14

    Hello!
    I want to share a small example of working with a thermocouple on the MAX6675. I used hardware SPI and dynamic indication on a seven-segment indicator. I assembled a device for measuring the temperature in the oven.

    'Chip settings
      #chip 16LF1829, 16
      #config Osc = Int
    
      SPIMode MasterSlow
    
      DIM Temperature as Word ' Temperature value from thermocouple
      DIM SegmentsBuffer(3) as Byte ' Symbol buffer for display on the indicator
      DIM Symbols(13) ' Character values ​​from 0 to 9, empty, E, r
      Symbols = 111, 40, 31, 62, 120, 118, 119, 44, 127, 126, 0, 87, 17
      #define SymbolE 11 
      #define SymbolR 12 
      #define Clear 10   
      #define delay 5    ' Time to display one character
      DIM L_byte as Byte
      DIM Timer as Byte
    
      ' SPI
      #define CS  PortA.5
      #define SCK PortB.6
      #define SO  PortB.4
      Dir SO in
      Dir SCK out
      Dir CS out
      ' 7 Segments
      #define SEG1 PORTA.4
      #define SEG2 PORTA.2
      #define SEG3 PORTB.5
      Dir PORTC out
      Dir SEG1 out
      Dir SEG2 out
      Dir SEG3 out
    
      Wait 1 s
    
      Timer = 100
    
      do Forever
    
        if Timer = 100 then
          call GetTemperature
          Timer = 0
        end if
        call ShowSegments
        Timer = Timer + 1
    
      Loop
    
    
      Sub GetTemperature
    
        CS = 0
        SPITransfer 0, Temperature
        Temperature = FnLSL(Temperature, 8)
        SPITransfer 0, L_byte
        Temperature = Temperature or L_byte
        Temperature = FnLSR(Temperature, 5)
        CS = 1
    
      End Sub
    
      Sub ShowSegments
        if Temperature = 1023 then
          SegmentsBuffer(1) = SymbolE
          SegmentsBuffer(2) = SymbolR
          SegmentsBuffer(3) = SymbolR
        else if Temperature > 99 then
          SegmentsBuffer(1) = Temperature / 100
          SegmentsBuffer(2) = Temperature % 100
          SegmentsBuffer(2) = SegmentsBuffer(2) / 10
          SegmentsBuffer(3) = Temperature % 10
        else if Temperature > 9 then
          SegmentsBuffer(1) = Clear
          SegmentsBuffer(2) = Temperature / 10
          SegmentsBuffer(3) = Temperature % 10
        else
          SegmentsBuffer(1) = Clear
          SegmentsBuffer(2) = Clear
          SegmentsBuffer(3) = Temperature
        end if
        PORTC = Symbols(SegmentsBuffer(1)+1)
        Set SEG1 Off
        Set SEG3 On
        Wait delay ms
        PORTC = Symbols(SegmentsBuffer(2)+1)
        Set SEG3 Off
        Set SEG2 On
        Wait delay ms
        PORTC = Symbols(SegmentsBuffer(3)+1)
        Set SEG2 Off
        Set SEG1 On
        Wait delay ms
    
      End Sub
    



     
  • Anobium

    Anobium - 2022-03-15

    A very nice implementation. I really like the use of the symbols array.

    Can I lift from the forum and include in the demo folders?

     
  • Anobium

    Anobium - 2022-03-15

    I am sure it will be. Your methods are worth it!

     

Log in to post a comment.