Intermediate
30 min

Make a voltage-controlled oscillator with AD7740 and STM32F031K6

Voltage-to-Frequency converter

V to Hz 3 Click with Nucleo 32 with STM32F031K6 MCU

Published Oct 01, 2024

Click board™

V to Hz 3 Click

Dev Board

Nucleo 32 with STM32F031K6 MCU

Compiler

NECTO Studio

MCU

STM32F031K6

Provides accurate output frequency proportional to its input voltage

A

A

Hardware Overview

How does it work?

V to Hz 3 Click is based on the AD7740, a CMOS synchronous Voltage-to-Frequency Converter (VFC), which uses a charge-balanced conversion technique from Analog Devices. The input voltage signal from 0V up to 5V from its VIN terminal is applied to a proprietary front-end based around an analog modulator that converts the input voltage into an output pulse train. Depending on the analog input value, the output frequency goes from 10% to 90% of the input frequency provided by the SPI-configurable LTC6903 programmable oscillator, with a maximum input frequency of 1MHz. The analog input signal to the AD7740 is continuously sampled by a switched capacitor modulator whose sampling rate

is set by a master clock (primary input frequency of the AD7740). The input signal may also be buffered, setting the BUF pin of the mikroBUS™ socket to a high logic state before being applied to the sampling capacitor of the modulator, isolating the sampling capacitor charging currents from the analog input pin. The AD7740 also contains an on-chip 2.5 V default bandgap reference, the reference input to the core of the AD7740 defining the span of the VFC. Alternatively, an external reference may be used to overdrive the internal reference by applying it to an onboard header marked as REFIN. Alongside SPI communication, this Click board™ also uses several additional pins. The BUF pin mentioned above represents the

Buffered mode selection, while the AN pin indicates the presence of an external analog signal. The last of the enabled pins is the F signal, routed to the INT pin of the mikroBUS™ socket, which can also serve as output frequency from the AD7740 in the same way as the FOUT terminal. This Click board™ can operate with both 3.3V and 5V logic voltage levels selected via the VCC SEL jumper. This way, it is allowed for both 3.3V and 5V capable MCUs to use the communication lines properly. However, the Click board™ comes equipped with a library containing easy-to-use functions and an example code that can be used, as a reference, for further development.

v-to-hz-3-click-hardware-overview

Features overview

Development board

Nucleo 32 with STM32F031K6 MCU board provides an affordable and flexible platform for experimenting with STM32 microcontrollers in 32-pin packages. Featuring Arduino™ Nano connectivity, it allows easy expansion with specialized shields, while being mbed-enabled for seamless integration with online resources. The

board includes an on-board ST-LINK/V2-1 debugger/programmer, supporting USB reenumeration with three interfaces: Virtual Com port, mass storage, and debug port. It offers a flexible power supply through either USB VBUS or an external source. Additionally, it includes three LEDs (LD1 for USB communication, LD2 for power,

and LD3 as a user LED) and a reset push button. The STM32 Nucleo-32 board is supported by various Integrated Development Environments (IDEs) such as IAR™, Keil®, and GCC-based IDEs like AC6 SW4STM32, making it a versatile tool for developers.

Nucleo 32 with STM32F031K6 MCU double side image

Microcontroller Overview

MCU Card / MCU

default

Architecture

ARM Cortex-M0

MCU Memory (KB)

32

Silicon Vendor

STMicroelectronics

Pin count

32

RAM (Bytes)

4096

You complete me!

Accessories

Click Shield for Nucleo-32 is the perfect way to expand your development board's functionalities with STM32 Nucleo-32 pinout. The Click Shield for Nucleo-32 provides two mikroBUS™ sockets to add any functionality from our ever-growing range of Click boards™. We are fully stocked with everything, from sensors and WiFi transceivers to motor control and audio amplifiers. The Click Shield for Nucleo-32 is compatible with the STM32 Nucleo-32 board, providing an affordable and flexible way for users to try out new ideas and quickly create prototypes with any STM32 microcontrollers, choosing from the various combinations of performance, power consumption, and features. The STM32 Nucleo-32 boards do not require any separate probe as they integrate the ST-LINK/V2-1 debugger/programmer and come with the STM32 comprehensive software HAL library and various packaged software examples. This development platform provides users with an effortless and common way to combine the STM32 Nucleo-32 footprint compatible board with their favorite Click boards™ in their upcoming projects.

Click Shield for Nucleo-32 accessories 1 image

Used MCU Pins

mikroBUS™ mapper

Analog Input Indicator
PA0
AN
NC
NC
RST
SPI Chip Select
PA4
CS
SPI Clock
PB3
SCK
SPI Data OUT
PB4
MISO
SPI Data IN
PB5
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
Buffered Mode
PA8
PWM
AD7740 Frequency
PA12
INT
NC
NC
TX
NC
NC
RX
NC
NC
SCL
NC
NC
SDA
Power Supply
5V
5V
Ground
GND
GND
1

Take a closer look

Schematic

V to Hz 3 Click Schematic schematic

Step by step

Project assembly

Click Shield for Nucleo-144 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the Nucleo 32 with STM32F031K6 MCU as your development board.

Click Shield for Nucleo-144 front image hardware assembly
Nucleo 144 with STM32L4A6ZG MCU front image hardware assembly
Stepper 22 Click front image hardware assembly
Prog-cut hardware assembly
Stepper 22 Click complete accessories setup image hardware assembly
Nucleo-32 with STM32 MCU 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
STM32 M4 Clicker HA MCU/Select 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

Track your results in real time

Application Output via Debug Mode

1. Once the code example is loaded, pressing the "DEBUG" button initiates the build process, programs it on the created setup, and enters Debug mode.

2. After the programming is completed, a header with buttons for various actions within the IDE becomes visible. Clicking the green "PLAY" button starts reading the results achieved with the Click board™. The achieved results are displayed in the Application Output tab.

DEBUG_Application_Output

Software Support

Library Description

This library contains API for V to Hz 3 Click driver.

Key functions:

  • vtohz3_set_input_frequencyThis function enables and sets the output frequency of the programmable oscillator, which is the AD7740 input frequency.

  • vtohz3_read_an_pin_voltageThis function reads the results of the AD conversion of the AN pin and converts them to a proportional voltage level.

  • vtohz3_get_frequency This function converts voltage to the estimated output frequency in Hz.

Open Source

Code example

This example can be found in NECTO Studio. Feel free to download the code, or you can copy the code below.

/*!
 * @file main.c
 * @brief VtoHz3 Click example
 *
 * # Description
 * This example demonstrates the use of the V to Hz 3 click board by calculating
 * the estimated output frequency from the input voltage.
 *
 * The demo application is composed of two sections :
 *
 * ## Application Init
 * Initializes the driver and sets the input frequency.
 *
 * ## Application Task
 * Reads the input voltage from AN pin and calculates the output frequency from it.
 * The results are being displayed on the USB UART approximately once per second.
 *
 * @author Stefan Filipovic
 *
 */

#include "board.h"
#include "log.h"
#include "vtohz3.h"

static vtohz3_t vtohz3;
static log_t logger;

void application_init ( void ) 
{
    log_cfg_t log_cfg;        /**< Logger config object. */
    vtohz3_cfg_t vtohz3_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.
    vtohz3_cfg_setup( &vtohz3_cfg );
    VTOHZ3_MAP_MIKROBUS( vtohz3_cfg, MIKROBUS_1 );
    if ( SPI_MASTER_ERROR == vtohz3_init( &vtohz3, &vtohz3_cfg ) ) 
    {
        log_error( &logger, " Application Init Error. " );
        log_info( &logger, " Please, run program again... " );

        for ( ; ; );
    }
    
    vtohz3_set_input_frequency ( &vtohz3, VTOHZ3_DEFAULT_IN_FREQUENCY );
    log_info( &logger, " Application Task " );
}

void application_task ( void ) 
{
    float voltage;
    if ( VTOHZ3_OK == vtohz3_read_an_pin_voltage ( &vtohz3, &voltage ) ) 
    {
        log_printf( &logger, " Voltage : %.2f V\r\n", voltage );
        log_printf( &logger, " Output frequency : %lu Hz\r\n\n", 
                    vtohz3_get_frequency ( &vtohz3, voltage, VTOHZ3_VREF_INTERNAL_2V5 ) );
    }
    Delay_ms ( 1000 );
}

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

Additional Support

Resources

Love this project?

'Buy This Kit' button takes you directly to the shopping cart where you can easily add or remove products.