Story

This project is an enhancement to an earlier project previously published:

Microbit Pulse Generator - Variable Ranges

The enhancements are a custom designed PCB to carry out the D2A conversion for the Sine and Sawtooth waveforms complete with independent outputs and independent amplitude control.

With the addition of an OLED display to indicate range, frequency and output status.

All housed in a custom 3D printed enclosure.

Digital waveforms

A digital sinewave waveform can be generated using shift resisters with weighted outputs.

Using two 4 bit shift registers we can generate 8 discrete up steps and 8 discrete down steps for symmetry.

For the first shift register.

With a resistor R on Q0 a current flows when QO is high. If we place a resistor on Q1 that's R./2 then twice the current will flow when Q1 is high. Consequently, if we fit resistors of R/4 on Q2 and R/8 on Q3 then we have a weighted current for each step counting up.

For the second shift register.

With a resistor R on Q3 a current flows when Q3 is high. If we place a resistor on Q2 that's R./2 then twice the current will flow when Q2 is high. Consequently, if we fit resistors of R/4 on Q1 and R/8 on Q0 then we have a weighted current for each step that reduces as the count increases.

If the summing point for both counters is connected to a load resistor each current step generates a corresponding voltage step.

The frequency of the output waveform = Fin/2^(n/2) where n = weighted outputs.

Therefore if Fin = 1KHz then the sinewave frequency will be 1000/16 = ~62.5Hz

Circuit Design

The circuit is designed using low voltage logic IC's (Shift register, Binary Counter, EXOR's and OpAmp) using DIL packages for ease of assembly.

The Sawtooth waveform is generated using a CD4024, 7 bit binary counter with binary weighted resistors connected to the 4 LSB outputs.

The clock input is derived from the MicrobIt at output P0.

The control for the clock frequency is provided by a 100k, 10 turn potentiometer with the main resistance connected between 0V and 3V and the wiper connected to P1 of the Microbit to provide a variable voltage (Vv) that is used to vary the frequency.

Vv = Rx/100k*3V where Rx is the resistance between the wiper and the connection to 0V

A POR (Power On Reset), is provided by a CR* network connected to the reset pins to ensure the Counters and the Registers power up in the low state.

*(The CR network pulls the Reset pin High on power up for ~1mS until the capacitor charges then its maintained low by the resistor).

The Binary Counter increments on each negative transition of the clock advancing one count from 0 to 15 then resets to 0 to repeat the cycle.

The result is a repetitive digital sawtooth wave.

The voltage at the summing point is fed to the non inverting input of one half of a dual Op-Amp configured as a non inverting amplifier.

A 5k (Rf) potentiometer is connected in the feedback path in conjunction with a 220R (Rp) to control the waveform output amplitude. Vgain = 1+Rf/Rp with Vgain from 1 to 24 enabling the output voltage to be controlled from ~0 to 3V.

The Shift Register transfers data on each positive transition of the clock and the last stage (Q3) of register 1 is connected to the data input of register 2 with its last stage (Q3) fed back to the data input of register 1.

At switch on all the registers are reset to zero but the inverter connected to the data input of register 1 sets each stage to a logic 1 on each clock transition. Giving a progressive increase in voltage.

Once the last stage of register 2 is set to 1 the data input is set to 0 by the inverter and each stage is successively set to 0. Giving a progressive reduction in voltage.

The result is a repetitive digital sine wave.

The voltage at the summing point is fed to the non inverting input of one half of a dual Op-Amp configured as a non inverting amplifier.

A 5k (Rf) potentiometer is connected in the feedback path in conjunction with a 220R (Rp) to control the waveform output amplitude. Vgain = 1+Rf/Rp with Vgain from 1 to 24 enabling the output voltage to be controlled from ~0 to 3V.

Coding

In the original incarnation of this project the Microbit display was used to indicate status.

However, as the Microbit is limited in the information that can be displayed in one go without resorting to scrolling this was upgraded to an OLED display.

Therefore additional code was included to make use of this display.

The information displayed is:

Application Name and version.

Output status.

Frequency Range

Frequency

Code description

On startThis calls reset (variables assigned and initial values set). If using Microbit V2 which has a built in sounder this will need to be switched off, ignored if using V1.

Button A - Output Enable

Displays output enabled or output disabled

Default on start up is output disabled.

Button B - Range

Sets the max_range on each button press for 1k, 10k, 100k, 250k & 500kHz max_range.

Default on start up is 1kHz.

Pot_Adjust

Reads the analogue input on P1 Converts it into a percentage of the maximum bit count and into a frequency based on the maximum range. Frequency = max_Range * (bit value/1023)

Update the display value relative to the selected max_range

Forever

Where the ring tone is applied with the required frequency.

Output enable is applied here subject to its status to output the required frequency or zero frequency.

In the code much of the activity to the Microbit display is disabled as it will be enclosed inside the box.

However, this can be re-enabled simply be reinserting the Plot code block.

Enclosure Design

For previous projects were I have made boxes these were made in two parts (an open box and a lid), but for this project there was a departure from this method being much larger than previous builds, I decided to make six sides to enabled them to be 3D printed separately.

The enclosure was designed in TinkerCAD: Function_generator_box

All fixing holes, cut outs, standoffs and legends would be created as part of the printing process.

The size of the completed box is 132mm (W) x 93mm (H) x 104mm (D) and consists of Top, Bottom, Left, Right, Back, Front & Display supports.


Operation

Power the Function Generator from a suitable power source via USB, the connector opening is on the right hand side.

It will initialize and display the status.

This will be Output disabled, Max frequency range: 1000Hz, Frequency 0Hz.

There will also be a green glow from the power indicator visible around the display.

Press the Enable button to turn on the outputs and the pulse frequency will be displayed.

Press the Range button to change the maximum frequency range.

Turn the frequency knob to adjust the frequency value.

Adjustment of the frequency will effect the sine, sawtooth and pulse waveforms.

However, sine & sawtooth will have a frequency 16 times lower than that at the pulsed output due to the D2A conversion process.

The sine and sawtooth waves have independent amplitude control from ~100mV to 3V.

The pulse output voltage is fixed at 3V maximum.

However, a potential divider on the output will allow setting of different voltages using the formula.

Vout = 3V*Rout/Rtotal where Rtotal = Rin+ Rout in series from the output to 0V, with the output taken from the centre tap of the two resistors.

If Rin =10K and Rout = 5K then 3V*5K/15K = 1V maximum.

Connections to the output terminals can be made using 4mm banana plugs, spade connectors or loose wires.

Additionally, the spacing between the output terminal posts is compatible with a BNC to 2x 4mm banana plug adaptor allowing the use of Co-axial cables if required.