AN-1111 Sine Wave Generator

In this app note we will use pulse width modulation coupled with an external filter to create an approximation of a sine wave using a SLG46531V device. We will then interface with this GreenPAK™ using an Arduino Uno and have it play a short song. This functionality will be created by writing to several counters via I2C and triggering a note by toggling a GPIO.

GreenPAK™ Design

CNT4, CNT6, and DFF3 are the core of this design. CNT4 and CNT6 are both used to clock inverting flip flop DFF3, and CNT6 is exactly one clock cycle longer than CNT4. The result is that the output of DFF3 is a square wave with a varying duty cycle.

Sine Wave Generator GreenPAK Design

Figure 2. GreenPAK™ Design

In Figure 2 and Figure 3, Yellow is the output of CNT4 and Blue is the output of CNT6, while Pink is the output of DFF3. You can see that the delay between CNT6 pulses is slightly longer than the delay between CNT4 pulses, and the Pink pulses become shorter due to this difference.

In Figure 3, you can see that the zoomed-out effect of the offset counters is a waveform with a period of CNT4*CNT6 that repeats. The output of DFF3 (Pink) oscillates between a 100% duty cycle and a 0% duty cycle.

Sine Wave Generator Close-up view

Figure 2.Close-up view

Sine Wave Generator Zoomed-out view

Figure 3. Zoomed-out view

The bottom section of the GreenPAK™ design file (see Figure 1) creates the Trigger functionality, which will tell the device to begin playing a tone. A rising edge of Pin 3 will latch DFF4 high, which is fed into the Pipe Delay with an inverting output. The Pipe Delay block delays the input for 10 clock periods then resets DFF4.

Meanwhile, the output of DFF5 is used as a latch to power down the oscillator when the triggered period is over. DFF5 is clocked by the output of DFF4, and is reset by the falling edge of the Pipe Delay's output. Figures 4, 5, and 6 include the property settings for the Pipe Delay, DFF4, and DFF5.

Pipe Delay Properties

Figure 4. Pipe Delay Properties

DFF4 Properties

Figure 5. DFF4 Properties

DFF5 Properties

Figure 6. DFF5 Properties

CNT2 is used to generate a 1kHz clock signal when the oscillator is powered on, which is used to clock CNT0. CNT0 in turn clocks the Pipe Delay. This means that in order to set the length of time you wish your tone to play, you will need to write the following to CNT0 via I2C:

CNT0 = 0.1 * [length of time in ms]-1

External Circuit

Figure 7 shows the external circuit of the Sine Wave Generator. The trigger pin has an internal 1M? pull-down resistor. An old pair of headphones is used for the speaker, which is connected to Pin4 through an RC filter. The RC filter has the effect of smoothing out the square waves shown in Figure 3 and Figure 4, leaving the roughly sinusoidal wave shown in Figure 8. Once again Yellow is the output of CNT4, Blue is the output of CNT6, and Pink is the output of the RC Filter.

External circuit schematic

Figure 7. External circuit schematic

Sine Wave Approximation

Figure 8. Sine Wave Approximation

Arduino Sketch

This Arduino Uno sketch will play the nursery rhyme "Mary had a little lamb" through the GreenPAK™ by using the techniques described so far, and it prints out the song lyrics to the Arduino serial monitor in sync with the respective notes. This sketch makes use of the Silego Arduino Library described in AN1107.

Arduino Code

Arduino Code


In this app note we used a Silego SLG46531V GreenPAK™ device to create a sine wave generator with just a few external components. We then interfaced with the GreenPAK™ using an Arduino Uno to play the nursery rhyme "Mary had a little lamb".

About the Author

Name: David Riedell

Background: David attained a BS in Computer Engineering from North Carolina State University. He is currently working with CMICs as an applications engineer at Silego Technology.




See full list of Application Notes