初学者
10 分钟

使用AS3935和ATmega32提供精确的雷电活动检测

体验ThunderSense的力量!

Thunder Click with EasyAVR v7

已发布 6月 26, 2024

点击板

Thunder Click

开发板

EasyAVR v7

编译器

NECTO Studio

微控制器单元

ATmega32

检测周围区域内潜在危险的雷电活动的存在和接近情况。

A

A

硬件概览

它是如何工作的?

Thunder Click 基于 ams AG 的 AS3935,这是一个可编程的全集成雷电传感器,配有灵敏的线圈天线和 Coilcraft 的 MA5532,能够探测潜在危险的雷电活动的接近。嵌入式的雷电算法检查传入信号模式,以排除可能的人造干扰源,提供噪声水平信息,并在高噪声条件下通知主 MCU。如果信号被分类为人造干扰源,该事件将被拒绝,传感器自动返回监听模式。然而,如果事件被分类为雷电击中,则统计距离估算模块评估到风暴前沿的距离。MA5532 外部天线直接连 接到 AS3935 的模拟前端(AFE),该前端放大和解

调接收到的信号。看门狗持续监控 AFE 的输出,并在接收到信号时警告集成的雷电算法模块。AS3935 的嵌入式硬线距离估算算法在每次检测到雷电时通过 IRQ 引脚(连接到 mikroBUS™ 插座的 INT 引脚)发出中断。显示在距离估算寄存器中的估算距离并不代表到单个雷电的距离,而是到风暴前沿的估算距离。除了探测潜在危险的雷电活动外,这款 Click board™ 还提供有关噪声水平上风暴中心估算距离的信息。AS3935 可以在高达 40km 的范围内探测雷电,其天 线敏感度调整为 500kHz 带宽,以便捕捉雷电事件,

对风暴前沿的精确度为 1km。AS3935 雷电传感器使用 SPI 串行接口与 MCU 通信,最大 SPI 频率为 2MHz。注意,SPI 的时钟操作频率不应与天线的共振频率(500kHz)相同,以最小化板载噪声。这款 Click board™ 可以通过 PWR SEL 跳线选择使用 3.3V 或 5V 的逻辑电压水平,使得 3.3V 和 5V 能力的 MCU 都能正确使用通信线路。此外,这款 Click board™ 配备了一个包含易于使用的功能和示例代码的库,可用作进一步开发的参考。

Thunder Click hardware overview 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
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
Interrupt
PD2
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Thunder Click Schematic schematic

一步一步来

项目组装

EasyAVR v7 front image hardware assembly

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

EasyAVR v7 front image hardware assembly
Buck 22 Click front image hardware assembly
MCU DIP 40 hardware assembly
EasyAVR v7 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”替换为要显示的参数。

软件支持

库描述

此库包含 Thunder Click 驱动程序的 API。

关键功能:

  • thunder_check_interr - 此功能检查并返回中断值。

  • thunder_get_storm_info - 此功能获取单个闪电的能量和风暴前沿的距离估计。

  • thunder_read_reg - 此功能从寄存器中读取所需数量的字节。

开源

代码示例

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

/*!
 * @file 
 * @brief Thunder Click example
 * 
 * # Description
 * This application detects the presence and proximity of potentially 
 * lightning activity and provides estimated distance to the center of the storm. 
 * It can also provide information on the noise level.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes SPI driver and performs the reset command and RCO calibrate command.
 * Also configures the device for working properly.
 * 
 * ## Application Task  
 * Checks if the interrupt event has occured (Listening mode) and after that reads
 * the storm information and logs the results on the USB UART.
 * 
 * @author MikroE Team
 *
 */

#include "board.h"
#include "log.h"
#include "thunder.h"

static thunder_t thunder;
static log_t logger;

uint8_t storm_mode;
uint32_t storm_energy;
uint8_t storm_distance;

void application_init ( void )
{
    log_cfg_t log_cfg;
    thunder_cfg_t cfg;

    /** 
     * 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.
    thunder_cfg_setup( &cfg );
    THUNDER_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    thunder_init( &thunder, &cfg );

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

void application_task ( void )
{
    storm_mode = thunder_check_int ( &thunder );

    if ( THUNDER_NOISE_LEVEL_INTERR == storm_mode )
    {
        log_printf( &logger, "Noise level too high\r\n\n" );
    }
    else if ( THUNDER_DISTURBER_INTERR == storm_mode )
    {
        log_printf( &logger, "Disturber detected\r\n\n" );
    }
    else if ( THUNDER_LIGHTNING_INTERR == storm_mode )
    {
        thunder_get_storm_info( &thunder, &storm_energy, &storm_distance );
        log_printf( &logger, "Energy of the single lightning : %lu\r\n", storm_energy );
        log_printf( &logger, "Distance estimation : %u km\r\n\n", ( uint16_t ) storm_distance );
        // Reset configuration to prepare for the next measurement
        thunder_default_cfg( &thunder );
    }
}

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

额外支持

资源

喜欢这个项目吗?

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