Beruflich Dokumente
Kultur Dokumente
how often (in ms) is DoIt() run in the following RTI interrupt handler?
CRGFLG |= 0x80;
Given!the!following!register!settings!in!the!9S12!
counter++; !
if (counter >= 254) RTICTL = 0x5F
{ counter = 0; CRGINT = 0x80
DoIt(); CRGFLG = 0xCB
}
} and a core clock frequency of 1.08 MHz
Answer
what is the RTI frequency in Hz?
Selected Answer: 359.0 Answer
Given!the!following!register!settings!in!the!9S12!
1. CRGINT and CRGFLG are ignored, as they only initialize the
! register.
RTICTL = 0x74
CRGINT = 0x92 2. Use RTICTL to find RTI frequency with the following
CRGFLG = 0x8A
formula:
and a core clock frequency of 3.81 MHz,
RTI freq. = Core Clock freq. / Prescale
what does C in the following RTI interrupt handler need to be to
=> Prescale = 1024 * 2^ ([RTICTL bits 6:4] - 1) *
run DoIt() every 699 ms?
([RTICTL bits 3:0] + 1)
void RTI_ISR(void)
{ static int counter = 0; = (1.08 * 10^6) / (1024 * 2 ^ (5-1) * (15 + 1) = 4.12
CRGFLG |= 0x80;
Given the register settings below, what type of signal will produce and input
capture on Pin 0? Question # 11 (OutputCompareLevels)
TCTL1 = 0x82
TCTL2 = 0xBE Given the register settings below, what will happen to Pin 4 upon a successful
TCTL3 = 0x6C output compare of Timer Channel 4?
TCTL4 = 0x78
TCTL1 = 0x27
Correct Answer: TCTL2 = 0x8D
TCTL3 = 0xC9
Disabled TCTL4 = 0xCC
1. This problem deals with edge detection, so use TCTL3 for Correct Answer:
channels 7:4 and TCTL4 for 3:0. It will be set to 1
Question # 11 (MaxCountCalc)
A 9S12 has a core clock frequency of 2.4 MHz. How long (in ms) would it
take the free-running counter to overflow (assuming an initial value 0x0000)
given the following register settings? Question # 11 (SquareWaveCalc)
TSCR1 = 0x97;
TSCR2 = 0x16; A 9S12 has a Bus clock frequency of 9.3 MHz. What is the period of the square
TCTL1 = 0x46; wave (in ms to two decimal places) generated with the following code?
TCTL2 = 0x45;
TCTL3 = 0x16; TSCR2 = 0x91;
TCTL4 = 0x02;
TIOS = TIOS | 0x01;
Correct Answer: TCTL2 = (TCTL2 & 0xFC) | 0x01;
3,495.25 ± 1% TFLG1 = 0x01;
TC0 = TCNT + 7,858;
1. TCNT Rate = Bus Rate / (2 ^ Prescale)
while(1)
=> Bus Rate = Core Clock Rate / 2 {
while((TFLG1 & 0x01)==0);
=> Prescale = TSCR2[2:0] (lower three bits of TC2 = TC2 + 7,858;
TSCR2) TFLG1 = 0x01;
}
-Bus rate = 2.4 * 10^6 / 2 Correct Answer: 3.38 ± 1%
-Prescale = lower three bits of TSCR2 are 110 = 6
2
NOTE: You must enable the enhanced timer capture so that it will be able to set
1. TCNT rate = Bus Rate / (2 ^ Prescale) flags. The flags it sets are always on Port T (or whatever FFEE corresponds to)
3. Period (of the Square Wave) = Period of TCNT * COUNT * -Multiple timer period by 26,890 because timer must get to that before
the alarm goes off
2 -Interrupt must be called 61 times before the port T signal is toggled
so multiply by 61
=> 2 for the toggle (for a square wave, a rise and a fall) -Port T output is toggled… Two toggles are needed to make a square
so multiply by 2
-So answer = 13.122 s
= ([(9.3 * 10 ^ 6) / (2^1)] ^ -1) * 7858 * 2 = .00338 = 3.38ms
Question # 11 (TimerFrequencyCalc)
Question # 11 (SquaeWaveCalcWithOverflow)
A 9S12 needs a timer clock frequency of 11.1 MHz. What would the core
A 9S12 has a core clock frequency of 4 MHz. What is the period of the square
clock frequency (in MHz to three decimal places) need to be given the
wave (in seconds to three decimal places) generated with the following code?
following register settings?
int main(void)
TSCR1 = 0x87;
{
TSCR2 = 0x91;
TIOS |= 0x01;
TCTL1 = 0x22;
TSCR2 = 0x83;
TCTL2 = 0x36;
TFLG1 |= 0x01;
TC0 = TCNT + 26,890; TCTL3 = 0x17;
SETVECT(0xFFEE, oc0_isr); TCTL4 = 0x32;
TIE |= 0x01; Answer
ENABLE();
Correct Answer: 44.400 ± 1%
while (1);
}
3. Period of TCNT = 1 / TCNT rate 1. Use the following equation to solve this problem:
4. Period (of the square wave) = Period of TCNT * COUNT * 2 Timer clock period = 1 / [Bus frequency / (2 ^ Prescale)]
* OverflowCount
=> Bus frequency = Core clock frequency / 2
=> COUNT = count from main function (TCNT + COUNT) => Prescale = TSCR2[2:0]
=> OverflowCount = count from if statement (++count >=
OverflowCount) Question # 11 (PreScaleAndCount)
=> 2 for the two square wave toggles
3
A 9S12 has a bus clock frequency of 8.0 MHz. Give the values necessary for the 4. Prescale can be any value between 0 and 7, inclusive. Test
code below to produce a square wave on channel 0 with a period of 5 ms. each of these values, and try to find a resulting value for Count
TSCR2 &= ~(BIT_3 | BIT_1 | BIT_0); that is closest to an integer. (If multiple reasonable answers
TSCR2 |= PreScale; exist, usually select the largest Prescale value.)
while(1)
{
Question # 13 (CFORC)
while((TFLG1 & BIT_0)==0);
TC0 = TC0 + Count;
TFLG1 = BIT_0;
}
Give a single C instruction which will cause the designated output compare
PreScale = [a] (As a decimal number.) action already programmed for channel 6 to occur immediately (but not
Count = [b] (As a decimal number.) produce an interrupt.) (Leave a single space between all variables and/or
operators and use no parentheses.)
Correct Answers for: a Answer
5
Selected Answer: CFORC = 0x40;
Correct Answers for: b 625
A 9S12 has a bus clock frequency of 8.0 MHz. Give the values necessary for the
code below to produce a square wave on channel 0 with a period of 5 ms. Give a single C instruction which will cause the designated output compare
action already programmed for channel 5 to occur immediately (but not
TSCR2 &= ~(BIT_3 | BIT_1 | BIT_0); produce an interrupt.) (Leave a single space between all variables and/or
TSCR2 |= PreScale; operators and use no parentheses.)
Answer
while(1)
{ Correct Answer: CFORC = 0x20
while((TFLG1 & BIT_0)==0);
TC0 = TC0 + Count;
TFLG1 = BIT_0; 1. Answer is almost always in this form:
}
A 9S12 has a core clock frequency of 1.0 MHz. Give the values necessary
for the code below to produce a square wave on channel 0 with a period
of 28 micro seconds. Assuming that the Bus clock is 9.5 MHz, what is the minimum delay count
value that can be used in DLYCT (as a single decimal digit) to insure the
TSCR2 &= ~(BIT_3 | BIT_1 | BIT_0); input capture system ignores pulses shorter than 76.5 micro seconds?
TSCR2 |= PreScale; (Answer '0' if DLYCT count cannot be large enough to ignore the signal.)
Answer
while(1)
{ Correct Answer: 3
while((TFLG1 & BIT_0)==0);
TC0 = TC0 + Count;
TFLG1 = BIT_0;
} 1. Answer will be 0, 1, 2, or 3. See slide 13.18. Only the lowest
two bits of the register matter.
Prescale = [a] (As a decimal number.)
Count = [b] (As a decimal number.)
4
3. The register OC7M selects the channels which can
2. Bus rate = Core clock rate / 2 POTENTIALLY be changed.
=> 1 selects the channel (pin)
3. Bus period = 1 / Bus rate => 0 leaves it alone (so 0x11 would select pins 4 and 0)
4. Time (of pulses to ignore) / Bus period = Delay 4. The register OC7D then clears and sets ONLY pins in PTT
that have been selected by OC7M.
5. Look up delay on the chart, return its corresponding binary => 1 sets a pin that has been selected by OC7M
value (0, 1, 2, or 3) => 0 clears it (the unselected pins are untouched, even if OC7D
NOTE: You must pick a value equal to or LARGER than your is high for them)
answer, never smaller.
5. If PTT is NOT given, and pin 7:0 output is desired, unknowns
may occur anywhere that OC7M did not select.
Question # 13 (OC7M-OC7D)
Question # 14 (FindPWMClockFreq)
Given!the!following!Bus!Clock!frequency!and!register!settings!for!the!9S12,!give!
Give!the!values!for!OC7M!and!OC7D!so!that!the!following!channels!will!be!
the!PWM!clock!frequency!(in!kHz!to!3!decimal!places)!for!channel!2.!
affected!as!described!below!by!a!successful!output!compare!on!Channel!7.!
!
!
fBus = 9.50 MHz
Channel 4 Sets to 1
Channel 3 Sets to 1
Channel 1 Sets to 1
PWMPRCLK = 0x14
Channel 0 Clears to 0
PWMSCLA = 0x49
PWMSCLB = 0x6A
PWMCLK = 0x79
OC7M = [a];
Answer
OC7D = [b];
Selected Answer: 4750
Correct Answers for: a 0x1B
1B
ALGORITHM FOR FINDING PWM CLOCK
1B
FREQUENCY
Correct Answers for: b 0x1A
1A 1. Bus frequency = Core clock frequency / 2
1A
2. Determine which clock is being used, according to which
channel is under inspection:
Given!the!code!below,!what!will!be!the!new!state!(0,!1,!or!Unknown)!of!each!
Port!T!pin!listed!below!after!the!Channel!7!timer!system!has!had!a!successful!
output!compare?! => Clock A or SA: channels 0, 1, 4, 5
! => Clock B or SB: channels 2, 3, 6, 7
DDRT = 0xFF
TIOS = 0xFF 3. PWM Clock = Bus frequency / (2 ^ Prescale)
PTT = 0xD8
TCTL1 = 0x3C
TCTL2 = 0xF4 => For clock A, Prescale = PWMPRCLK [2:0]
TCTL3 = 0x45 => For clock B, Prescale = PWMPRCLK [6:4]
TCTL4 = 0xD3
Pin 7 = [a] 1
=> Look at the PWMCLK register, at the pin
Pin 6 = [b] 1 corresponding to the observed channel
Pin 5 = [c] 1 - If pin = 1, use “S” variant
Pin 4 = [d] 1 - If pin = 0, use clock A or B
Pin 3 = [e] 0
Pin 2 = [f] 1
Pin 1 = [g] 0
5. If clock is an “S” variant, i.e. SA or SB, then apply another
Pin 0 = [h] 0 scaling with this formula:
5
Given!the!following!Core!Clock!frequency!and!register!settings!for!the!9S12,!
Question # 14 (FindPWMPER) supply!the!parameters!for!the!PWM!waveform!produced!on!Channel!1.!
!
fCore = 12.7 MHz
Given!the!following!Bus!Clock!frequency!and!register!settings!for!the!9S12,!
provide!the!settings!for!PWMPERn!and!PWMDTYn!in!order!to!produce!a!PWM!
waveform!on!Channel!3!with!the!given!parameters.! PWMPRCLK = 0x63
! PWMSCLA = 0xC4
fBus = 0.85 MHz PWMSCLB = 0x30
PWMCLK = 0xB7
PWMPER1 = 0xCA
PWMPRCLK = 0x04 PWMDTY1 = 0x95
PWMSCLA = 0xD3 PWMPOL = 0x4B
PWMSCLB = 0x1F PWMCAE = 0xAC
PWMCLK = 0x01
PWMPOL = 0x75
PWMCAE = 0x7E (Give all answers to nearest integer)
4. Solve the following equation relating PWM freq., waveform PWMPRCLK = 0x72
freq., and PER, for PER: PWMSCLA = 0x16
PWMSCLB = 0xBB
PWMCLK = 0x11
PWM Waveform frequency = PWM Clock frequency / PER PWMPOL = 0x1D
PWMCAE = 0xF4
5. PER = PWMPER PWMCTL = 0x20
PWMPER0 = 0x7A PWMDTY0 = 0x5A
PWMPER1 = 0xD7 PWMDTY1 = 0xA9
6. Now to determine the PWMDTY, first check the PWMPOL PWMPER2 = 0x72 PWMDTY2 = 0x64
bit corresponding to the observed channel. Then solve the PWMPER3 = 0xBD PWMDTY3 = 0x8F
PWMPER4 = 0x7A PWMDTY4 = 0x5F
resulting equation for PWMDTY: PWMPER5 = 0x93 PWMDTY5 = 0x6E
PWMPER6 = 0xCB PWMDTY6 = 0xA6
=> If the polarity is 1: 100 * PWMDTY / PWMPER = Duty PWMPER7 = 0xCC PWMDTY7 = 0xAB
Factor %
=> If the polarity is 0: 100 * (PWMPER - PWMDTY) / (Give all answers to nearest integer)
PWMPER= Duty Factor %
For Channel 3:
NOTE: If you end up with a value that is not an integer, PWM Period = [a] ms
round PWM Time High = [b] ms
PWM Duty = [c] %
6
PWMCLK = 0x66
Correct Answers for: b 549 PWMPER7 = 0xB5
PWMDTY7 = 0x24
Correct Answers for: c 88 PWMPOL = 0x28
PWMCAE = 0xB8
Given!the!register!settings!below,!what!form!below!best!describes!the! 3. Test the 8 possible values of PCKA (0:7) and write down any
waveform!created!on!PWM!Channel!7?!!
values of PCKA such that PWMSCLA turns out to be an integer
!
PWMPRCLK = 0xD9 less 256 (as well as the corresponding PWMSCLA values).
PWMSCLA = 0x6C PWMSCLA must be very close to an integer (must be able to
PWMSCLB = 0xA1 round to .99 or .01)
7
>>Write a C instruction to reset the interrupt flag for pin 7 of Port H. Correct
Answer: PIFH = PIFH | 0x80;
>>To have the processor boost the priority of an interrupt on timer 7, we How many Output Compare channels are there on the 9S12: 8
would put a value of [a]in the [b] register. Correct Answers for: a 0xE0
OUTPUT COMPARE (has edge define)
Correct Answers for: b HPRIO INPUT CAPTURE (Has edge detect)
>>To have the processor run doatod() when timer the A/D 1 produces an What signal values/transitions can the Output compare system produce at a
interrupt we would run the following instruction: SETVECTOR([a], [b]); pin? {High Value, Low Value, Toggle}
Correct Answers for: a 0xFFD0 Correct Answers for: b doatod
What signal values/transitions can input capture be initialized to detect?
>>HPRIO = “boosts” priority of an interrupt source {Rising Edge , Falling Edge}
>>When the X-bit of the CCR is [a], the non-maskable interrupt is disabled: RTIE turns on or off the RTI
1 (or “one”) 16 bit registers: {TCNT, TC4,TC5}
>>The x bit in the CCR controls the non-maskable interrupt of the 9S12 Give a single C statement to set the Enhanced Capture System of a 9S12 to
produce the following transitions on the following pins of Port T given a
>>The X-bit of the CCR cannot be set to 1 through software. successful output compare. {Pin 7 = timer disconnected from pin; Pin 6 = Set
Line; Pin 5 = Toggle; Pin 4 = Clear Line). Correct answer: TCTL1 = 0x36;
>>Timing Errors—(synchronous: in time; asynchronous: not in time)
>>Write a single C instruction to reset the interrupt flags for every pin on
Port H. Correct Answer: PIFH = 0xFF;