This shows you the differences between two versions of the page.
milestone_3_task_2 [2023/02/20 21:04] scott [Transmitter] |
milestone_3_task_2 [2023/03/02 17:53] (current) scott [Source Code] |
||
---|---|---|---|
Line 62: | Line 62: | ||
* drivers/switches.h | * drivers/switches.h | ||
* include/leds.h | * include/leds.h | ||
+ | * include/mio.h | ||
+ | * include/utils.h | ||
* lasertag/main.c | * lasertag/main.c | ||
* lasertag/transmitter.h | * lasertag/transmitter.h | ||
Line 323: | Line 325: | ||
void transmitter_runTest() { | void transmitter_runTest() { | ||
printf("starting transmitter_runTest()\n"); | printf("starting transmitter_runTest()\n"); | ||
- | mio_init(false); | ||
- | buttons_init(); // Using buttons | ||
- | switches_init(); // and switches. | ||
transmitter_init(); // init the transmitter. | transmitter_init(); // init the transmitter. | ||
- | transmitter_enableTestMode(); // Prints diagnostics to stdio. | + | while (!(buttons_read() & BUTTONS_BTN3_MASK)) { // Run continuously until BTN3 is pressed. |
- | while (!(buttons_read() & BUTTONS_BTN1_MASK)) { // Run continuously until BTN1 is pressed. | + | |
uint16_t switchValue = switches_read() % FILTER_FREQUENCY_COUNT; // Compute a safe number from the switches. | uint16_t switchValue = switches_read() % FILTER_FREQUENCY_COUNT; // Compute a safe number from the switches. | ||
transmitter_setFrequencyNumber(switchValue); // set the frequency number based upon switch value. | transmitter_setFrequencyNumber(switchValue); // set the frequency number based upon switch value. | ||
Line 338: | Line 336: | ||
printf("completed one test period.\n"); | printf("completed one test period.\n"); | ||
} | } | ||
- | transmitter_disableTestMode(); | ||
do {utils_msDelay(BOUNCE_DELAY);} while (buttons_read()); | do {utils_msDelay(BOUNCE_DELAY);} while (buttons_read()); | ||
printf("exiting transmitter_runTest()\n"); | printf("exiting transmitter_runTest()\n"); | ||
Line 411: | Line 408: | ||
You can access this signal at the "Transmitter Probe" pin on the development board. To test the transmitter state machine, do the following in ''transmitter_runTest''. | You can access this signal at the "Transmitter Probe" pin on the development board. To test the transmitter state machine, do the following in ''transmitter_runTest''. | ||
- | - loop until Button 3 is pressed: | + | - Loop until Button 3 is pressed: |
- Read the slide switches and use the numerical value of the switches as the frequency index. When all switches are in the down position (closest to the bottom of the board), you should generate the waveform for frequency 0. Sliding switch (SW0) upward would select frequency 1, and so forth. | - Read the slide switches and use the numerical value of the switches as the frequency index. When all switches are in the down position (closest to the bottom of the board), you should generate the waveform for frequency 0. Sliding switch (SW0) upward would select frequency 1, and so forth. | ||
- Set the frequency using the ''transmitter_setFrequencyNumber()'' function. | - Set the frequency using the ''transmitter_setFrequencyNumber()'' function. | ||
- | - Invoke ''transmitter_run()''. | + | - Invoke ''transmitter_run()'' and then wait for ''transmitter_running()'' to return false. |
- Use the utils_msDelay() function to delay for approximately 400 ms, long enough to demonstrate the operation of the transmitter on the oscilloscope. | - Use the utils_msDelay() function to delay for approximately 400 ms, long enough to demonstrate the operation of the transmitter on the oscilloscope. | ||
- Wait for the release of Button 3. | - Wait for the release of Button 3. | ||
Line 423: | Line 420: | ||
Access and display the transmitter output as described above. In your test function, do the following: | Access and display the transmitter output as described above. In your test function, do the following: | ||
- Invoke ''transmitter_setContinuousMode(true)'', ''transmitter_run()'' prior to entering an endless loop. | - Invoke ''transmitter_setContinuousMode(true)'', ''transmitter_run()'' prior to entering an endless loop. | ||
- | - loop until Button 3 is pressed: | + | - Loop until Button 3 is pressed: |
- Set the frequency using the ''transmitter_setFrequencyNumber()'' function. | - Set the frequency using the ''transmitter_setFrequencyNumber()'' function. | ||
- Wait for the release of Button 3. | - Wait for the release of Button 3. | ||
Line 437: | Line 434: | ||
As you transition to the state when the "press" of the trigger has been successfully debounced, print the 'D' character to the console using the DPCHAR() macro shown above. Make sure that you only print the 'D' character once as you enter the state when the trigger switch has been successfully debounced. Similarly, print out a 'U' character when the release of the trigger has been debounced. If you only print out a single 'D' and a single 'U' for each press-release of BTN0, the trigger is probably getting debounced properly. | As you transition to the state when the "press" of the trigger has been successfully debounced, print the 'D' character to the console using the DPCHAR() macro shown above. Make sure that you only print the 'D' character once as you enter the state when the trigger switch has been successfully debounced. Similarly, print out a 'U' character when the release of the trigger has been debounced. If you only print out a single 'D' and a single 'U' for each press-release of BTN0, the trigger is probably getting debounced properly. | ||
- | In ''trigger_runTest()'', enable the trigger state machine and demonstrate the required behavior to the TA. | + | In ''trigger_runTest()'', enable the trigger state machine and demonstrate the required behavior to a TA. |
==== Hit LED Timer ==== | ==== Hit LED Timer ==== | ||
- | Goal: demonstrate that your hitLedTimer state machine illuminates LD0 and drives a '1' onto the JF-3 pin for 1/2 second each time it is activated. You will see LED1 blink on and off at 1/2-second intervals if this is working correctly. LED1 is directly connected to JF-3 and is provided for debug and pass off. | + | Goal: demonstrate that your hitLedTimer state machine illuminates LD0 and drives a '1' onto the JF-3 pin for 1/2 second each time it is activated. You will see LED1 blink on for 1/2-second intervals if this is working correctly. LED1 is directly connected to JF-3 and is provided for debug and pass off. |
In your ''hitLedTimer_runTest()'' function do the following inside a while-loop: | In your ''hitLedTimer_runTest()'' function do the following inside a while-loop: | ||
- | * Step 1: invoke ''hitLedTimer_start()'', | + | * Step 1: invoke ''hitLedTimer_start()''. |
* Step 2: wait until ''hitLedTimer_running()'' is false (use another while-loop for this). | * Step 2: wait until ''hitLedTimer_running()'' is false (use another while-loop for this). | ||
- | * Delay for 300 ms using utils_msDelay(). | + | * Step 3: Delay for 300 ms using utils_msDelay(). |
* Go back to Step 1. | * Go back to Step 1. | ||
- | Demonstrate to the TA that LD0 and LED1 is blinking at a rate of 1/2 second (this will be approximate because this will be a visual inspection). Also show the TA that pin "Hit Detected" has the appropriate waveform by attaching an oscilloscope probe to the "Hit Detected" pin. | + | Demonstrate to a TA that LD0 and LED1 blink on for 1/2 second (this is an approximate visual inspection). |
{{::hitledpicture.jpg?400|}} | {{::hitledpicture.jpg?400|}} | ||
Line 464: | Line 461: | ||
- Print out the time duration from the interval timer. | - Print out the time duration from the interval timer. | ||
- | Show the TA the execution of ''lockoutTimer_runTest()''. | + | Show a TA the execution of ''lockoutTimer_runTest()''. |
==== Code Submission ==== | ==== Code Submission ==== |