Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Problem: The following HCS12 program generates a square wave on pin PTO: (10 pts

ID: 2291871 • Letter: P

Question

Problem: The following HCS12 program generates a square wave on pin PTO: (10 pts) 1.void main(void) // Set up timer TSCRI = 0x80; // Enable timer (TEN=1), no fast flag clear (TFFCA=0) TSCR2 = 0x00; // No interrupts (TO1:0), prescale-000 4 // Set up output compare on channel 0 TIOS = 0xff; // All Port T is output TCTL2 = 0x01; // Configure PTO to toggle TIE = 0x01; // Enable interrupts on channel 0 TFLG1 = 0x01; // Clear any compare flag (COF) _asm CLI; 10. 12 13. for() ( 14 15 16. 17 18. void interrupt (((0x10000-Vtimch7)/2-1) void TCO ISR (void) 19 20 21. FEED_COPO TFLG1 = 0x01; // Clear compare flag (COF) TC0 = TC0 + 6000 (a) Assuming a 24 MHz clock, what is the period of the square wave generated? (b) Describe the output signal if the programmer used "TCO TCNT+ 6000;" on line 20 (c) Describe the output signal if the programmer forgot to enable interrupts (the instruction on line 9)

Explanation / Answer

(a) Assuming a 24 MHz clock, what is the period of the square wave generated?

Answer. The timer system is configured for the fastest possible rate, using the prescaler value of 000 (line 9). That means it uses the full 24 MHz clock rate. At 0.042 us per count, 6000 counts is 0.25 ms. The complete period is 0.5 ms.

(b) Describe the output signal if the programmer used “TC0 = TCNT + 6000;” on line 3.

Answer. The period of the square wave would not be exactly 0.5 ms, but it would be a little longer, and it would vary slightly. The reason is that TCNT keeps incrementing after the compare action occurs, and so its value on line 3 is a little bigger than what is in TC0.

(c) Describe the output signal if the programmer forgot to enable interrupts (the instruction on

line 9).

Answer. The ISR would never be executed. However, the pin would still automatically toggle every time the timer register (TCNT) equaled whatever was in the compare register. This would happened every 65536 counts, or 65536*0.042 us = 0.00273 seconds. So a square wave would still be generated, but its period would be 2*0.00273 = 0.00546 seconds.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote