Script and Tests

Script: servo_plot

  • Right-click servo_plot.hex and select Save link as... to download it.

servo_plot.hex

  • Go to python.microbit.org/v/2.
  • Click Load/Save and then drag the file you just downloaded and drop it on the gray box in the Load section.  
  • Click the Flash button to load the script into the micro:bit.
  • Click Disconnect.


Tests

  • Go to cyberscope.parallax.com BUT DO NOT CLICK CONNECT YET.
  • Change the Device dropdown from Auto to Oscilloscope.
  • Change Time/Div from 1000 ms to 5 ms.
  • Change V/Div from 0.5 V to 0.75 V.
  • Now, click Connect.
  • Wait for at least one full plot to display.  (It won’t look like the image below yet.)
  • Set Trigger to Rise.
  • The milliseconds (ms) trigger time control will start at 10 ms.  Slide it to 5 ms.

Your display should now resemble this one: 

 

The time that the signal stays high (at 3.3 V in this case) is called the pulse width.  Here, we are not going to measure the pulse width, just observe how it contains information that tells the servo what angle to hold.  

 

  • Observe your servo and the pulse widths in your CYBERscope, and then answer these questions:
  1. Which servo horn angle corresponds to the narrowest pulse widths?
  2. Which servo horn angle corresponds to a pulse width that’s half way between the widest pulse widths?
  3. Which servo horn angle corresponds to the widest pulse widths?

 

One thing we can measure at 5 ms/div is the signal’s period (T).  This was first introduced in the Connect and Blink a Light activity’s On-Off Signals page.  It introduced the period of an on/off signal like a blinking light or this servo signal as tHIGH + tLOW, but take a look at what happens between the rising edges in the CYBERscope.  See how the time between rising edges contains both the high (pulse width) and low times in the signal?   

  • Record the times of the rising edges in your CYBERscope, then answer these questions:
  1. Calculate the signal period by subtracting the millisecond time of the first rising edge from the time of the second.  What is the signal period?  
  2. If you subtract the millisecond time of the second rising edge from the third, is it the same period?
  3. Does the period change as the servo horn angles change?
  4. Review converting milliseconds to seconds in Convert Prefixes to Values, and calculate what 20 ms is in terms of seconds.
  5. Look up how to calculate the frequency of an on/off signal in the activity’s On-Off Signals page, and use it to calculate the frequency of this signal.  Make sure to use the period in seconds, not in milliseconds in your calculations.  (You figured out how many seconds in 20 milliseconds in question 7.) What is the frequency of this signal?
  6. How many times per second does this signal repeat itself?