初学者
10 分钟

使用Si4703和PIC18F57Q43保持信息畅通和娱乐

调频,调高音量,尽情摇滚!

FM Click with Curiosity Nano with PIC18F57Q43

已发布 6月 26, 2024

点击板

FM Click

开发板

Curiosity Nano with PIC18F57Q43

编译器

NECTO Studio

微控制器单元

PIC18F57Q43

只需插上耳机,无论你身在何处,都可以收听你喜爱的电台!

A

A

硬件概览

它是如何工作的?

FM Click基于Si4703,这是一款来自Silicon Labs的广播FM收音机调谐器。该收音机在全球范围内的FM波段工作,频率范围为76-108MHz,天线使用耳机。立体声音频连接器支持三和四导线耳机,建议电缆长度为1.1m至1.45m,以获得最佳信号接收效果。Si4703是行业中体积最小的FM调谐器之一,配备了32.768kHz的参考时钟,以获得更好的频率容差。它 具有左右两个音频输出。每个输出使用来自德州仪器

的音频功率放大器LM4864来放大通道输出。这些放大器可以提供大约200mW的连续平均功率到8Ω负载。FM Click也可以作为立体声设备和单声道使用。FM Click可以通过mikroBUS™插座的I2C串行接口与主机MCU通信。除了通信引脚之外,此板还使用了其他几个引脚。SEN引脚路由到mikroBUS™插座的CS引脚,用作串行接口激活信号,与I2C引脚结合使用,形 成3线接口。RST引脚用作通用复位功能,另外还有两

个用户可配置的引脚,GP2和GP1,路由到mikroBUS™插座的AN和INT引脚。这些I/O引脚可以用作中断请求(搜索/调谐或RDS准备)或立体声/单声道指示器。这个Click板™只能使用3.3V逻辑电压电平操作。在使用具有不同逻辑电平的MCU之前,板子必须执行适当的逻辑电压电平转换。但是,该Click板™配备了一个包含函数和示例代码的库,可用作进一步开发的参考。

FM Click hardware overview image

功能概述

开发板

PIC18F57Q43 Curiosity Nano 评估套件是一款尖端的硬件平台,旨在评估 PIC18-Q43 系列内的微控制器。其设计的核心是包含了功能强大的 PIC18F57Q43 微控制器(MCU),提供先进的功能和稳健的性能。这个评估套件的关键特点包括一个黄 色用户 LED 和一个响应灵敏的机械用户开关,提供无

缝的交互和测试。为一个 32.768kHz 水晶振荡器足迹提供支持,确保精准的定时能力。套件内置的调试器拥有一个绿色电源和状态 LED,使编程和调试变得直观高效。此外,增强其实用性的还有虚拟串行端口 (CDC)和一个调试 GPIO 通道(DGI GPIO),提供广泛的连接选项。该套件通过 USB 供电,拥有由

 MIC5353 LDO 调节器提供支持的可调目标电压功能,确保在 1.8V 至 5.1V 的输出电压范围内稳定运行,最大输出电流为 500mA,受环境温度和电压限制。

PIC18F57Q43 Curiosity Nano double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC

MCU 内存 (KB)

128

硅供应商

Microchip

引脚数

48

RAM (字节)

8196

你完善了我!

配件

Curiosity Nano Base for Click boards 是一款多功能硬件扩展平台,专为简化 Curiosity Nano 套件与扩展板之间的集成而设计,特别针对符合 mikroBUS™ 标准的 Click 板和 Xplained Pro 扩展板。这款创新的基板(屏蔽板)提供了无缝的连接和扩展可能性,简化了实验和开发过程。主要特点包括从 Curiosity Nano 套件提供 USB 电源兼容性,以及为增强灵活性而提供的另一种外部电源输入选项。板载锂离子/锂聚合物充电器和管理电路确保电池供电应用的平稳运行,简化了使用和管理。此外,基板内置了一个固定的 3.3V 电源供应单元,专用于目标和 mikroBUS™ 电源轨,以及一个固定的 5.0V 升压转换器,专供 mikroBUS™ 插座的 5V 电源轨,为各种连接设备提供稳定的电力供应。

Curiosity Nano Base for Click boards accessories 1 image

这款标准小型立体声耳机采用顶级立体声电缆和连接器,为用户提供高品质的听觉体验。设计通用兼容性,它们轻松连接到所有MIKROE mikromedia和多媒体板,是您电子项目的理想选择。耳机额定功率为100mW,能够在20Hz至20kHz的广泛频率范围内提供清晰的音频。它们具有100 ± 5dB的灵敏度和32Ω ± 15%的阻抗,确保了最佳的音质。直径为Φ15mm的扬声器提供清晰、沉浸式的音频。这些耳机具有性价比高、多功能的特点,非常适合测试您的原型设备,为您的项目提供经济实惠、可靠的音频解决方案。

FM Click accessories image

使用的MCU引脚

mikroBUS™映射器

General Purpose I/O
PA0
AN
Reset
PA7
RST
Serial Enable Input
PD4
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
General Purpose I/O
PA6
INT
NC
NC
TX
NC
NC
RX
Serial Clock Input
PB2
SCL
Serial Data Input
PB1
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

FM Click Schematic schematic

一步一步来

项目组装

Curiosity Nano Base for Click boards front image hardware assembly

从选择您的开发板和Click板™开始。以Curiosity Nano with PIC18F57Q43作为您的开发板开始。

Curiosity Nano Base for Click boards front image hardware assembly
Charger 27 Click front image hardware assembly
PIC18F47Q10 Curiosity Nano front image hardware assembly
Prog-cut hardware assembly
Charger 27 Click complete accessories setup image hardware assembly
Curiosity Nano with PICXXX Access 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 image step 5 hardware assembly
Necto image step 6 hardware assembly
PIC18F57Q43 Curiosity 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

实时跟踪您的结果

应用程序输出

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”替换为要显示的参数。

软件支持

库描述

这个库包含FM Click驱动程序的API。

关键功能:

  • fm_get_received_signal_strength_indicator - 此函数读取接收信号强度指示器

  • fm_get_channel_frequency - 此函数根据波段和间距设置计算当前频道频率

  • fm_get_channel - 此函数从READCHAN寄存器读取CHANNEL位

开源

代码示例

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

/*!
 * \file 
 * \brief Fm Click example
 * 
 * # Description
 * This click represent FM radio tuner which supports worldwide FM band (76 – 108 MHz)
 * and has a set of features such as automatic frequency and gain control, seek tuning and volume control.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializing I2C driver, powering up device, setting basic settings for Europe, 
 * setting values of seek threshold, volume, snr threshold and impulse detection threshold.
 * Seek and memorize 5 radio stations with a signal strength above the set limit.
 * 
 * ## Application Task  
 * Tunes all memorized stations. Switches the stations each 10 seconds.
 * 
 * ## Additional Functions
 * - void fm_case_plus( fm_t *ctx )      - Increases volume
 * - void fm_case_minus( fm_t *ctx )     - Decreases volume
 * - void fm_case_seek( fm_t *ctx )      - Seeks next station
 * - void fm_case_tune( fm_t *ctx )      - Tunes default station
 * - void fm_case_memorize( )            - Memorizes current station
 * - void fm_case_station1( fm_t *ctx )  - Tunes memorized station 1
 * - void fm_case_station2( fm_t *ctx )  - Tunes memorized station 2
 * - void fm_case_station3( fm_t *ctx )  - Tunes memorized station 3
 * - void fm_case_station4( fm_t *ctx )  - Tunes memorized station 4
 * - void fm_case_station5( fm_t *ctx )  - Tunes memorized station 5
 * - void fm_case_mute( fm_t *ctx )      - Mutes device
 * - void fm_case_tune_up( fm_t *ctx )   - Fine tunes frequency
 * - void fm_case_tune_down( fm_t *ctx ) - Fine tunes frequency
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "fm.h"

// ------------------------------------------------------------------ VARIABLES

#define SIGNAL_STRENGTH_LOWER_LIMIT 25

static fm_t fm;
static log_t logger;

static uint16_t received_signal_strength_indicator;
static uint16_t station_channel;
static uint16_t station1;
static uint16_t station2;
static uint16_t station3;
static uint16_t station4;
static uint16_t station5;

static uint8_t memory;
static uint8_t mute;
static uint8_t received_data;
static uint8_t data_ready;
static uint8_t error_flag;
static uint8_t cnt;

static float channel_frequency;
static float tuned_frequency;
static float tune_freq;

// ------------------------------------------------------- ADDITIONAL FUNCTIONS

void fm_case_plus ( fm_t *ctx  )
{
    error_flag = fm_volume_up( ctx );

    if ( error_flag == 0 )
    {
        log_printf( &logger, "volume up\r\n" );
    }
    else
    {
        log_printf( &logger, "volume max\r\n" );
    }
}

void fm_case_minus ( fm_t *ctx )
{
    error_flag = fm_volume_down( ctx );

    if ( error_flag == 0 )
    {
        log_printf( &logger, "volume down\r\n" );
    }
    else
    {
        log_printf( &logger, "volume min\r\n" );
    }
}

void fm_case_seek ( fm_t *ctx )
{
    fm_seek( ctx );

    Delay_ms( 500 );

    fm_end_seek( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );
    station_channel = fm_get_channel( ctx );
}

void fm_case_tune ( fm_t *ctx )
{
    error_flag = fm_tune( ctx, tune_freq );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    if ( error_flag == 0 )
    {
        received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
        tuned_frequency = fm_get_channel_frequency( ctx );
        station_channel = fm_get_channel( ctx );

        log_printf( &logger, "tune complete\r\n" );

        log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

        log_printf( &logger, "tuned frequency: %.2f MHz\r\n", tuned_frequency );
        log_printf( &logger, "-----------------------\r\n" );
    }
    else
    {
        log_printf( &logger, "frequency not in valid range\r\n" );
    }
}

void fm_case_memorize ( )
{
    switch ( memory )
    {
        case 0 :
        {
            station1 = station_channel;
            memory += 1;

            log_printf( &logger, "station 1 memorized\r\n" );

            break;
        }
        case 1 :
        {
            station2 = station_channel;
            memory += 1;

            log_printf( &logger, "station 2 memorized\r\n" );

            break;
        }
        case 2 :
        {
            station3 = station_channel;
            memory += 1;

            log_printf( &logger, "station 3 memorized\r\n" );
            
            break;
        }
        case 3 :
        {
            station4 = station_channel;
            memory += 1;

            log_printf( &logger, "station 4 memorized\r\n" );

            break;
        }
        case 4 :
        {
            station5 = station_channel;
            memory = 0;

            log_printf( &logger, "station 5 memorized\r\n" );

            break;
        }
        default :
        {
            break;
        }
    }
}

void fm_case_mute ( fm_t *ctx )
{
    if ( mute == 0 )
    {
        fm_mute_enable( ctx );

        log_printf( &logger, "mute enabled\r\n" );

        mute = 1;
    }
    else if ( mute == 1 )
    {
        fm_mute_disable( ctx );

        log_printf( &logger, "mute disabled\r\n" );

        mute = 0;
    }
}

void fm_case_station_1 ( fm_t *ctx  )
{
    fm_tune_channel( ctx, station1 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 1 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_station_2 ( fm_t *ctx )
{
    fm_tune_channel( ctx, station2 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 2 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_station_3 ( fm_t *ctx )
{
    fm_tune_channel( ctx, station3 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 3 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_station_4 ( fm_t *ctx )
{
    fm_tune_channel( ctx, station4 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 4 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_station_5 ( fm_t *ctx )
{
    fm_tune_channel( ctx, station5 );

    Delay_ms( 100 );

    fm_end_tune( ctx );

    Delay_ms( 10 );

    received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
    channel_frequency = fm_get_channel_frequency( ctx );

    log_printf( &logger, "station 5 tuned\r\n" );

    log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

    log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
    log_printf( &logger, "-----------------------\r\n" );
}

void fm_case_tune_up ( fm_t *ctx )
{
    error_flag = fm_fine_tune_up( ctx );

    if ( error_flag == 0 )
    {
        Delay_ms( 100 );

        fm_end_tune( ctx );

        Delay_ms( 10 );
        
        received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
        channel_frequency = fm_get_channel_frequency( ctx );
        station_channel = fm_get_channel( ctx ); 

        log_printf( &logger, "tune up\r\n" );

        log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

        log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
        log_printf( &logger, "-----------------------\r\n" );
    }
    else
    {
        log_printf( &logger, "upper band limit reached\r\n" );
    }
}

void fm_case_tune_down ( fm_t *ctx )
{
    error_flag = fm_fine_tune_down( ctx );

    if ( error_flag == 0 )
    {
        Delay_ms( 100 );

        fm_end_tune( ctx );

        Delay_ms( 10 );
    
        received_signal_strength_indicator = fm_get_received_signal_strength_indicator( ctx );
        channel_frequency = fm_get_channel_frequency( ctx );
        station_channel = fm_get_channel( ctx );

        log_printf( &logger, "tune down\r\n" );

        log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );

        log_printf( &logger, "tuned frequency: %.2f MHz\r\n", channel_frequency );
        log_printf( &logger, "-----------------------\r\n" );
    }
    else
    {
        log_printf( &logger, "lower band limit reached\r\n" );
    }
}

void fm_case_wrong_command ( )
{
    log_printf( &logger, "wrong command\r\n" );
}

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    fm_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.

    fm_cfg_setup( &cfg );
    FM_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    fm_init( &fm, &cfg );
    
    Delay_ms( 500 );
    fm_default_cfg( &fm );

    memory = 0;
    mute = 0;
    fm_case_mute( &fm );
     
    for ( cnt = 0; cnt < 5;  )
    {
        log_printf( &logger, "seeking...\r\n" );
        do 
        {
            received_signal_strength_indicator = 0;
            fm_case_seek( &fm );
        }
        while ( received_signal_strength_indicator < SIGNAL_STRENGTH_LOWER_LIMIT ); //rssi value
        
        log_printf( &logger, "station found\r\n" );
        log_printf( &logger, "rssi: %u dBuV\r\n", received_signal_strength_indicator );
        log_printf( &logger, "channel frequency: %.2f MHz\r\n", channel_frequency );
        fm_case_memorize( );
        log_printf( &logger, "-----------------------\r\n" );
        Delay_ms( 100 );
        cnt++;
    }  
    
    mute = 1;
    fm_case_mute( &fm );
    log_printf( &logger, "playing memorized stations...\r\n\r\n" );
}

void application_task ( void )
{ 
    fm_case_station_1( &fm );
    Delay_ms( 10000 );
       
    fm_case_station_2( &fm );
    Delay_ms( 10000 );
    
    fm_case_station_3( &fm );
    Delay_ms( 10000 );
    
    fm_case_station_4( &fm );
    Delay_ms( 10000 );
    
    fm_case_station_5( &fm );
    Delay_ms( 10000 );
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

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

额外支持

资源

喜欢这个项目吗?

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