Maker Pro
Maker Pro

Thermocouple Interfacing with PIC18F45K80

Djsarkar

Jul 27, 2020
46
Joined
Jul 27, 2020
Messages
46
Hi
What the hardware interface required to connect thermocouple with PIC18F45K80?

I have PIC18F45K80. I am using MPLABX 5.40 and XC8 2.30. I want to Interfacing thermocouple with PIC18F45K80.
I have also operational amplifier UA74CP
 

Attachments

  • Development board.jpg
    Development board.jpg
    74.5 KB · Views: 7
  • themocouple.jpg
    themocouple.jpg
    61.6 KB · Views: 8

Djsarkar

Jul 27, 2020
46
Joined
Jul 27, 2020
Messages
46
You know how to use Google? Microchip has an application note.
I know that thermocouple is used to major the temperature.

These are my doubts i want to understand before to code

1. Can I connect thermocouple directly to pic my board?

2. I have seen that the voltage of thermocouple is very low, so will an operational amplifier required?

3.Would UA74CP be suitable ?

4. Do I need an external ADC with inbuilt operational amplifier. I have mcp3008
 
Last edited:

bertus

Moderator
Nov 8, 2019
2,719
Joined
Nov 8, 2019
Messages
2,719
Hello,

Wich type of thermocouple do you have?
It is likely a K or T type as those are most common.
Have a look at this page for more data:
http://www.lanzo.se/applications/thermocouple.html
Also have a look at the attached PDF for interfacing.

Bertus
 

Attachments

  • 00844a_simplified_thermocouple_interface.pdf
    273.8 KB · Views: 7

bertus

Moderator
Nov 8, 2019
2,719
Joined
Nov 8, 2019
Messages
2,719
Hello,

Did you read the application note I posted?
It has a schematic for J type themocouple and an 3004, but a 3008 could also be used.

Bertus
 

Djsarkar

Jul 27, 2020
46
Joined
Jul 27, 2020
Messages
46
Hello,

Did you read the application note I posted?
It has a schematic for J type themocouple and an 3004, but a 3008 could also be used.

Bertus
I want to connect thermocouple with MCP3008. I don't understand where to connect two wires of thermocouple. CH0 = IN+ CH1 = IN-

I don't want to damage the hardware that's why I asking help

MCP3008.jpg

Code:
#define _XTAL_FREQ 20000000

// PIC18F45K80 Configuration Bit Settings

// CONFIG1L
#pragma config RETEN = ON // VREG Sleep Enable bit (Ultra low-power regulator is Enabled (Controlled by SRETEN bit))
#pragma config INTOSCSEL = LOW // LF-INTOSC Low-power Enable bit (LF-INTOSC in Low-power mode during Sleep)
// SOSCSEL = No Setting
#pragma config XINST = OFF // Extended Instruction Set (Disabled)
// CONFIG1H#pragma config FOSC = HS2 // HS oscillator (high power, 16 MHz-25 MHz
#pragma config PLLCFG = OFF // PLL x4 Enable bit (Disabled)
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor (Disabled)
#pragma config IESO = OFF // Internal External Oscillator Switch Over Mode (Disabled)
// CONFIG2L#pragma config PWRTEN = ON // Power Up Timer (Enabled)
#pragma config BOREN = OFF // Brown Out Detect (Disabled in hardware, SBOREN disabled)
#pragma config BORV = 0 // Brown-out Reset Voltage bits (3.0V)
#pragma config BORPWR = LOW // BORMV Power level (BORMV set to low power level)
// CONFIG2H#pragma config WDTEN = OFF // Watchdog Timer (WDT disabled in hardware; SWDTEN bit disabled)
#pragma config WDTPS = 1 // Watchdog Postscaler (1:1)
// CONFIG3H#pragma config CANMX = PORTC // ECAN Mux bit (ECAN TX and RX pins are located on RC6 and RC7, respectively)
#pragma config MSSPMSK = MSK5 // MSSP address masking (5 bit address masking mode)
#pragma config MCLRE = OFF // Master Clear Enable (MCLR Disabled, RE3 Enabled)
// CONFIG4L#pragma config STVREN = OFF // Stack Overflow Reset (Disabled)
#pragma config BBSIZ = BB1K // Boot Block Size (1K word Boot Block size)
// CONFIG5L#pragma config CP0 = ON // Code Protect 00800-01FFF (Enabled)
#pragma config CP1 = ON // Code Protect 02000-03FFF (Enabled)
#pragma config CP2 = ON // Code Protect 04000-05FFF (Enabled)
#pragma config CP3 = ON // Code Protect 06000-07FFF (Enabled)
// CONFIG5H#pragma config CPB = ON // Code Protect Boot (Enabled)
#pragma config CPD = ON // Data EE Read Protect (Enabled)
// CONFIG6L#pragma config WRT0 = ON // Table Write Protect 00800-01FFF (Enabled)
#pragma config WRT1 = ON // Table Write Protect 02000-03FFF (Enabled)
#pragma config WRT2 = ON // Table Write Protect 04000-05FFF (Enabled)
#pragma config WRT3 = ON // Table Write Protect 06000-07FFF (Enabled)
// CONFIG6H#pragma config WRTC = ON // Config. Write Protect (Enabled)
#pragma config WRTB = ON // Table Write Protect Boot (Enabled)
#pragma config WRTD = ON // Data EE Write Protect (Enabled)
// CONFIG7L#pragma config EBTR0 = ON // Table Read Protect 00800-01FFF (Enabled)
#pragma config EBTR1 = ON // Table Read Protect 02000-03FFF (Enabled)
#pragma config EBTR2 = ON // Table Read Protect 04000-05FFF (Enabled)
#pragma config EBTR3 = ON // Table Read Protect 06000-07FFF (Enabled)
// CONFIG7H#pragma config EBTRB = ON // Table Read Protect Boot (Enabled)
// #pragma config statements should precede project file includes.// Use project enums instead of #define for ON and OFF.
#include <xc.h>
 
#define TRUE 1
#define CS_PIN LATAbits.LATA5 // MCP3204/3208 CS pin
 
void Port_Initialized (void)
{
    ANCON0 = 0; // Set to digital port
    ANCON1 = 0; // Set to digital port
    CM1CON = 0; // Comparator off
    CM2CON = 0; // Comparator off
    ADCON0 = 0; // A/D conversion Disabled
    ADCON1 = 0; // A/D conversion Disabled
    ADCON2 = 0; // A/D conversion Disabled
    
    LATA = 0; // Make all PORTA pins low
    LATB = 0; // Make all PORTB pins low
    LATC = 0; // Make all PORTC pins low
    LATD = 0; // Make all PORTD pins low
    LATE = 0; // Make all PORTE pins low
    
    TRISA = 0b0000000; // Slave Select (SS) RA5/AN4/C2INB/
    TRISB = 0b0000000; // all are output, Unused
    
    //Serial Data Out (SDO) RC5/SDO,
    //Serial Data In (SDI) RC4/SDA/SDI
    //Serial Clock (SCK) RC3/REF0/SCL/SCK
    TRISC = 0b00010000;
    TRISD = 0b0000000; // all are output, show low byte
    TRISE = 0b0000000; // All are output, show high 2 bits
}

void SPI_Init_Master()
{
    SSPSTAT = 0b01000000; // SSPSTAT: MSSP STATUS REGISTER (SPI MODE) SMP=0, CKE=1
    SSPCON1 = 0b00100010; // Master mode,Serial enable
    PIR1bits.SSPIF=0;
}

unsigned char SPI_Xfer(unsigned char Sendchar)
{
    SSPBUF = Sendchar; // Copy data in SSBUF to transmit
    while (!PIR1bits.SSPIF); // Wait for complete 1 byte transmission
    PIR1bits.SSPIF = 0; // Clear SSPIF flag
    return SSPBUF;
}
 void main(void)
{
    unsigned char High_byte; // temporary ADC receive byte - 2 bits only
    unsigned char low_byte; // temporary ADC receive byte
    
    Port_Initialized();
    SPI_Init_Master();
    
    while (1)
    {
        CS_PIN = 0; // Set CS pin low
        SPI_Xfer(0x01); // Send "Start" bit
        High_byte = SPI_Xfer(0b00000000); // 0000 differential CH0 = IN+ CH1 = IN-
        low_byte = SPI_Xfer(0x00); // Send dummy, receive lower 8 bits
        CS_PIN = 1; // Set CS pin high
        LATD = low_byte; // show result on PORTD LEDs
        LATE = High_byte; // show result top 2 bits on PORTE LEDs
        __delay_ms(10); // limit interrogation rate
    }
    
}
 

bertus

Moderator
Nov 8, 2019
2,719
Joined
Nov 8, 2019
Messages
2,719
Hello,

Did you see the schematic on page 8 of the given application note.
It shows the amplifier needed for the thermocouple and the 3004 and pic.

Bertus
 
Top