STM32 with AD8495 Thermocouple Amplification

by Marwen Maghrebi

In this article, we will explore how to integrate STM32 with the AD8495 amplifier for K-Type thermocouple temperature sensing.

STM32 microcontroller interfacing with AD8495 for thermocouple temperature measurements.

Things used in this project

Software apps and online services

1- STMicroelectronics STM32CubeMX

2- STMicroelectronics STM32CubeIDE

3- Proteus 8

Exploring Temperature Sensing Applications with STM32 and AD8495:

In this project, we will delve into the intricacies of utilizing an STM32 microcontroller alongside the AD8495 K-type thermocouple amplifier. Thermocouples are renowned for their sensitivity, necessitating a robust amplifier with cold-compensation reference. While digital thermocouple amplifiers are readily available, the introduction of an exceptional analog-output amplifier adds versatility to temperature sensing applications

Understanding the AD8495 K-Type Thermocouple Amplifier:

The AD8495 K-type thermocouple amplifier from Analog Devices simplifies temperature sensing with its user-friendly design. Featuring comprehensive documentation on the back of its compact PCB, the AD8495 facilitates effortless integration. Powering the board with 3-18VDC and measuring the output voltage on the OUT pin allows for straightforward conversion of voltage to temperature.

Key Features of the AD8495 Amplifier:

  • Works exclusively with K-type thermocouples, ensuring compatibility and accuracy.
  • Offers an easy-to-use analog output, streamlining the temperature measurement process.
  • Provides a wide temperature range: with 5V power, from -250°C to +750°C output (0 to 5VDC), and with 3.3V power, from -250°C to +410°C output (0 to 3.3VDC), subject to the thermocouple’s handling capabilities.

Powering and Integrating the AD8495 into the Project:

  • Flexible Power Options: Seamlessly power the board using either 3.3V or 5V, allowing engineers to tailor the temperature range based on application specifications. This versatility ensures compatibility with a wide range of power sources, enhancing the amplifier’s adaptability to diverse operating conditions.

To commence this endeavor, we initiate ADC Independent mode configuration, followed by the setup of ADC conversion in regular mode. Subsequently, we establish UART communication to facilitate the transmission of both ADC readings and system status

STM32CubeMX Configuration:

  • Open CubeMX & Create New Project Choose The Target MCU STM32F103C6 & Double-Click Its Name
  • Go To The Clock Configuration & Set The System Clock To 8MHz

Configuration for the ADC Mode:

  • In the Categories tab, select the [ADC1, enable IN2]
  • In the Parameter settings tab, ADC Settings : Enable Continuous Conversion Mode
  • In the Parameter settings tab, ADC_Regular_Conversion Mode: [Enabler Regular Conversion Mode & Number of Conversio : 1 & External Trigger Conversion source : Regular Conversion launched by software & Rank1: channel : 2, sympling Time :1.5 Cycles]

Configuration for the UART mode:

  • Enable USART1 Module (Asynchronous Mode)
  • Set the USART1 communication parameters (baud rate = 9600, parity=NON, stop bits =1, and word length =8bits)
  • Generate The Initialization Code & Open The Project In CubeIDE

STM32CubeIDE Configuration :

  • Write The Application Layer Code
  • main.c
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include"stdio.h"
#include<string.h>
/* Private variables ---------------------------------------------------------*/
ADC_HandleTypeDef hadc1;
UART_HandleTypeDef huart1;

/* USER CODE BEGIN PV */
int val = 0; // Variable to store the value read
float TempC; // Temperature value in Celsius degree
float TempF; // Temperature value in Fahrenheit degree
float gain = (3.3/(4096-1)) ; // gain = STM23_Vref/(2^12-1) STM32 ADC 12bit resolution
float vref = 2.5; //  datasheet : Reference  value 2.5V for adjustment
float Output_Voltage= 0.005; // datasheet : 5 mV/°C for J type and K type
char buffer[100];
/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_ADC1_Init(void);
static void MX_USART1_UART_Init(void);

int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();

/* USER CODE BEGIN 2 */
if(HAL_ADC_Start(&hadc1)!=HAL_OK)
{
Error_Handler();
}
/* USER CODE END 2 */

while (1)
{
while(HAL_ADC_PollForConversion(&hadc1, HAL_MAX_DELAY)!=HAL_OK)
{
Error_Handler();
}
val = HAL_ADC_GetValue(&hadc1); // Read the input from ADC
TempC = (( (float)(val) * gain)-vref)/ Output_Voltage; // -ref Convert ADC value to Celsius degree
TempF = (TempC * 1.8) + 32.0;
sprintf(buffer, "Temperature: %.2f Degrees Celsius, %.2f  Degrees Fahrenheit\r\n", TempC,TempF);
HAL_UART_Transmit(&huart1, (uint8_t *)buffer, strlen(buffer), HAL_MAX_DELAY);
HAL_Delay(500);
}
}

Proteus Configuration :

  • Open Proteus & Create New Project and click next
  • Click on Pick Device
  • Search for STM32F103C6 & TCK & CONN3 & RES & AD8495 & VSOURCE
  • Click on Virtual Instruments Mode then choose VIRTUAL TERMINAL & DC VOLTMETRE 
  • Click on Terminal Mode then choose (DEFAULT & POWER &GROUND)
  • finally make the circuit below and start the simulation
STM32 K-Type Thermocouple Amplification Circuit with AD8495

That’s all!

If you have any questions or suggestions don’t hesitate to leave a comment below

You Might Also Like

Leave a Comment


Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00