CSCE 236 Embedded Systems, Spring 2014
Lab 3


Wednesday, February 19, 2013
Individual checkoff for section 4
due before class: Friday, February 28, 2014
Names of Group Members:


1  Instructions

This is a group assignment to work on during class. You only need to hand in one copy of this, but make sure that the names of all of your group members are on this sheet to receive credit. Complete all of the sections below and make sure to get the instructor or TA to sign off where required. You should keep your own notes on what you complete since parts of future homework will build on this lab.

2  Dimming LEDs

In this section you will take two different approaches to solving the same problem. The goal is to dim one of the LEDs whenever the button is pressed. You can dim an LED by only turning it on for a very short amount of time and then turning it off for a period of time. If you do this faster than about 30 Hz, you will not notice the flickering of the LED turning on and off and it will appear dimmer than if it is fully on (since the human eye acts as an integrator at this frequency).

2.1  Manual

First, you will achieve this by using manual delays. Download the sample code for this lab from the course website and examine it. Make sure you connect your LEDs and buttons to the proper pins by examining the code. This code dims the RED LED when the button is pressed. It does so by using the function delay(ms). Try changing the values of the delays and determine what values work well? Approximately what is the frequency and duty cycle that it is being dimmed at? If you increase the amount of time the LED is off, at what frequency can you start to see the LED pulsing?
The problem with this approach is that the processor is always busy doing the pulsing of the LED to dim it. If a function is called that prevents this from occurring, the LED will not dim properly. To see this, insert another delay of 100 milliseconds outside of the logic that controls the LED. This simulates the execution of other code that takes a while to complete. What happens when you press the button now?
Checkoff: Show the LED dimming when the button is pressed with and without the 100ms delay. What frequency and duty cycle are you using with your LED?

2.2  PWM

To overcome the problem that you cannot easily do other actions while dimming the LED, you will now implement LED dimming using PWM. To do this, connect your LED to pin PB2 (pin 10 on Arduino, which should have the blue LED connected to it already), which is also OC1B (output compare B for timer1). Download the core code from the course website.
Now, look at section 16 (Timer/Counter1) of the datasheet (the description of fast PWM mode in 16.9.3 and the register description in 16.11 are especially useful). The code I gave you already configures it so:
You need to:
Checkoff: Show the code using the PWM system to dim the LED when the button is pressed. Note how adding code (e.g. delay(100)) in the main loop no longer impacts the dimming. Be sure to show us how you got 1Khz clock.

3  Servo Control

Servos are also controlled by PWM signals. Most servos enable angular control of the output shaft (e.g. between 0 and 120 degrees). The servos we are using in class are known as continuous rotation servos. Instead of controlling position, we are able to control the forward and backward rotational speed using PWM signals. Most servos use PWM signals with a period of approximately 20 milliseconds. By varying the pulse length between 1ms to 2ms the servo will go from full speed forward to full speed backwards (on a traditional servo this would mean rotating from 0 to 120 degrees).
You have seen how to manually configure the PWM channels to control the frequency and duty cycle. However, instead of manually configuring all the PWM channels, we will instead make use of an Arduino servo control library. Read the information on how to use the servo library here:
http://arduino.cc/en/Reference/Servo
To hook up the servos to your breadboard, you will need to first use the 3-pin header to adapt the female servo connector to a male connector. Then, connect the black wire to ground, red to power (5V), and white to the PWM signal. Double check these connections before powering your board. Also note that the servos can draw more power than a USB port can supply. Therefore, you should not restrict the output of the servo while using USB power, instead make use of the AC adapter to power the servos whenever AC power is available.
Before you fully construct your robot, write code that reverses the direction of one servo whenever the button is pressed. If you have trouble with this please ask for help!

4  Building Robot and Driving Primitives

This section of the lab requires individual checkoff for each person. I do not expect you to complete this in lab so please come and get checked off by the date indicated above.
You should now use the supplied parts to build your own robot as demonstrated in Lab and the online instructions: http://cse.unl.edu/~carrick/wordpress/?p=130
Checkoff: Create driving primitives that enable you to drive in a straight line and also rotate a particular angle (e.g. 90 degrees). Program your robot so that when you press the button it will drive a square. The turning and distance traveled will depend a lot on the surface you are driving on, so I would recommend you make this easily tunable to adjust to different surfaces. Also, these are functions you will be using a lot for the rest of the semester. So it is worth investing a little time to make the code reusable.



File translated from TEX by TTH, version 3.89.
On 18 Feb 2014, 14:46.