3 min read
STM32 Function Generator

~ Function Generator Waves

Function Generator Overview Overview of the prototype.

Behavior Description

The device acts as a function generator with the user being able change settings for the device via a numerical keypad. The keypad allows for three different properties of the waveform being generated to be modified in real-time. The three properties are: frequency, waveform type, and duty cycle (for square waves). Pressing number buttons 1 - 5 on the keypad, selects the frequency starting at 100 Hz and going up to 500 Hz. Pressing ‘6’ causes the waveform to change to sine, ‘7’ to triangle, ‘8’ to sawtooth, and ‘9’ to a square wave. When the current waveform is a square wave, pressing the ‘*’ key reduces the duty cycle by 10%, which cannot go lower than 10%. Pressing ‘0’ resets the duty cycle to 50%, and ‘#’ increases the duty cycle by 10%, with a maximum of 90%.

Physical Overview

This project was built around a STM32 Nucleo64-L476RG development board. The user-interface is a old school 12 button telephone keypad. The waveform generation is handled by a external MCP4921 12-bit DAC with a SPI interface. There are also four LED’s which output what button was last pressed represeteed in binary.

Function Generator Architecture

BOM:

ItemDesignatorDescriptionPrice
NUCLEO-L476RGU112-Bit DAC with SPI Interface, 8-Pin PDIP, Extended Temperature14.90
MCP4921U212-Bit Single Output DAC with SPI2.81
KeypadK112 Button Keypad4.95
LEDD1, D2, D3, D4Light-Emitting Diode1.12
ResistorR1, R2, R3, R4Resistor0.40

Software Overview

This project was created using register based configuration for the STM32. Choosing to not utilize STM’s HAL (hardware abstraction layer) provided for a more in depth learning experience which required extensive research into the STM technical manuals for proper perhipherial configuration and setup via the registers. To precisely control the timing of output waves, the output values for the DAC were set at controlled intervals using a interupt timer. The values for waveforms were generated using a script and stored in a look up table to save on computational overhead. The ARR timing value was calcualated based on the size of the LUT, the minimun frequency needed (100 Hz in this case) and the system clock, using this formula ARR = F_SYSCLK / (n_lookup * F_min).

Fucntion Generator State machine