CSc 4110/6110 Embedded Systems
Lab Experiment
Instructor: Dr. Michael Weeks

Interrupt-based Temperature

This lab will introduce you to reading the temperature based on an interrupt. You will need to download and install the Arduino FreeRTOS library. With this, you can make programs with commands like xTaskCreate, vTaskStartScheduler, xTaskResumeFromISR, vTaskSuspend, and taskYIELD. Also, we will use interrupts, such as the attachInterrupt function.

Part 1

There is example code called Blink and AnalogRead (right after "Next Steps") that defines two tasks. The first one, Blink, turns the LED on and off, repeating the cycle every 2 seconds. The other one, AnalogRead, reads the value from an analog pin, and send the value through the serial connection. Copy this code into a new program, and get it to work. You will need to change the line at the top from
  #include
to
  #include <Arduino_FreeRTOS.h>

For the value to read, you can use the temperature sensor, though you will need to change the "analogRead(A0)" part to what you used for the temperature reading lab. Also, adjust "vTaskDelay(1)" to a 5 second delay. Test it out with the Serial Monitor. When this is working, and you are comfortable with how it works, go on to the next part.

Part 2

The page on interrupts has example code on it. Copy this to a new program. Note that the "ledPin" that it defines is the same pin number (13) as the Blink and AnalogRead code. You should be able to attach something to pin 2 (like the float sensor, or a push-button switch if you have one). Get this example code to work, and test it out until you are comfortable with how it works.

Part 3

As you probably guessed, this part combines the first two. Make a new program, and copy in the relevant parts of the previous two. In part 1, the code sets up two tasks. Keep the "TaskAnalogRead" task the same as it is in part 1. For the "TaskBlink" function, alter it to check a boolean value on each pass of the loop. If the boolean value is false, have the task wait for 1 second before it repeats the loop. Otherwise (i.e., the boolean value is true) set it to false, turn the LED on, wait 1/4 seconds, then turn the LED off. After this, have the task wait for 3/4 seconds before repeating the loop.

For the interrupt part, the ISR should set the boolean value to true whenever an interrupt happens. Thus, the LED should flash when the interrupt happens. Test it out to make sure that it works as expected.

Questions

  1. What values did you change the 1 from vTaskDelay(1) to? Explain how you determined the correct value to use.
  2. What is the purpose of the volatile keyword? Did you use it in your code?
  3. What are the other possibilities for the interrupt triggering?
  4. When signaling an interrupt, is there any "bounce" in the signal, where it rapidly changes off and on? How would you find out? What would that look like to the system?
  5. One of the tasks is called "AnalogRead," though the name is not really fitting as we have adapted the task in this assignment. What would you change it to? Would a global-replace of "analogread" to the new name, before changing anything else from the code in the original example, work? What places would need to be consistently changed for the code to work, and which instances of "AnalogRead" are only for other programmers to read?
  6. What does "INPUT_PULLUP" mean?
  7. In the attachInterrupt command, does it matter whether you use digitalPinToInterrupt(pin) or pin ? Why or why not?


What to Turn In

Follow the directions on Lab Report format, given on the class web-page. Write-up what you did IN YOUR OWN WORDS. Do not simply re-word the directions, but explain what is going on. Avoid listing steps. Use outside sources as appropriate, and be certain to cite your sources. If you copy and paste ANY text, put it in double-quotes and include a citation immediately after it.

Please see the link to the lab format.