FabGL
ESP32 VGA Controller and Graphics Library
fabgl::SquareWaveGeneratorClass Class Reference

This is a square wave generator that uses APLL internal Audio PLL clock. More...

#include <swgenerator.h>

Public Member Functions

void begin (bool div1_onGPIO0, gpio_num_t div2=GPIO_NUM_39, gpio_num_t div4=GPIO_NUM_39, gpio_num_t div8=GPIO_NUM_39, gpio_num_t div16=GPIO_NUM_39, gpio_num_t div32=GPIO_NUM_39, gpio_num_t div64=GPIO_NUM_39, gpio_num_t div128=GPIO_NUM_39, gpio_num_t div256=GPIO_NUM_39)
 Initializes SquareWaveGeneratorClass and associate GPIOs to the outputs. More...
 
void end ()
 Disables all outputs. More...
 
void play (int freq, lldesc_t volatile *dmaBuffers=nullptr)
 Sets the main frequency. More...
 
void stop ()
 Disables all outputs. More...
 

Detailed Description

This is a square wave generator that uses APLL internal Audio PLL clock.

When FABGLIB_USE_APLL_AB_COEF = 0 (the default) the frequency range is 2651514 Hz to 62500000 Hz.
Average error is 21 Hz, Minimum error is 0, Maximum error is 1000 Hz except for range 41666667 Hz to 42708333 Hz while frequency remains fixed at 41666666 Hz (error from 0 Hz to 1041666 Hz) and except for range 42708334 hz to 43748999 Hz while frequency remains fixed at 43750000 Hz (error from 750001 Hz to 1041666 Hz).

When FABGLIB_USE_APLL_AB_COEF = 1 the frequency range is 82500 Hz to 62500000 Hz. Unfortunately the output has lot of frequency jittering.
Average error is about 7 Hz, Minimum error is 0, Maximum error is 6349 Hz.

Member Function Documentation

◆ begin()

void fabgl::SquareWaveGeneratorClass::begin ( bool  div1_onGPIO0,
gpio_num_t  div2 = GPIO_NUM_39,
gpio_num_t  div4 = GPIO_NUM_39,
gpio_num_t  div8 = GPIO_NUM_39,
gpio_num_t  div16 = GPIO_NUM_39,
gpio_num_t  div32 = GPIO_NUM_39,
gpio_num_t  div64 = GPIO_NUM_39,
gpio_num_t  div128 = GPIO_NUM_39,
gpio_num_t  div256 = GPIO_NUM_39 
)

Initializes SquareWaveGeneratorClass and associate GPIOs to the outputs.

Parameters
div1_onGPIO0If true the undivided frequency is delivered on GPIO0.
div2Specifies the GPIO where to send frequency / 2 (set GPIO_NUM_39 to disable output).
div4Specifies the GPIO where to send frequency / 4 (set GPIO_NUM_39 to disable output).
div8Specifies the GPIO where to send frequency / 8 (set GPIO_NUM_39 to disable output).
div16Specifies the GPIO where to send frequency / 16 (set GPIO_NUM_39 to disable output).
div32Specifies the GPIO where to send frequency / 32 (set GPIO_NUM_39 to disable output).
div64Specifies the GPIO where to send frequency / 64 (set GPIO_NUM_39 to disable output).
div128Specifies the GPIO where to send frequency / 128 (set GPIO_NUM_39 to disable output).
div256Specifies the GPIO where to send frequency / 256 (set GPIO_NUM_39 to disable output).

Example:

// Outputs 25Mhz on GPIO0 and 6.25Mhz on GPIO5, for 5 seconds
SquareWaveGenerator.begin(true, GPIO_NUM_39, GPIO_NUM_5);
SquareWaveGenerator.play(25000000);
delay(5000);
// Outputs 20Mhz on GPIO and 5Mhz on GPIO5, for 10 seconds
SquareWaveGenerator.play(20000000);
delay(10000);
SquareWaveGenerator.stop();

◆ end()

void fabgl::SquareWaveGeneratorClass::end ( )

Disables all outputs.

◆ play()

void fabgl::SquareWaveGeneratorClass::play ( int  freq,
lldesc_t volatile *  dmaBuffers = nullptr 
)

Sets the main frequency.

Parameters
freqFrequency in Hertz.
dmaBuffersUse only to provide custom DMA buffers.

Example:

// Set 25MHz as main frequency
SquareWaveGenerator.play(25000000);
Examples:
SquareWaveGenerator/SquareWaveGenerator.ino.

◆ stop()

void fabgl::SquareWaveGeneratorClass::stop ( )

Disables all outputs.

Examples:
SquareWaveGenerator/SquareWaveGenerator.ino.

The documentation for this class was generated from the following files: