What is the smallest divider possible that could still allow the timer to produce the same overflow period? Assume, of course, that the timer’s period (in counts) can also change.
We have a 16-bit Timer_A (so its maximum count is 65536). We can use this inequality.
Convert the flow chart to an equivalent segment of code.
flowchart LR
A([Start]) --> B{Are a and b both zero?}
B -- Yes --> C([Done])
B -- No --> D[Divide a by 2 and save back into a]
D --> E[Multiply b by a and save back into b]
E --> B
flowchart LR
A([Start]) --> B{Are a and b both zero?}
B -- Yes --> C([Done])
B -- No --> D[Divide a by 2 and save back into a]
D --> E[Multiply b by a and save back into b]
E --> B
1
2
3
4
while(a==0&&b==0){a=a/2;b=b*a;}
Q4 Timer / Interrupt Code
Given the complete program below and knowing that SMCLK is 12 MHz, answer the following questions.
voidIncA(),IncB(),IncC();uint8_tA=0,B=0,C=0;Timer_A_UpModeConfigtim_config;uint32_ttimer=XXXXXXXXX;// Some valid value
voidmain(){SysInit();TimerInit();while(1){// To fill in
}}voidTimerInit(){tim_config.clockSource=TIMER_A_CLOCKSOURCE_SMCLK;tim_config.clockSourceDivider=TIMER_A_CLOCKSOURCE_DIVIDER_32;tim_config.timerPeriod=12345;tim_config.timerClear=TIMER_A_DO_CLEAR;tim_config.timerInterruptEnable_TAIE=TIMER_A_TAIE_INTERRUPT_ENABLE;Timer_A_configureUpMode(timer,&tim_config);Timer_A_registerInterrupt(timer,TIMER_A_CCRX_AND_OVERFLOW_INTERRUPT,IncC);Timer_A_startCounter(timer,TIMER_A_UP_MODE);}voidIncA(){Timer_A_clearInterruptFlag(TIMER_A1_BASE);A++;}voidIncB(){Timer_A_clearInterruptFlag(TIMER_A2_BASE);B++;}voidIncC(){Timer_A_clearInterruptFlag(TIMER_A3_BASE);C++;}
Q4.1
What function given in this code is and will be called as an Interrupt Service Routine? Give the function name.
1
IncC()
Because the line Timer_A_registerInterrupt(timer, TIMER_A_CCRX_AND_OVERFLOW_INTERRUPT, IncC); It sets up IncC() as the ISR for the timer interrupt.
Q4.2
How often is this function triggered by the hardware? Give your answer in milliseconds.
Write a segment of code to be placed in the while(1) loop that would implement a blocking delay of approximately 5 s without using __delay_cycles() such that the message “5 seconds” is printed after each delay.
Write a segment of code to be placed in the while(1) loop that would implement a non-blocking delay of approximately 5 s without using __delay_cycles() such that the message “5 seconds” is printed after each delay and “not blocked” is printed continuously.