How the servo_plot Tests Work
The tests you just completed helped verify two things:
- Servo angle is controlled by pulse width.
- The servo signal’s period is 20 ms for a frequency of 50 Hz.
The 5 ms/div setting is fine for measuring the servo signal’s period, but a smaller Time/Div setting would be better for measuring the actual pulse width times. Look forward to that in the Try This section.
Here is an excerpt from the servo_plot script:
pin16.write_analog(51) # 51.2 -> 1000 us -> 45 degrees plot_servo(ch2="servo", delay=40) sleep(4000)
The pin16.write_analog(51) and sleep(4000) statements are from the original servo_test_angles script you used to test the servo in Connect and Test the Servo. The plot_servo(ch2=”servo”, delay=40) function call tells the multimeter module to measure a servo signal with the Ch2 probe connected to P2 but wait 40 ms before starting the measurement. This delay in taking the measurement ensures that the micro:bit has successfully switched from whatever servo signal it was sending previously to the new one.
Unlike a real oscilloscope, which would record thousands of voltage measurements and plot them, the multimetermodule measures the servo signal’s high and low times, in microseconds. It uses those measurements to generate a list of voltages and times that it sends to the CYBERscope to emulate what a real oscilloscope does.
Try This: Adust the Settings
A smaller Time/Div setting will make it easier to measure the servo pulses.
- Change the Time/Div dropdown to 5 ms to 0.5 ms.
- Verify that the oscilloscope displays this when the servo points its horn in the 90° direction.
One approach to measuring pulses with an oscilloscope is to subtract the time the pulse’s rising edge occurs from the time the falling edge occurs. In the case of the pulse for 90°, subtract 0.5 ms from 2 ms for a result of 1.5 ms.
- Record the rising and falling edge times for each servo horn angle.
- Calculate the pulse width for each of these servo angles:
Angle Pulse width
0°
45°
90° 2 ms - 0.5 ms = 1.5 ms (Example)
180°