Having trouble with SERIN command and MAX6675


Closed Thread
Results 1 to 40 of 40

Hybrid View

  1. #1
    Join Date
    Dec 2010
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    is the code you gave specifically for the 16f630?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    No. The code shows how to use the MAX chip.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Dec 2010
    Posts
    48


    Did you find this post helpful? Yes | No

    Default

    i found in this post (http://www.picbasic.co.uk/forum/show...1178#post71178) that you stated you need a temperature
    reference for every time the wire material from the thermocouple changes.

    Anyplace the wire material changes you need a reference temperature and calcs. A couple exceptions here and there though.
    I had copper wire soldered to the terminals on my thermocouple. I disconnected the copper wires but it didn't help
    Last edited by emerson; - 10th December 2010 at 20:47.

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Do you have pin #6 (CS) on the MAX6675 pulled low? I use a 10K to the zero rail on mine.
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    MAX6675 need more than 200 millisecs for the temperature convertion. You are polling too fast so you don't get any response. Place a delay of 250 msecs to allow convertion.

    edit:My note was reffered to code seen in post#5. I just see that you added delay 500 in your code in post #7, so my answer is obsolete.
    My new suggestion are :

    add INCLUDE "modedefs.bas" on top of your code
    and modify your SHIFTIN command adding:

    shiftin MXSO, MXSCLK, MSBPRE, [MXTemp\16] 'read the data to MXTemp

    and see if it works.



    Al.
    Last edited by aratti; - 11th December 2010 at 11:51.
    All progress began with an idea

  6. #6
    Join Date
    Aug 2006
    Location
    SWITZERLAND (french speaking)
    Posts
    938


    Did you find this post helpful? Yes | No

    Default it's working... but bit-shifting not clear to me :-(

    Hi,

    It's my first time using a MAX6675 k-type thermocouple converter and got it to work thanks to (99%) of the info in this thread .

    AAMOF, I had to modify one info found above and it is about bit shifting.

    First, my working code (and hopefully correct) is:
    Code:
    ' ====== FUSES ====================================================================================
    ' PIC 16F690
    @ __Config _FCMEN_OFF &_IESO_OFF &_CPD_OFF &_WDT_OFF &_INTRC_OSC_NOCLKOUT &_BOR_OFF &_CP_OFF &_PWRTE_OFF &_MCLRE_OFF 
    
    ' ====== REGISTERS ================================================================================
    '             76543210
    OPTION_REG = %10000000 ' PORT A&B Pull-Ups disabled (see WPUA & WPUB)
    OSCCON     = %01100000 ' Internal RC set to 4Mhz - not to be used with XTal
    ANSEL      = %00000000 ' Analog inputs Channels Bit<0>=0 to Bit<7>=7
    ANSELH     = %00000000 ' Analog inputs Channels Bit<0>=8 to Bit<3>=11 
    ADCON0     = %00000000 ' A/D Module OFF 
    CM1CON0    = %00000000 ' Comparator1 Module is OFF
    CM2CON0    = %00000000 ' Comparator2 Module is OFF
    INTCON     = %00000000 ' INTerrupts CONtrol
    PORTA      = %00000000 ' Ports High/Low (0 to 5)
    TRISA      = %00000000 ' Set Input/Output (0 to 5)
    PORTB      = %00100000 ' Ports High/Low (4 to 7) B5=MAX6675-CS
    TRISB      = %00010000 ' Set Input/Output (4 to 7) B4=MAX6675-SDO
    PORTC      = %00000000 ' Ports High/Low (0 to 7)
    TRISC      = %00000000 ' Set Input/Output (0 to 7)
    
    ' ====== DEFINES ==================================================================================
    DEFINE OSC 4
    
    DEFINE SHIFT_PAUSE 250  'for MAX6675 conversion time
    
    DEFINE LCD_DREG PORTC   'LCD data port 
    DEFINE LCD_DBIT 0       'LCD data starting bit 0 or 4 on µC 
    DEFINE LCD_RSREG PORTC  'LCD Register Select port 
    DEFINE LCD_RSBIT 4      'LCD Register Select bit 
    DEFINE LCD_EREG PORTC   'LCD Enable port 
    DEFINE LCD_EBIT 5       'LCD Enable bit 
    DEFINE LCD_BITS 4       'LCD bus size 4 or 8 
    DEFINE LCD_LINES 2      'Line number on LCD 
    
    ' ====== VARIABLES ================================================================================
    MAX6675_SDO var PORTB.4
    MAX6675_CS  var PORTB.5
    MAX6675_SCK var PORTB.6
    
    RawTemp     var word
    RawTemp     = 0
    Temp        var byte
    Temp        = 0
    TempUnit    var byte
    TempUnit    = 0
    TempDec     var byte
    TempDec     = 0
    
    ' ====== PROGRAM ==================================================================================
    
    PAUSE 500   ' time for LCD to settle
    
    MAX6675_READ:    
    
      MAX6675_CS = 0
      shiftin MAX6675_SDO,MAX6675_SCK,0,[RawTemp\16] 'mode is MSBPRE
      MAX6675_CS = 1
      
      Temp = RawTemp >> 2
    
      TempUnit = Temp / 10 'get temperature Units for display
      TempDec =  Temp MOD 10 'get temperature Decimals for display
      lcdout $FE, $80,"BIN ", BIn16 Rawtemp
      lcdout $FE, $C0,"Tmp ", DEC TempUnit,".",dec TempDec," C"
      
      PAUSE 1000
      
    GOTO MAX6675_READ
    END
    According to the MAX6675 datasheet: "Read the 16 output bits on the falling edge of the clock. The first bit, D15, is a dummy sign bit and is always zero. Bits D14–D3 contain the converted temperature in the order of MSB to LSB".

    If I get it well, when reading the termocouple, I get 16 bits and I need to "keep" bits 14 to 3.
    Name:  2017-04-15 21_53_35-MAX6675K-Type Thermocouple IC.pdf - SumatraPDF.jpg
Views: 2015
Size:  21.4 KB

    So, to get the (what I hope is correct) right value, why do I have to shift by "2" instead of what has been said above (shift by 3) or even shift by 1 since bit 14 is the second bit to start with?
    Roger

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: it's working... but bit-shifting not clear to me :-(

    Unless you are trying to get the fractional part of the reading 10 bits is all you need.
    Dave
    Always wear safety glasses while programming.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts