中级
30 分钟

使用AD9834和PIC32MZ1024EFH064塑造您的信号

频率激励/波形生成

Waveform 2 Click with PIC32MZ clicker

已发布 6月 25, 2024

点击板

Waveform 2 Click

开发板

PIC32MZ clicker

编译器

NECTO Studio

微控制器单元

PIC32MZ1024EFH064

通过先进的波形发生器实现正弦和三角波输出以及频率相位调谐和调制。

A

A

硬件概览

它是如何工作的?

Waveform 2 Click 基于 Analog Devices 的 AD9834,这是一款 75 MHz 低功耗 DDS 设备,能够产生高性能的正弦波、三角波和方波输出。AD9834 可以实现多种简单和复杂的调制方案,这些调制方案在数字域中完全实现,允许使用 DSP 技术精确实现复杂的调制算法。它包含一个通过 SPI 串行接口访问的 16 位控制寄存器,可根据用户的需求设置 AD9834 的操作方式。AD9834 的内部电路包括数控振荡器 (NCO)、频率和相位调制器、SIN ROM、DAC、比较器和稳压器。AD9834 的输出通过 RC 网络滤波,然后通过 THS4551 放大,THS4551 是一个差分放大器,提供了从单端源到德州仪器的高精度模数转换器所需的差分输

出的简便接口。AD9834 的输出信号沿两条路径传输。当发生器的输出波形为正弦波或三角波时,一条路径被路由到标记为 Signal Out 的输出连接器;而当发生器的输出波形为方波时,另一条路径被路由到标记为 Square Out 的输出连接器。除了正电源电压要求外,THS4551 放大器还需要负电源电压,这是通过 ADM8829 实现的,ADM8829 是一个电荷泵电压逆变器,用于从 Analog Devices 的正输入生成负电源电压。该 Click 板™ 还具有 75MHz 的外部振荡器,由 mikroBUS™ 插座的 EN 引脚启用,代表 AD9834 可以接受的最大频率。75MHz 时钟在高频率下产生最干净的正弦波形,而低频率则会产生误差。除了这些功能

外,Waveform 2 Click 还具有 EEPROM 存储器 IC 24AA64,这是 Microchip 的一款 I2C 可配置的 64K 串行 EEPROM,可用于各种存储应用。Waveform 2 Click 使用兼容标准 SPI、QSPI™ 和 MICROWIRE™ 的 3 线 SPI 串行接口与 MCU 通信,操作时钟速率最高可达 40 MHz。此外,它还具备复位功能,这是 AD9834 初始化过程中所需的,通过 mikroBUS™ 插座的 RST 引脚实现和路由。该 Click 板™ 只能在 3.3V 逻辑电压水平下工作。在使用不同逻辑电平的 MCU 之前,必须执行适当的逻辑电压电平转换。不过,该 Click 板™ 配备了包含易于使用的函数库和示例代码的库,可用作进一步开发的参考。

Waveform 2 Click top side image
Waveform 2 Click bottom side image

功能概述

开发板

PIC32MZ Clicker 是一款紧凑型入门开发板,它将 Click 板™的灵活性带给您喜爱的微控制器,使其成为实现您想法的完美入门套件。它配备了一款板载 32 位带有浮点单元的 Microchip PIC32MZ 微控制器,一个 USB 连接器,LED 指示灯,按钮,一个 mikroProg 连接器,以及一个用于与外部电子设备接口的头部。得益于其紧凑的设计和清晰易识别的丝网标记,它提供了流畅且沉浸式的工作体验,允许在任

何情况下、任何地方都能访问。PIC32MZ Clicker 开 发套件的每个部分都包含了使同一板块运行最高效的必要组件。除了可以选择 PIC32MZ Clicker 的编程方式,使用 USB HID mikroBootloader 或通过外部 mikroProg 连接器为 PIC,dsPIC 或 PIC32 编程外,Clicker 板还包括一个干净且调节过的开发套件电源供应模块。USB Micro-B 连接可以提供多达 500mA 的电流,这足以操作所有板载和附加模块。所有 

mikroBUS™ 本身支持的通信方法都在这块板上,包 括已经建立良好的 mikroBUS™ 插槽、重置按钮以及若干按钮和 LED 指示灯。PIC32MZ Clicker 是 Mikroe 生态系统的一个组成部分,允许您在几分钟内创建新的应用程序。它由 Mikroe 软件工具原生支持,得益于大量不同的 Click 板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作的许多方面。

PIC32MZ clicker double side image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC32

MCU 内存 (KB)

1024

硅供应商

Microchip

引脚数

64

RAM (字节)

524288

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
RE5
RST
SPI Chip Select
RG9
CS
SPI Clock
RG6
SCK
NC
NC
MISO
SPI Data IN
RG8
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Enable
RB3
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RD10
SCL
I2C Data
RD9
SDA
NC
NC
5V
Ground
GND
GND
1

“仔细看看!”

Click board™ 原理图

Waveform 2 Click Schematic schematic

一步一步来

项目组装

PIC32MZ clicker front image hardware assembly

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

PIC32MZ clicker 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
Flip&Click PIC32MZ 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

软件支持

库描述

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

关键功能:

  • waveform2_set_freq - 设置输出频率的功能

  • waveform2_sine_output - 设置正弦波输出的功能

  • waveform2_triangle_output - 设置三角波输出的功能

开源

代码示例

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

/*!
 * @file main.c
 * @brief Waveform2 Click example
 *
 * # Description
 * This is an example that demonstrates the use of the Waveform 2 Click board.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initialize the communication interface, preforming hardware reset, and configure the Click board.
 *
 * ## Application Task
 * Predefined characters are inputed from the serial port.
 * Depending on the character sent the signal frequency, waveform or amplitude
 * will be changed.
 *
 * - Command:
 * [ + ] - Increase frequency
 * [ - ] - Decrease frequency
 * [ t ] - Triangle-shaped signal
 * [ s ] - The signal in the form of a sinusoid
 * 
 * - Additional Functions :
 * aprox_freq_calculation( float freqency ) - This function is used to calculate the aproximate 
 * value that will be written to the frequency set register.
 *
 * @author Stefan Ilic
 *
 */

#include "board.h"
#include "log.h"
#include "waveform2.h"

static waveform2_t waveform2;
static log_t logger;

float value = 100000;
char demo_rx_buf[ 10 ];
char demo_tx_buf[ 10 ] = "MikroE";

/**
 * @brief Aproximate frequency calculation function.
 * @details This function is used to calculate the aproximate value that will be 
 * written to the frequency set register..
 */
uint32_t aprox_freq_calculation ( float freqency );

void application_init ( void ) {
    log_cfg_t log_cfg;  /**< Logger config object. */
    waveform2_cfg_t waveform2_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.
    waveform2_cfg_setup( &waveform2_cfg );
    WAVEFORM2_MAP_MIKROBUS( waveform2_cfg, MIKROBUS_1 );
    err_t init_flag  = waveform2_init( &waveform2, &waveform2_cfg );
    if ( ( I2C_MASTER_ERROR == init_flag ) || ( SPI_MASTER_ERROR == init_flag ) ) {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    waveform2_default_cfg ( &waveform2 );

    log_printf( &logger, "---- EEPROM test ----\r\n " );
    log_printf( &logger, ">> Write [MikroE] to address 0x0123\r\n " );
    waveform2_eeprom_write_string( &waveform2, 0x0123, demo_tx_buf, 6 );
    waveform2_eeprom_read_string ( &waveform2, 0x0123, demo_rx_buf, 6 );
    log_printf( &logger, ">> Read data: %s  from address 0x0123.... \r\n ", demo_rx_buf );
    Delay_ms ( 1000 );
    waveform2_hw_reset( &waveform2 );
    Delay_ms ( 1000 );
    
    log_printf( &logger, "---- Waveform set freqency ----\r\n" );
    int32_t freqency;
    freqency = aprox_freq_calculation( value );
    waveform2_set_freq( &waveform2, freqency );
    waveform2_triangle_output( &waveform2 );
    Delay_ms ( 1000 );
    log_info( &logger, " Application Task " );
}

void application_task ( void ) {
    char rx_data;
    uint32_t freq_data;

    if ( log_read( &logger, &rx_data, 1 ) ) {
        switch ( rx_data ) {
            case '+': {
                if ( value > 200000 ) {
                    value = 0;
                }
                value += 100000;
                freq_data = aprox_freq_calculation( value );
                waveform2_set_freq( &waveform2, freq_data );
                log_printf( &logger, ">> Increasing the frequency \r\n " );
                break;
            }

            case '-': {
                if ( value < 200000 ) {
                    value = 400000;
                }
                value -= 100000;
                freq_data = aprox_freq_calculation( value );
                waveform2_set_freq( &waveform2, freq_data );
                log_printf( &logger, ">> Decreasing the frequency \r\n " );
                break;
            }

            case 't': {
                waveform2_triangle_output( &waveform2 );
                log_printf( &logger, ">> Triangle output \r\n " );
                break;
            }

            case 's': {
                waveform2_sine_output( &waveform2 );
                log_printf( &logger,  ">> Sinusoid output \r\n " );
                break;
            }
        }
    }
}

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;
}

uint32_t aprox_freq_calculation ( float freqency ) {
    uint32_t calculation;
    float WAVEFORM_OSC_FREQ = 50000000.0;
    float WAVEFORM_CONSTANT = 268435456.0; 

    calculation = freqency * ( WAVEFORM_CONSTANT / WAVEFORM_OSC_FREQ );

    return calculation;
}

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

额外支持

资源

喜欢这个项目吗?

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