初学者
10 分钟

使用 G6D-1A-ASI 和 PIC32MZ2048EFM100 保持研究和实验的理想条件

您可信赖的全环境温度计

Thermostat 2 Click with Curiosity PIC32 MZ EF

已发布 6月 25, 2024

点击板

Thermostat 2 Click

开发板

Curiosity PIC32 MZ EF

编译器

NECTO Studio

微控制器单元

PIC32MZ2048EFM100

使用我们的温度测量技术,提前预防潜在的健康风险,该技术旨在为关键环境中的温度波动提供早期预警。

A

A

硬件概览

它是如何工作的?

Thermostat 2 Click设计时没有主要IC;它允许使用外部连接的热传感器。它可以与使用1-Wire®通信的DS1820兼容传感器接口。Click board™配备了一个3针母插座,可以用于安装TO-92封装的DS1820兼容传感器。还配有一个3极螺钉端子,如果传感器需要安装在远程位置(例如加热组件上),则可以使用该端子。螺钉端子与插座共享其线路。通过mikroBUS™的PWM引脚与主机MCU进行1-Wire®通信。根据通过1-Wire®接口获得的温度信息,主机MCU可以采取必要的操作:它可以打开或关闭继电器的触点。Click board™使用了来自欧姆龙的G6D系列PCB电源继电器。这个高质量继电器可以在没有负载连接的情况下承受惊人的大量机械循环。然而,当其输出连接有显著负载时,微电弧会随着时间的推移导致触点磨损。最大负载电流为5A时,它可以承受高达70,000次

循环。其触点由银合金制成,具有出色的最大100mΩ的ON电阻。继电器通过低压侧内置线圈产生的磁场激活。线圈由主机MCU激活。线圈激活的电压为5V,线圈的电流为40mA。MCU无法直接驱动线圈,因此需要添加一个NPN晶体管。其基极由主机MCU控制,允许线圈从5V mikroBUS™电源轨吸取足够的电流。晶体管的基极被路由到Click board™的CS引脚。晶体管在同一外壳中打包了两个偏置电阻,因此可以直接在MCU引脚上使用,而无需外部偏置电阻。标记为ACTIVE的红色LED用于指示晶体管处于打开状态,并且电流正在通过继电器线圈。当线圈(或任何其他电感器)中的电流突然改变时,将产生反电动势,反对电流的变化。这有时会导致控制电路损坏:在这种情况下,晶体管将变为反向极化。为了防止这种情况的发生,在线圈两端添加了一个续流二

极管。在正常操作期间,该二极管不导通任何电流。然而,当线圈关闭时,反向极化将导致电流以最小阻力通过该二极管。这防止了反向(续流)电压的建立,从而保护了晶体管。输出上的触点可能连接到较高电压,并且可能会通过较大的电流。为防止这种情况下的高电压瞬变,续流二极管并不是可行的选择。因此,Thermostat 2 Click使用了压敏电阻(VDR)。当电压升高超过其额定钳位电压时,该组件会迅速降低其电阻。由于它将成为最小阻力的电流路径,因此过量的电压瞬变将通过VDR。在正常操作期间,当电压低于额定钳位电压时,VDR具有非常高的电阻,因此电流通过电路运行。Click board™的工作电压可以通过VCC SEL跳线选择。此跳线允许从mikroBUS™选择3.3V或5V。所选电压将应用于连接的DS1820传感器的VCC引脚。

Thermostat 2 Click hardware overview image

功能概述

开发板

Curiosity PIC32 MZ EF 开发板是一个完全集成的 32 位开发平台,特点是高性能的 PIC32MZ EF 系列(PIC32MZ2048EFM),该系列具有 2MB Flash、512KB RAM、集成的浮点单元(FPU)、加密加速器和出色的连接选项。它包括一个集成的程序员和调试器,无需额外硬件。用户可以通过 MIKROE 

mikroBUS™ Click™ 适配器板扩展功能,通过 Microchip PHY 女儿板添加以太网连接功能,使用 Microchip 扩展板添加 WiFi 连接能力,并通过 Microchip 音频女儿板添加音频输入和输出功能。这些板完全集成到 PIC32 强大的软件框架 MPLAB Harmony 中,该框架提供了一个灵活且模块化的接口

来应用开发、一套丰富的互操作软件堆栈(TCP-IP、USB)和易于使用的功能。Curiosity PIC32 MZ EF 开发板提供了扩展能力,使其成为连接性、物联网和通用应用中快速原型设计的绝佳选择。

Curiosity PIC32MZ EF double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

2048

硅供应商

Microchip

引脚数

100

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
Relay Control
RPD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
1-Wire Data
RPE8
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Thermostat 2 Click Schematic schematic

一步一步来

项目组装

Curiosity PIC32MZ EF front image hardware assembly

从选择您的开发板和Click板™开始。以Curiosity PIC32 MZ EF作为您的开发板开始。

Curiosity PIC32MZ EF front image hardware assembly
GNSS2 Click front image hardware assembly
Prog-cut hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
Board mapper by product7 hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
Necto image step 5 hardware assembly
Necto image step 6 hardware assembly
Curiosity PIC32 MZ EF MCU Step hardware assembly
Necto No Display image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Debug Image Necto Step hardware assembly

软件支持

库描述

该库包含Thermostat 2 Click驱动程序的 API。

关键功能:

  • thermostat2_read_temperature - 该函数读取摄氏温度值。

  • thermostat2_relay_state - 该函数打开/关闭继电器。

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * @file main.c
 * @brief Thermostat 2 Click Example.
 *
 * # Description
 * This example demonstrates the use of Thermostat 2 Click board by reading
 * and displaying the temperature in Celsius and turning the relay on/off 
 * depending on the temperature value.
 * DS1820, DS18S20 and DS18B20 chips can be used in this example. 
 * 
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and performs the Click default configuration.
 *
 * ## Application Task
 * Reads and displays the temperature measured by the Click board on the UART Terminal.
 * If the temperature goes beneath the THERMOSTAT2_TEMPERATURE_LIMIT, 
 * the relay will be turned off while otherwise it will be turned on. 
 * In both cases an appropriate message will be displayed on the terminal. 
 *
 * @author Aleksandra Cvjetićanin 
 *
 */

#include "board.h"
#include "log.h"
#include "thermostat2.h"

static thermostat2_t thermostat2;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    thermostat2_cfg_t thermostat2_cfg;  /**< Click config object. */

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, " Application Init " );

    // Click initialization.
    thermostat2_cfg_setup( &thermostat2_cfg );
    THERMOSTAT2_MAP_MIKROBUS( thermostat2_cfg, MIKROBUS_1 );
    if ( ONE_WIRE_ERROR == thermostat2_init( &thermostat2, &thermostat2_cfg ) ) 
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    if ( THERMOSTAT2_ERROR == thermostat2_default_cfg ( &thermostat2 ) )
    {
        log_error( &logger, " Default config." );
        for ( ; ; );
    }
    
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    static uint8_t relay_state = 0xFF;
    float temperature;
    
    if ( THERMOSTAT2_OK == thermostat2_read_temperature ( &thermostat2, &temperature ) )
    {
        log_printf( &logger, " Temperature: %.2f C\r\n\n ", temperature );
    }
    
    if ( temperature < THERMOSTAT2_TEMPERATURE_LIMIT )
    {
        if ( relay_state != THERMOSTAT2_RELAY_ON )
        {
            log_info( &logger, " Relay is ON.\r\n " );
            thermostat2_relay_state ( &thermostat2, THERMOSTAT2_RELAY_ON );
            relay_state = THERMOSTAT2_RELAY_ON;
        }
    }
    else 
    {
        if ( relay_state != THERMOSTAT2_RELAY_OFF )
        {
            log_info( &logger, " Relay is OFF.\r\n" );
            thermostat2_relay_state ( &thermostat2, THERMOSTAT2_RELAY_OFF );
            relay_state = THERMOSTAT2_RELAY_OFF;
        }
    }
}

int main ( void ) 
{
    /* Do not remove this line or clock might not be set correctly. */
    #ifdef PREINIT_SUPPORTED
    preinit();
    #endif
    
    application_init( );
    
    for ( ; ; ) 
    {
        application_task( );
    }

    return 0;
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。