中级
30 分钟

使用ADS1230和ATmega32测量物体的力或重量

力计

Load Cell 7 Click with EasyAVR v7

已发布 6月 26, 2024

点击板

Load Cell 7 Click

开发板

EasyAVR v7

编译器

NECTO Studio

微控制器单元

ATmega32

桥接传感应用的完整前端解决方案。

A

A

硬件概览

它是如何工作的?

Load Cell 7 Click 基于 ADS1230,这是一款来自德州仪器的高精度、低噪声、低功耗的 20 位 ΣΔ ADC,具有卓越的噪声性能。它包括一个低噪声 PGA、内部振荡器、三级 ΔΣ 调制器和四级数字滤波器,从而为桥接传感器应用提供完整的前端解决方案。ADS1230 易于配置,所有数字控制通过专用引脚完成,无需可编程寄存器。来自 ADS1230 的转换数据通过 SPI 串行接口发送到 MCU,数字信息被转换为重量。低噪声 PGA 具有可选择的增益,通过板载标记为 GAIN 

SEL 的 SMD 跳线设置为 64 和 128,分别支持 ±39mV 或 ±19.5mV 的全量程差分输入。此外,当需要更高速度时,数据可以以 10SPS 输出,具有出色的 50Hz 和 60Hz 抑制,或以 80SPS 输出。板载标记为 SPS SEL 的 SMD 跳线可以选择此功能,将其放置在标记为 10 和 80 的适当位置。ADS1230 可以进入低功耗待机模式或完全关闭的掉电模式。此 Click board™ 使用四线制负载单元配置,具有两个感应引脚和两个输出连接。连接到 AD7780 参考输

入的负载单元差分 S 线创建了一个免疫低频电源激励电压变化的比例配置。这些感应引脚连接到惠斯通电桥的高低两侧,无论由于布线电阻造成的电压降如何,电压都可以精确测量。此 Click board™ 可在 3.3V 或 5V 逻辑电压水平下工作,通过 VCC SEL 跳线选择。这种方式使得 3.3V 和 5V 的 MCU 都可以正确使用通信线路。此外,这款 Click board™ 配备了一个包含易于使用的函数库和示例代码的库,可以作为进一步开发的参考。

Load Cell 7 Click top side image
Load Cell 7 Click bottom side image

功能概述

开发板

EasyAVR v7 是第七代AVR开发板,专为快速开发嵌入式应用的需求而设计。它支持广泛的16位AVR微控制器,来自Microchip,并具有一系列独特功能,如强大的板载mikroProg程序员和通过USB的在线电路调试器。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。EasyAVR v7 通过每个端口的四种不同连接器,比以往更高效地连接附件板、传感器和自定义电子产品。EasyAVR v7 开发板的每个部分

都包含了使同一板块运行最高效的必要组件。一个集成的mikroProg,一个快速的USB 2.0程序员,带有mikroICD硬件在线电路调试器,提供许多有价值的编 程/调试选项和与Mikroe软件环境的无缝集成。除此之外,它还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括外部12V电源供应,7-12V交流或9-15V直流通过DC连接器/螺丝端子,以及通过USB Type-B(USB-B)连接器的电源。通信选项如USB-UART和RS-232也包括在内,与

广受好评的mikroBUS™标准、三种显示选项(7段、图形和基于字符的LCD)和几种不同的DIP插座一起,覆盖了广泛的16位AVR MCU。EasyAVR v7 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

EasyAVR v7 horizontal image

微控制器概述 

MCU卡片 / MCU

default

建筑

AVR

MCU 内存 (KB)

32

硅供应商

Microchip

引脚数

40

RAM (字节)

2048

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
NC
NC
RST
SPI Chip Select
PA5
CS
SPI Clock
PB7
SCK
SPI Data OUT
PB6
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
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™ 原理图

Load Cell 7 Click Schematic schematic

一步一步来

项目组装

EasyAVR v7 front image hardware assembly

从选择您的开发板和Click板™开始。以EasyAVR v7作为您的开发板开始。

EasyAVR v7 front image hardware assembly
GNSS2 Click front image hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyAVR v7 Access DIP MB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
EasyPIC PRO v7a Display Selection Necto Step hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

实时跟踪您的结果

应用程序输出

1. 应用程序输出 - 在调试模式下,“应用程序输出”窗口支持实时数据监控,直接提供执行结果的可视化。请按照提供的教程正确配置环境,以确保数据正确显示。

2. UART 终端 - 使用UART Terminal通过USB to UART converter监视数据传输,实现Click board™与开发系统之间的直接通信。请根据项目需求配置波特率和其他串行设置,以确保正常运行。有关分步设置说明,请参考提供的教程

3. Plot 输出 - Plot功能提供了一种强大的方式来可视化实时传感器数据,使趋势分析、调试和多个数据点的对比变得更加直观。要正确设置,请按照提供的教程,其中包含使用Plot功能显示Click board™读数的分步示例。在代码中使用Plot功能时,请使用以下函数:plot(insert_graph_name, variable_name);。这是一个通用格式,用户需要将“insert_graph_name”替换为实际图表名称,并将“variable_name”替换为要显示的参数。

软件支持

库描述

该库包含 Load Cell 7 Click 驱动程序的 API。

关键功能:

  • loadcell7_tare_scale - 此函数计算 @b ctx->tare_scale,即空容器的原始 ADC 读数。

  • loadcell7_calibrate_weight - 此函数通过计算输入校准重量的 @b ctx->weight_scale 来校准重量。

  • loadcell7_get_weight - 此函数计算货物的重量(单位:克)。

开源

代码示例

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

/*!
 * @file main.c
 * @brief Load Cell 7 Click example
 *
 * # Description
 * This example demonstrates the use of Load Cell 7 Click by measuring the weight
 * in grams of the goods from the load cell sensor connected to the Click board.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and reads the tare scale of the empty container, and after
 * that, it calibrates the weight scale with a known calibration weight.
 *
 * ## Application Task
 * Reads the net weight of the goods in grams approximately once per second and logs the
 * results on the USB UART. 
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "loadcell7.h"

// Enter below the weight in grams of the goods with a known weight which 
// you will use to calibrate the scale weight.
#define LOADCELL7_CALIBRATION_WEIGHT_G  1000.0

static loadcell7_t loadcell7;
static log_t logger;

void application_init ( void )
{
    log_cfg_t log_cfg;  /**< Logger config object. */
    loadcell7_cfg_t loadcell7_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.
    loadcell7_cfg_setup( &loadcell7_cfg );
    LOADCELL7_MAP_MIKROBUS( loadcell7_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == loadcell7_init( &loadcell7, &loadcell7_cfg ) )
    {
        log_error( &logger, " Communication init." );
        for ( ; ; );
    }
    
    log_printf( &logger, " Remove all goods from the scale in the following 5 sec.\r\n");
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    log_printf( &logger, " Calculating tare scale...\r\n");
    if ( LOADCELL7_OK == loadcell7_tare_scale ( &loadcell7 ) ) 
    {
        log_printf( &logger, " Tarring complete!\r\n\n");
    }
    else 
    {
        log_error( &logger, " Calculating tare scale.");
        for ( ; ; );
    }
    
    log_printf( &logger, " Place a %ug calibration weight on the scale in the following 5 sec.\r\n", 
                ( uint16_t ) LOADCELL7_CALIBRATION_WEIGHT_G );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    log_printf( &logger, " Calibrating weight...\r\n");
    if ( LOADCELL7_OK == loadcell7_calibrate_weight ( &loadcell7, LOADCELL7_CALIBRATION_WEIGHT_G ) ) 
    {
        log_printf( &logger, " Calibration complete!\r\n\n");
    }
    else 
    {
        log_error( &logger, " Calibrating weight.");
        for ( ; ; );
    }

    log_info( &logger, " Application Task " );
}

void application_task ( void )
{
    float weight;
    if ( LOADCELL7_OK == loadcell7_get_weight ( &loadcell7, &weight ) ) 
    {
        log_printf(&logger, " Weight : %.2f g\r\n", weight );
    }
}

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

额外支持

资源

喜欢这个项目吗?

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