Microbit Pulse Generator - Variable Ranges
by Gammawave in Circuits > Microcontrollers
1481 Views, 5 Favorites, 0 Comments
Microbit Pulse Generator - Variable Ranges
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.
In a previous Instructable (Microbit Pulse Generator - Stepped Ranges), I describe how to use a Microbit to generate pulses at specific stepped frequencies requiring no external components.
This Instructable will again illustrate how to use a Microbit to generate pulses for use in timing applications but continuously variable for selected ranges using an external potentiometer and a few capacitors.
Supplies
MicroBit V1 or V2
Potentiometer 100kR
Resistor 10kR
Capacitor 10uF/10V electrolytic
Capacitor 470nF ceramic - Qty 2
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.
Whilst evaluating the two options for generating pulses it was observed that the Pins options suffers periodic gaps and instability when monitored over a longer period.
Hence Ring Tone was adopted as the preferred option.
Capability
The pulse generation capability is different depending upon which Microbit version is used.
V1 - 4Hz to 100kHz
V2 - 4Hz to 1MHz.
Circuit Simulation
Basic code to illustrate the method and circuit layout created in TinkerCad.
Used the analog pitch function as ring tone is not available but it illustrates the method.
In practice analog pitch has stability issues and instead ring tone is used in the final application.
Run the simulation, adjust the potentiometer to display the control voltage and the corresponding pulses generated and displayed on the oscilloscope.
Default maximum frequency range 1kHz but this can be changed in max_range.
Remember to adjust the oscilloscope time per division if changing max_range.
Downloads
Implementation
This implementation will primarily make use a potentiometer to allow continuous adjustment of output frequency. With the two buttons to control frequency ranges and enable the output.
Button A will be used to enable and disable the output.
The centre LED indicates the output status, LED on, output enabled, LED off, output disabled.
Button B will be used to define the max range 1kHz, 10kHz, 100kHz*, 250kHz, 500kHz^
*Microbit V1
^For Microbit V2 (& Selections >500kHz on uBit V2 defaults to 1MHz)
The last column displays the maximum range selected by Button B
The frequency being output is represented on the display by a diagonal wipe which increases from the bottom left to the top right or minimum to maximum for the selected range.
Coding
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 - Output Enable
Switches the centre LED on for output enabled or LED off for output disabled
Default on start up is output disabled.
Button B - Range
Illuminates one of 5 LED's in column 4, on each button press, starting from the bottom to the top.
Sets the max_range on each button press for 1k, 10k, 100k, 250k & 500kHz
max_range on start up is 1kHz
Pot_Adjust
Reads the analog 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.
Usage
Switch on and upload the HEX file.
The Microbit will display the title V_PGEN (Variable Pulse Generator), then illuminate LED at co-ordinates 4,4.
The output at P0 is disabled by default and is toggled between enabled and disabled by pressing button A.
The centre LED at co-ordinates 2,2 will illuminate if the output is enabled and off if disabled.
Default maximum range is 1kHz
Adjust the external potentiometer to set the required frequency up to the maximum range selected.
Press Button B to change the range as required.
You can monitor the output at P0 in a number of different ways some with more limitations than others, Oscilloscope, frequency counter, LED or meter.
Waveforms are shown for 1kHz, 10kHz, 100kHz, 250kHz & 500kHz verified on the oscilloscope with time period.
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.