News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

MAX6675

Started by Oskar-svr, Jan 12, 2022, 05:14 AM

Previous topic - Next topic

Oskar-svr

Hello everyone, who has worked with the MAX6675 thank you

joesaliba

I think I used it once. Will try to find when at my PC.

Joe

Maxi

Here is my code
(you need wait at least 250ms (0.25sec) per read.

Device 18F25K22
Declare Xtal=8

TRISA=%00000000
Declare All_Digital= true
Declare Optimiser_Level = 0

Declare LCD_DTPin PORTB.4
Declare LCD_RSPin PORTB.0
Declare LCD_ENPin PORTB.1
Declare LCD_Interface 4
Declare LCD_Lines 2

DelayMS 500
Cls

Dim HOT As Word
Dim X As Word    
Dim y As Bit
   
Symbol SO  = PORTA.4
Symbol CS  = PORTA.7
Symbol SCK = PORTA.6

'--------------------
Loop1:
  
CS=0
X=SHIn SO,SCK,0,16
CS=1
   
y=GetBit X ,2
If y <> 0 Then X=0

HOT= X >>5

Print At 1,1,"Hot:",Dec HOT,"   "

GoTo Loop1
'--------------------

keytapper

I made a bit of works using two which are sharing the same lines, except for the CS.There may be certain limitation for the MCU to use. I was using for a 16F628A.

$define fractionOf(x) x / 1024

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Proc readMAX6675(which As Byte), Byte
' Procedure to read the 16bit ADC.
  cnty  = 16                        ' reset the counter
  cntx = ~which
  PORTB = PORTB & cntx              ' lower the pin to the first device
  Set CLK                           ' preparing the clock pin
  Clear y                           ' resetting the variable for the result
  Clear GIE                         ' atomic operation no interrupts
  ' next instruction gives a little delay before reading the input
loop80:
    Clear CLK                       ' ticking the serial clock
    Nop                             ' adding delay to make sure it won't fail
    y = y << 1                      ' shift left the variable MSB first
    Set CLK                         ' reset the clock
    Btfsc MaxDT                     ' if bit zero will remain zero
    Bsf  _Y,0
    Decfsz cnty,F                   ' repeat for all needed bits
    GoTo loop80                     ' loop for the next bit
  Set GIE                           ' atomic operation completes, OK interrupts
  PORTB = PORTB | which             ' accordingly to the entered choice
  If y.2 = TRUE Then                ' if bit 2 is high an error has occured
    Result = $ff                    ' signal it with highest value
  Else
    y = y >> 5                      ' Approximation to 1 degree Celsius
    Clear Result
    If y > MINTEMP Then
      Result = y - MINTEMP          ' reduced to a single byte, within the range
    End If
    If no_PID = TRUE Then           ' controlling without a PID
      If y.highbyte <> 0 Then       ' when exceed one byte it's problem
        Set Result                  ' signal it with highest value
      End If
    End If
  End If
EndProc

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Proc TEMPctrl(currtemp As Byte, pos As Byte), Byte
' procedure to implent a PID control
' currtemp is for the measured input
' Setpoint is a global value that tell the limit to achieve
' pos is used to map a position in RAM where the data are stored. So the caller
' will obtains its own results
' no_PID is for skipping PID function and operating just as ON/OFF method

  Dim integral As SByte             ' integral term for PID
  Dim previous_error As SByte       ' memory for last error
  Dim derivative As SByte           ' derivative term for PID
  Dim err As SByte                  ' error calculation
  Dim tmp As SDword                 ' 32bit signed scratch variable

  If currtemp < MINTEMP Then        ' the heater didn't reach above minimum
    Result = 100                    ' result will be maximum
    ExitProc                        ' end return
  End If
  cnty = FSR                        ' preserve the register, just in case
  FSR = AddressOf(tempdata) + pos   ' restore the data, loding the area to use
  cntx = FSR
  integral = INDF                   ' into the necessary variables
  Inc FSR
  previous_error = INDF
  pos = pos * 4
  Kp = ERead pos
  Inc pos,2
  Ki = ERead pos
  Inc pos,2
  Kd = ERead pos
  err = Setpoint - currtemp         ' start the calculation
  tmp = err * fractionOf(Kp)        ' evaluate the proportional term
  integral = integral + err         ' add the integral
  ' keep into a reasonable limit
  If integral < 0 Then integral = 0
  If integral > 100 Then integral = 100
  ' calculate the integral term
  tmp = tmp + integral * fractionOf(Ki)
  derivative = err - previous_error
  ' complete the summation
  tmp = tmp + derivative * fractionOf(Kd)
  If tmp < 0 Then  tmp = 0
  If tmp > 100 Then tmp = 100       ' limiting for the necessary
  Result = tmp                      ' convert into a single byte
  FSR = cntx                        ' Save the data, so it's possible to swap
  INDF = integral
  Inc FSR
  INDF = err                        ' save the error, for the next occurence
  FSR = cnty
EndProc
There is the feature to opt on two output.
Ignorance comes with a cost

normnet

See:
C:\Program Files (x86)\ProtonIDE\Plugin\VHBExplorer\VHBoards\VSM for PIC18\MAX6675 Thermometer

Oskar-svr

Thank you very much everyone for your help, greetings :)