Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| learn:microprocessor:tutorials:software-timing-delays:start [2017/12/21 19:25] – Martha | learn:microprocessor:tutorials:software-timing-delays:start [2022/10/04 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| The purpose of this project is to investigate methods of creating software time delays to pace processor operations. The timing methods that control when a process is to be executed can be implemented by using polling techniques that sample a free running clock or by executing code that requires a fixed amount of time. This project also demonstrates the use of time delays for signal conditioning. | The purpose of this project is to investigate methods of creating software time delays to pace processor operations. The timing methods that control when a process is to be executed can be implemented by using polling techniques that sample a free running clock or by executing code that requires a fixed amount of time. This project also demonstrates the use of time delays for signal conditioning. | ||
| + | |||
| + | \\ | ||
| + | < | ||
| + | <a href="/ | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | < | ||
| + | <a href="/ | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | < | ||
| + | <a href="/ | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| + | < | ||
| + | <a href="/ | ||
| + | </ | ||
| + | \\ | ||
| + | \\ | ||
| ---- | ---- | ||
| Line 13: | Line 35: | ||
| ==== Inventory ==== | ==== Inventory ==== | ||
| - | * 1 [[http://store.digilentinc.com/ | + | * 1 [[https://digilent.com/shop/ |
| * [[http:// | * [[http:// | ||
| - | * 1 [[http://store.digilentinc.com/ | + | * 1 [[https://digilent.com/shop/ |
| - | * 1 Logic analyzer or oscilloscope (Digilent [[http://store.digilentinc.com/ | + | * 1 Logic analyzer or oscilloscope (Digilent [[https://digilent.com/ |
| ---- | ---- | ||
| Line 61: | Line 83: | ||
| It is sufficient to say that each C instruction can require multiple assembly language instructions to implement and each assembly instruction requires time to execute. The bottom line is that the execution of C code requires time and we can use this time to generate predictable time delays. An alternate method to generate a time delay is to use one of the timer resources of the processor. We will investigate both of these two methods of creating a delay function in this project. | It is sufficient to say that each C instruction can require multiple assembly language instructions to implement and each assembly instruction requires time to execute. The bottom line is that the execution of C code requires time and we can use this time to generate predictable time delays. An alternate method to generate a time delay is to use one of the timer resources of the processor. We will investigate both of these two methods of creating a delay function in this project. | ||
| + | |||
| + | ---- | ||
| ==== Pacing the Computer ==== | ==== Pacing the Computer ==== | ||
| Line 66: | Line 90: | ||
| Two approaches for developing a delay function will be explored in this project. One of them requires no special hardware but instead relies strictly upon the execution time of a software loop. We will refer to this approach as the software delay method. The other uses one of the processor' | Two approaches for developing a delay function will be explored in this project. One of them requires no special hardware but instead relies strictly upon the execution time of a software loop. We will refer to this approach as the software delay method. The other uses one of the processor' | ||
| + | |||
| + | ---- | ||
| ==== Pure Software Delays ==== | ==== Pure Software Delays ==== | ||
| Line 95: | Line 121: | ||
| Given that the “mS” variable that specifies the number of milliseconds to delay is an unsigned integer, the range, or longest possible delay, is 4, | Given that the “mS” variable that specifies the number of milliseconds to delay is an unsigned integer, the range, or longest possible delay, is 4, | ||
| + | |||
| + | ---- | ||
| ==== Calibrating Time for Software Delays ==== | ==== Calibrating Time for Software Delays ==== | ||
| Line 102: | Line 130: | ||
| An effective alternative for measuring delay time is to use the MPLAB X Stopwatch tool described in the third tab on the right. | An effective alternative for measuring delay time is to use the MPLAB X Stopwatch tool described in the third tab on the right. | ||
| + | |||
| + | ---- | ||
| ==== Hardware-Assisted Delays ==== | ==== Hardware-Assisted Delays ==== | ||
| Line 239: | Line 269: | ||
| Use the LATBINV = LEDA; and LATBINV = LEDB ; instructions to toggle the two LEDs. You need both instructions to implement the two different delay programs. Connecting an oscilloscope or logic analyzer to the test point for LEDB (RB3) will allow you to measure the total delay being called for from the main function. Connecting the oscilloscope / logic analyzer probe to the test point for LEDA (RB2) will measure the millisecond for loop delay but only for the sw_msDelay function. (Remember to connect the oscilloscope or logic analyzer ground to the PmodSTEP ground pin. See the first tab on the top right for the pin locations.) | Use the LATBINV = LEDA; and LATBINV = LEDB ; instructions to toggle the two LEDs. You need both instructions to implement the two different delay programs. Connecting an oscilloscope or logic analyzer to the test point for LEDB (RB3) will allow you to measure the total delay being called for from the main function. Connecting the oscilloscope / logic analyzer probe to the test point for LEDA (RB2) will measure the millisecond for loop delay but only for the sw_msDelay function. (Remember to connect the oscilloscope or logic analyzer ground to the PmodSTEP ground pin. See the first tab on the top right for the pin locations.) | ||
| - | Figure 1 is an example of the instrumentation to determine the timing for a 20 ms delay. The LEDA trace toggles each 1 ms resulting in a frequency of 500 Hz. The LEDB trace toggles each 20 ms resulting in a frequency of 25 H | + | Figure 1 is an example of the instrumentation to determine the timing for a 20 ms delay. The LEDA trace toggles each 1 ms resulting in a frequency of 500 Hz. The LEDB trace toggles each 20 ms resulting in a frequency of 25 Hz. |
| + | |||
| + | {{ : | ||
| + | |||
| + | Figure 1. Screen capture for 20 ms delay. | ||
| + | Screenshot of Digilent WaveForms running on Microsoft Windows 7. | ||
| + | |||
| + | Complete the data entries for Table 1 using the signal provided by instruments connected to the test point for LEDB and then the MPLAB X Stopwatch tool. When using the MPLAB X Stopwatch tool, place the Stopwatch Start for the first executable line of code in the delay function and set the Stopwatch Stop for the delay function closing brace as noted in the comments for Listing 3 and Listing 4. | ||
| + | |||
| + | ^ Design Total Delay — ms ^ Software Delay — Measured — ms |^ Hardware Delay — Measured — ms || | ||
| + | | ^ LEDB ^ Stopwatch | ||
| + | | 1 | 1 | 0.99775 | ||
| + | | 10 | 10 | 9.97491 | ||
| + | | 100 | 100 | 99.74654 | ||
| + | | 1000 | 1000 | Not valid | 1000 | Not valid | | ||
| + | |||
| + | (Solution values are in red and should be removed prior to distribution to students.) | ||
| + | |||
| + | |||
| + | ---- | ||
| + | |||
| + | ==== Try It on Your Own! ==== | ||
| + | Now that you've completed this project, you should take a look at the following questions and problems: | ||
| + | |||
| + | < | ||
| + | <ol type=" | ||
| + | < | ||
| + | </ | ||
| + | <font color=" | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | <ol start=" | ||
| + | < | ||
| + | </ | ||
| + | <font color=" | ||
| + | |||
| + | A couple of the things the software delay method has going for it is that it is easy to understand the concept, and it is easy to write the code to implement. However, beyond the scope of this project, software interrupts can also be preempted by an interrupt. This results in extending the delay period. The disadvantage is that the processor is completely tied up just incrementing a number unless interrupted. The bottom line is that they are simple by consume processor time.</ | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | </ | ||
| + | <font color=" | ||
| + | |||
| + | Should the software delay loop be interrupted, | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | </ | ||
| + | <font color=" | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | </ | ||
| + | <font color=" | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | </ | ||
| + | <font color=" | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | </ | ||
| + | <font color=" | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | </ | ||
| + | |||
| + | {{tag> | ||

