CSEP567 PreLab 6: "Accelerometer PWM"
Task
Create programs to read the X and Y axes of the accelerometer.
Suggested Reading
Suggested Steps
PART 1:
-
Implement a program that uses timer 1 input capture mode, (accelerometer y-axis output to
ICP1 pin 20), to determine the positive duty cycle of the y-axis accelerometer.
To do this, time the length of the positive pulse of your accelerometer (rising
edge to falling edge) and the length of the period (rising edge to next rising
edge). Use the 7-segment LED to display a "1" when the accelerometer has a duty
cycle less than 50% and a "2" when the accelerometer has a duty cycle greater
than or equal to 50%.
NOTES:
-
You should choose as small a prescaler factor as possible for Timer 1 to
increase the accuracy.
-
Assume a period of 4 ms. for the Accelerometer outputs.
-
Use TCNT1 and ICR1 to access 16-bit values instead of using the 8-bit registers
(i.e. ICRL & ICRH and TCNT1L & TCNT1H)
-
Remember to set TCNT1=0 when you want the counter restart at 0. The input
capture interrupt does not reset TCNT1 to zero automatically
PART 2:
-
New program: Define the x-axis of the accelerometer as an input on INT0 (pin 16).
-
Use INT0 and Timer2 to create a manual interupt capture routine to determine
the positive duty cycle of the x-axis.
-
Implement a program that measures the x-axis and drives the 7-segment LED as in
part 1.
Question
Question 1: What would you change to accurately read a signal period of 1 msec?
Question 2: What are the accuracy differences between the input capture of
the x-axis and the y-axis? (Please list more than one difference in your answer)
Turn-In
Please complete the prelab individually. Please turn-in your commented C
code for both parts along with the answer to the question at the beginning
of next week's lab.