Question: Consider the following code segment that utilizes the watchdog timer in in the interval mode with period set to 1 s (line 4 of the
Consider the following code segment that utilizes the watchdog timer in in the interval mode with period set to 1 s (line 4 of the code).
#include
void main(void) {
int p = 0;
WDTCTL = WDT_ADLY_1000; // 1 s interval timer
P2DIR |= BIT2; // Set P2.2 to output direction
P2OUT |= BIT2;
for (;;) {
if ((IFG1 & WDTIFG) == 1) {
p++;
if (p == 5) {P2OUT ^= BIT2; p=0;}
IFG1 &= ~WDTIFG;
}
}
}
A. (5 points) What does the code segment do? Sketch the signal you would observe on P2.2.
B. (5 points) How would you implement the given functionality using an interrupt service routine.
C. (10 points) You would like to generate two pulse-width modulated (PWM) signals P1 (75% of duty cycle) and P2 (50% of duty cycle), with frequency of 1 KHz. Assume that an external high-frequency resonator is used to provide 8MHz clock on ACLK that is used by TimerA. Can you do this using TimerA? If yes, describe a TimerA configuration that will carry out signal generation? Note: use English and waveforms to describe your solution.
| P1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| P2 |
|
|
|
|
|
|
|
|
|
| 0ms | 0.25ms | 0.5ms | 0.75ms | 1ms | 1.25ms | 1.5ms | 1.75ms |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
