Microbit Pulse Generator - Stepped Ranges

by Gammawave in Circuits > Microcontrollers

885 Views, 4 Favorites, 0 Comments

Microbit Pulse Generator - Stepped Ranges

DSCF5744_2.png

You need a pulse generator and the first thing that comes to mind may be a timing chip such as the ubiquitous 555 timer and a hand full of components.

But if you do not have a timer chip immediately to hand another option is a microcontroller.

This instructable will illustrate how to use a Microbit to generate pulses for use in timing applications.

No external components are required to achieve this just coding and a Microbit.

Supplies

Microbit V1 or V2

Pulse Generation Options

There are several options for generating pulses with the Microbit.

1: Pins. - Using the analog pin functions.

Analog Pitch allows the setting of the frequency and the duration in milliseconds.

2: Ring Tone - Using the Music function

Ring Tone allows the setting of the frequency. There is no requirement to specify the duration of the tone.

Further details regarding these options can be found at the above links.

Outputs

The flexibility to use different outputs depends on the function being used to generate the pulse.

Using Ring Tone the output defaults to P0.

Whereas using Analog Pitch there are 6 unfettered outputs to choose from.

P0, P1 & P2 on the large pins and P3, P4 & P10 on the small pins.

In this project Ring Tone will be used to generate the output..

Capability

The pulse generation capability is different depending upon which Microbit version is used.

V1 - 4Hz to 100kHz

V2 - 4Hz to 1MHz.

Implementation

Layout.png
layout_example.png

This implementation will make use of the two buttons A and B to control the output frequency.

Button A will be used to define the step value from 1 to 9.

Button B will be used to define the multiplier x1, 10, 100, 1e3, 10e3, 100e3, 1e6

7 Ranges 4- 9Hz, 10 - 90Hz, 100 - 900Hz, 1k - 9kHz, 10k - 90kHz, 100k* - 500kHz^, 1MHz&.

*Microbit V1 enabling set integer values from 4 to 100kHz output inversion at ~80kHz but back to normal at 100kHz.

^For Microbit V2 enabling set integer values from 4 to 1MHz (& Selections >500kHz on uBit V2 default to 1MHz)

The display being limited to 25 LED's in a 5 x 5 array is still sufficient to display the range and the multiplier by illuminating LED in specified columns.

Range - Column 1 and 2 (9 LED's)

Multiplier - Column 4 and 5 (6 LED's)

Coding

s_pgen-screenshot.png
default.png

On Start

This 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 - Scale

Incrementally illuminate 5 LED's in column 1, on each button press, starting from the bottom to the top and continuing for the next 4 LED's in column 2 for a total of 9.

Once maximum count has been achieved the associated LED's will be extinguished.

Calls frequency that calculates the frequency from the range and multiplier values.

Frequency calls Output

Button B - Multiplier

Incrementally illuminate 5 LED's in column 4, on each button press, starting from the bottom to the top and continuing for the next 4 LED's in column 5 for a total of 6.

Once maximum count has been achieved the associated LED's will be extinguished.

Calls frequency that calculates the frequency from the range and multiplier values.

Frequency calls Output

Button A+B - Output on/off

Switches the output on and off without changing the assigned settings.

Illuminates the centre LED to indicate pulse status, LED on enabled, LED off disabled

Output

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.

Usage

DSCF5742.JPG
default.png
enable_no_op.png
enable_op.png
10Hz.PNG
100Hz.PNG
1kHz.PNG
10kHz.PNG
100kHz.PNG
1MHz.PNG

Switch on and upload the HEX file.

The Microbit will display the title S_PGEN (Stepped Pulse Generator), then a blank display.

The output at P0 is disabled by default and is toggled between enabled and disabled by pressing button A+B.

The centre LED at co-ordinates 2,2 will illuminate if the output is enabled and off if disabled.

The buttons A & B can be pressed in any order but an output frequency will only be produced once both buttons have been used, to assign the appropriate scale * multiplier > 0 and the output has been enabled.

Pressing buttons A or B will also update the display to indicate the frequency value.

You can monitor the output at P0 in a number of different ways some with more limitations than others, Oscilloscope, Frequency counter, LED, Meter or logic divider.

Waveforms are shown for 10Hz, 100Hz, 1kHz, 10kHz, 100kHz*, 1MHz^; Microbit capability *V1 and ^V2

Frequency = 1/Period

Nominal positive duty cycle 12%.

The output voltage is 0 to~3V, interfacing to other Microbits or logic as the same supply voltage should have few issues.

However, if connecting to interfaces at different voltage levels then level translation and/or isolation will be required to prevent damage to the Microbit.