Did You Know: Period, Frequency, and Duty Cycle
In the Tests section, you modified the script to adjust the light’s period, frequency, and duty cycle. Not all lights blink indefinitely, so after this, you will also experiment with script modifications to make the light blink a certain number of times.
On/off signal period and duty cycle matter because they are used to control many devices other than lights. Examples include:
- Ovens where more heating element on-time in relation to off-time translates to more heat
- Devices use on/off times to exchange information. For example, a very rapid version of the LED on/off signal where the amount of on time in each on/off repetition controls the position the servo turns to.
Period is the time it takes for a signal to repeat. Period is measured in seconds and abbreviated with an upper-case T. In the case of your LED on/off signal, it’s the sum of the high (on) and low (off) times.
Example: The LED was on for 0.25 seconds and off for 0.25 seconds. What is the period?
T = tHIGH + tLOW
= 0.25 s + 0.25 s
= 0.5 s
Frequency is the rate at which the light blinks on/off, in repetitions per second. Frequency’s abbreviation is f, and its SI unit for measurements is hertz (Hz). The hertz is named after Heinrich Rudolf Hertz, who did important work to prove the existence of electromagnetic waves. Examples of electromagnetic waves include visible light and radio waves.
Convert period to frequency (and frequency to period) by making the known value the denominator of 1. For example, if you know the time it takes a signal to repeat itself (period T), then the frequency is f = 1 / T. Likewise, if you know the repetitions per second (frequency F), then the period is T = 1 / f.
f = 1 / T T = 1 / f
Example: The period is 0.5 s, what is the frequency?
f = 1 / T
= 1 / 0.5 s
= 2 Hz
Example: The frequency is 2 Hz, what is the period?
T = 1 / f
= 1 / 2 Hz
= 0.5 s
SI units 1 Hz = 1/s. In speaking terms, you can think of 1/s as “one repetition per second or one ‘cycle’ per second”.
Duty cycle is a measure of how much time a repeating signal stays on (high) during its period. It is commonly abbreviated D, DC, or %DC, and most commonly measured as a percent value. In other words, what percent of the period did the light stay on?
In the Tests section, you experimented with three different combinations of high and low time at 1 Hz:
Example: Calculate the duty cycle for a signal that is high for 200 ms and low for 800 ms.
%DC = [ tHIGH / (tHIGH + tLOW) ] x 100 %
= [ 200 ms / (200 ms + 800 ms) ] x 100 %
= 0.2 x 100 %
= 20 %
Example: Calculate the duty cycle for a signal that is high for 200 ms and low for 800 ms.
%DC = [ tHIGH / (tHIGH + tLOW) ] x 100 %
= [ 500 ms / (500 ms + 500 ms) ] x 100 %
= 0.5 x 100 %
= 50 %
Example: Calculate the duty cycle for a signal that is high for 800 ms and low for 200 ms.
Answer: 80%
Your Turn: Variable Blink Rates
With a variable, you can also make a light blink at varying rates. You will try that with the led_blink_variable_rate script.
- Change the project name to led_blink_variable_rate.
- Update your script to match the one below, then click Save.
- Click Send to micro:bit.
- Verify that the light blink rate speeds up and slows back down repeatedly.
In this example, the time variable controls the on/off times. The time variable is also multiplied by scale variable to increase and decrease the on/off times with each loop repetition. Initially, scale is 0.7, which causes time to decrease with each loop repetition. When time drops to 2 or less, scale gets changed to 1.3. Then, time starts increasing again until scale grows to 300 or more.