Intermediate
30 min

Convert voltage data into frequency signals using TC9400 and PIC18F46K22

Signal generation redefined: Explore our voltage-to-frequency solution

V To Hz Click with EasyPIC v8

Published Sep 30, 2023

Click board™

V To Hz Click

Dev. board

EasyPIC v8

Compiler

NECTO Studio

MCU

PIC18F46K22

Experience a breakthrough in signal generation – our voltage-to-frequency solution transforms voltage inputs into finely tuned frequency signals, granting you unprecedented control over your waveform generation

A

A

Hardware Overview

How does it work?

V to Hz Click is based on the TC9400, a voltage-to-frequency and frequency-to-voltage converter from Microchip. It accepts voltage at its input and generates a pulse train, with a frequency linearly proportional to the input voltage. The pulse train is present on two output pins: the full frequency pin outputs signal with the pulse rate linear to the input voltage, while the half frequency pin outputs signal with the pulse rate equal to the half of the full frequency pin pulse rate. When V to Hz click is operated for the first time, it needs to be calibrated. The click is equipped with two variable resistors for gain and offset fine tuning. There are several steps that should be followed when calibrating. An input signal of 10mV should be applied to the input. The offset should be adjusted so that a 10Hz signal appears on the output. An input signal of 5V should be applied to the input. The gain should be adjusted so that 10kHz signal

appears on the output. V to Hz Click is equipped with the input voltage terminal (VOLT IN), which is used to connect the control voltage up to 5V. Besides having control voltage input on this terminal, it is possible to select the voltage generated by the MCU as the control voltage input, too. INPUT SEL switch can be set so that the PWM pin from the mikroBUS™ is used as the control voltage input. The PWM signal generated by the MCU is filtered out by the onboard low pass filter so that the control voltage remains constant. For this reason, PWM signal frequency from the MCU should be at least 40 kHz. The output terminal (FREQ OUT) is used to output the generated frequency. There are two outputs routed to this two-pole screw terminal: the first output is full frequency output (f), while the second output is the half of the generated frequency (f/2). The frequency output is also

routed to the INT pin of the mikroBUS™. To select between the half and the full frequency output routed to the INT pin, the FREQ SEL SMD jumper needs to be switched to the correct position. Both of the half frequency and the full frequency outputs are pulled HIGH (3.3V) with an onboard resistor, which means that the output generated signal amplitude will be 3.3V. To provide 12V for the TC9400, V to Hz click employs a boost converter, built around the MIC2606, a boost regulator from Microchip, which works at 2MHz. This IC provides 12V for supplying the TC9400 out of 5V routed from the mikroBUS™ socket. EN pin of the boost regulator is routed to the mikroBUS™ CS pin and it is used to enable power output from the boost regulator, effectively enabling the TC9400 itself. EN pin is pulled to a HIGH logic level (3.3V) by the onboard resistor.

V To Hz Click hardware overview image

Features overview

Development board

EasyPIC v8 is a development board specially designed for the needs of rapid development of embedded applications. It supports many high pin count 8-bit PIC microcontrollers from Microchip, regardless of their number of pins, and a broad set of unique functions, such as the first-ever embedded debugger/programmer. The development board is well organized and designed so that the end-user has all the necessary elements, such as switches, buttons, indicators, connectors, and others, in one place. Thanks to innovative manufacturing technology, EasyPIC v8 provides a fluid and immersive working experience, allowing access anywhere and under any

circumstances at any time. Each part of the EasyPIC v8 development board contains the components necessary for the most efficient operation of the same board. In addition to the advanced integrated CODEGRIP programmer/debugger module, which offers many valuable programming/debugging options and seamless integration with the Mikroe software environment, the board also includes a clean and regulated power supply module for the development board. It can use a wide range of external power sources, including a battery, an external 12V power supply, and a power source via the USB Type-C (USB-C) connector.

Communication options such as USB-UART, USB DEVICE, and CAN are also included, including the well-established mikroBUS™ standard, two display options (graphical and character-based LCD), and several different DIP sockets. These sockets cover a wide range of 8-bit PIC MCUs, from the smallest PIC MCU devices with only eight up to forty pins. EasyPIC v8 is an integral part of the Mikroe ecosystem for rapid development. Natively supported by Mikroe software tools, it covers many aspects of prototyping and development thanks to a considerable number of different Click boards™ (over a thousand boards), the number of which is growing every day.

EasyPIC v8 horizontal image

Microcontroller Overview

MCU Card / MCU

PIC18F46K22

Architecture

PIC

MCU Memory (KB)

64

Silicon Vendor

Microchip

Pin count

40

RAM (Bytes)

3896

Used MCU Pins

mikroBUS™ mapper

NC
NC
AN
NC
NC
RST
Boost Regulator Enable
RE0
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
PWM Input
RC0
PWM
Frequency Output
RB0
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

Click board™ Schematic

V To Hz Click Schematic schematic

Step by step

Project assembly

EasyPIC v8 front image hardware assembly

Start by selecting your development board and Click board™. Begin with the EasyPIC v8 as your development board.

EasyPIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
GNSS2 Click complete accessories setup image hardware assembly
EasyPIC v8 Access DIPMB 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
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

Track your results in real time

Application Output

1. Application Output - In Debug mode, the 'Application Output' window enables real-time data monitoring, offering direct insight into execution results. Ensure proper data display by configuring the environment correctly using the provided tutorial.

2. UART Terminal - Use the UART Terminal to monitor data transmission via a USB to UART converter, allowing direct communication between the Click board™ and your development system. Configure the baud rate and other serial settings according to your project's requirements to ensure proper functionality. For step-by-step setup instructions, refer to the provided tutorial.

3. Plot Output - The Plot feature offers a powerful way to visualize real-time sensor data, enabling trend analysis, debugging, and comparison of multiple data points. To set it up correctly, follow the provided tutorial, which includes a step-by-step example of using the Plot feature to display Click board™ readings. To use the Plot feature in your code, use the function: plot(*insert_graph_name*, variable_name);. This is a general format, and it is up to the user to replace 'insert_graph_name' with the actual graph name and 'variable_name' with the parameter to be displayed.

Software Support

Library Description

This library contains API for V To Hz Click driver.

Key functions:

  • vtohz_set_duty_cycle - Generic sets PWM duty cycle

  • vtohz_pwm_stop - Stop PWM module

  • vtohz_pwm_start - Start PWM module.

Open Source

Code example

The complete application code and a ready-to-use project are available through the NECTO Studio Package Manager for direct installation in the NECTO Studio. The application code can also be found on the MIKROE GitHub account.

/*!
 * \file 
 * \brief VtoHz Click example
 * 
 * # Description
 * This application converts an analog voltage input signal into a pulse wave signal of a certain frequency.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init
 * Initializes driver and enables the click board. 
 * 
 * ## Application Task  
 * Alternates between different output frequencies.
 * 
 * ## Additional functions
 *  - set_output_frequency - Changing the output frequency by setting the PWM duty cycle to desired value. 
 * 
 * @note Output frequency may vary depending on the offset and gain potentiometers on board the click.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "vtohz.h"

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

static vtohz_t vtohz;
static log_t logger;

static float duty_cycle = 0.5;

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

uint16_t pwm_period;

static uint8_t set_output_frequency ( float frequency )
{
    float duty_cycle;

    if ( frequency > 10000 )
    {
        return -1;
    }
    
    duty_cycle = frequency;
    duty_cycle /= 10000;
    vtohz_set_duty_cycle( &vtohz, duty_cycle );
    vtohz_pwm_start( &vtohz );
    
    return 0;
}

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

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

    vtohz_cfg_setup( &cfg );
    VTOHZ_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    vtohz_init( &vtohz, &cfg );
    
    vtohz_enable ( &vtohz );
}

void application_task ( void )
{
    set_output_frequency( 1000 );        //1000 Hz output
    log_printf( &logger, "Output frequency: \t 1000 Hz\r\n" );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    set_output_frequency( 2000 );        //2000 Hz output
    log_printf( &logger, "Output frequency: \t 2000 Hz\r\n" );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    set_output_frequency( 5000 );        //5000 Hz output
    log_printf( &logger, "Output frequency: \t 5000 Hz\r\n" );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    set_output_frequency( 10000 );       //10000 Hz output
    log_printf( &logger, "Output frequency: \t 10000 Hz\r\n" );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    Delay_ms ( 1000 );
    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.