CS计算机代考程序代写 algorithm Microcontrollers and embedded programming

Microcontrollers and embedded programming
• Page limitsfor each question:
o Question 4: No more than three pages (two pages should be sufficient). o Question 5: No more than two pages (one page should be sufficient).
o Question 6: No more than four pages (three pages should be sufficient).
• 4. C onsider an algorithm running on a microcontroller that performs a sequence of transitions between states (see Note 4.1) for a given input and with the following characteristics:
• Each state represents an integer number (see Note 4.2);
• The algorithm moves between states depending on whether either or both push buttons
(denoted by Pl and P2, respectively) on the microcontroller are pressed;
• While the push button (s) are pressed, LEDl blinks if the next integer is higher, otherwise LED2
blinks;
• When in a steady state, if the integer is even, an external counter connected to the
microcontroller counts up, otherwise it counts down. Complete the following tasks:
a. Sketch the state machine diagram corresponding to the algorithm that generates the given sequence of transitions. What type of state machine is this?
b. List and explain the events, activities and actions that take place in this machine.
c. Write equivalent C code representing this machine using the nested-if approach.
d. Write equivalent C code representing this machine using the state table approach.
Note 4.1: Use the last (rightm一ost) d一igit of your 一student num一ber to一identify the sequenc一e of
transitions you must use for your scenario based on Table 4.1. For example, if your student
number is “16004963”, then you must use transition sequence number 3 being ”
P2 P2 Pl P2 PlP2 PlP2 PlP2 Pl PlP2 Pl Pl P2 PlP2
SO ➔Sl➔S2➔S3➔S3➔SO SO➔SO”
S3
S2➔S2
SO➔SO
S3
S1➔S1➔S2 ➔Sl
Note 4.2: To obtain the list of integers corresponding to the states for your scenario, split your eight-digit student number in four two-digit integers starting from the left. For example, if your student number is “16004963”, then the integers corresponding to states SO to S3, respectively, will be “16”, “00”, “49” and “63”.
[15 marks]

Last Digit Of Student Number 。
1 2 3 4 5 6 7 8 9
Corresponding sequence of transitions



一 一



一 一



Sl ➔
soP1P2 一
Pl
SO➔ SO➔ S1➔ S2➔ S3➔S3




S1➔S1 ➔ S2 ➔ SO




P2 一
一 一
SO P➔l S1 Pl ➔
SO
P1P2
P2 P1P2
P2

Pl
SO➔ S3➔S3
P1P2 一
S1➔S1
PlP2 Pl P2 PlP2 P2 P2

S1➔ S2➔ S3➔S3➔ S2➔S2➔ SO➔SO➔ S3 ➔ S1 一
SO
Table 4.1

Push button combination
(Given as: Current State S1 ➔S1 P➔1 S2P1P2 P2 P1 P2 P2
Next State)


P1P2
P1P2 P1P2
P2 P2 P1 S3 ➔ S1 ➔ S2 ➔ S1

SOP2 Pl一PlP2 Pl Pl Pl PlP2 PlP2 P2 P2 P2 PlP2 P2 Pl
SO SOP1P2 P1P2 P2
S3—+SO
P1P2 Pl Pl
S2➔S2
P1 P2 P1 P2
P2 P1P2 P1



SO➔ SO➔ S1➔ S2➔ S3➔S3 P1P2 P1P2 P1
S1
SO➔SO
S2 ➔ S3➔S3
S3 ➔S3
P2 P2 P1 P2 P1P2 P1P2
SO —+ Sl —+ S2—+ S3➔S3—+ SO
S2➔S2
SO P1






SO➔SO
S1 ➔Sl P➔2 S2P1P2 Pl P2 P1
P1P2
SO➔SO S2➔S2
S1 S3
S2 ➔ S1
S2
P1P2 P1 P1P2 P1 P1 P2 P1P2



一 一
SO➔SO
SO➔ S3➔ S2➔S2➔ SO➔ SO➔ S3➔ Sl➔Sl➔ S2


S3 SO-+ SO
S2➔S2
Pl P2 Pl Pl Pl P2 P2 P1P2 P1P2 P1P2 P2 P1P2 P1
P1P2 P1P2 P2
SO➔SO
SO
S3 ➔S3—+SO—+SO➔S0—+S1—+S2—+S1—+S2—+S3
S2
SO➔SO
S3
S2 ➔ s3 ➔ S2 ➔ so ➔ S3 ➔ S1➔S1 ➔ SO
S2



S2 S3➔S3 ➔ S2➔S2
SO SO➔SO
S3—+S1➔S1
SO-+ P1P2 Pl
Pl
P2 一
P2 一
P1P2 一



S1—+S2➔S2
Pl P2 P1P2 P1 P1P2 P1P2
P2 P1P2

SO ➔ S1 P2 P2 P1
S2
S3 S1➔S1
S1
S3➔S3 PlP2 P2
S2➔ SO➔ SO SOP➔1S3P1P2 一
SO
PlP2 PlP2 PlP2 P2 P2 Pl Pl Pl P2




S2
Pl Pl Pl P2 P2 PlP2 Pl



SO ➔ S3
S2 ➔ Pl P1P2
S1
PZ Pl P1P2
S3—+SO
SO
S3
S2➔S2
SO
S1
Pl PlP2
S1 S2➔S2
S1 S1
S0 ➔ SO➔SO
S2
S1 ➔ 一


S2
SO
S3—+ Sl➔Sl—+ S2 —+ Sl
S3 P1P2 P1P2
S1➔S1
Pl P1 P2
S3 ➔ Sl ➔ S2 ➔ S1
so
S1

5. Consider the functional block diagram shown in Figure 5.1. This corresponds to an arbitrary microcontroller whose architecture is based partially on that of the MSP432 microcontroller.
PSEL
GPIO PWM ADC UART
LSEL
TAIFG��
1x 2x 4x Bx
16x
32x
Figure 5.1
• The frequency of the DCOCLK is given by the product of the DCOBASE frequency (equal to 1.5 MHz) multiplied by a scaling factor specified by DCOSEL.
• The frequencies of the remaining clock module sources are given by: VLO = 10 kHz, LFXT = 32 kHz, HFXT = 1 MHz, SYSOSC = 5 MHz.
• The ID and IDEX pre-scalers, as well as the mode control (MC), are identical to those used for the 16-bit Timer A (TA) peripheral on the MSP432.
• PSEL is used to select one of the four peripherals as the active module, these including GPIO, PWM, ADC and UART functionalities.
• TAVAL is a random, natural number loaded into the 16-bit Timer A register (TAR) (see Note 5.1).
• A 20-bit timing control register is used by this microcontroller the value of which determines its
operation (see Note 5.2).
E I�:�I H E如 CLKSEL ID IDEX MC MlPH IM2PH PSEL B19 l��!1 B17 BlS I B13 IB12 IB11 B10 IB9 B8 IB7 IB6 BS IB4 B3 B2 B厂180
Given the above functional block diagram of this fictional microcontroller, as well as the bit order and values for the associated timing control register (as specified in Note 5.2), explain how each component of this peripheral would be setup. Subsequently, explain what signals we would expect

to see at each output pin and active module. Be sure to describe your approach and reasoning in detail.
Note 5.1: For the purpose of this task, you should use the following approach to compute your unique TAVAL number: Take the last (rightmost) four digits of your student number and multiply it by 6. This will serve as your TAVAL number for this task. For example, if your student number is “16004963”, then the TAVAL number you would have to use would be equal to TAVAL = (4963 * 6) = 29778.
Note 5.2: Convert your entire eight-digit student number (which by default is in decimal format) to its corresponding binary number. You can use any valid decimal to binary converter1 to complete this conversion. Once converted, take the last (rightmost) 20 digits of this generated binary number and use it as your value for the timing control register. For example, if your student number is “16004963”, then the corresponding binary number would be “111101000011011101100011”. Taking the last (rightmost) 20 bits would mean that our timing register would be loaded with “01000011011101100011”, that is to say:
Example:
DCOSEL LSEL I HSEL CLKSEL IDEX MC I MlPH I M2PH I PSEL
011101O10101111101 1 111110111110 o I 1 I 1 [10 marks]
1 See for example htt s: www.ra idtables.com convert number decimal-to-binar .html
ID

6. Consider a scenario in which a Texas Instruments microcontroller from the MSP family is used to capture a reading from an analogue sensor (see Note 6.1), print it to the serial terminal and blink an LED at two different rates depending on whether the reading is above or below a certain threshold. Describe in detail the sequence of events and how you would go about configuring the parameter values for each peripheral. Your answer should discuss the following operations within the context of a specific, real-world example:
a. Interface between specified sensor and ADC.
b. Sampling, quantisation and conversion process.
c. Setup of ADC control registers.
d. Setup of serial communication registers for a particular baud rate (see Note 6.2).
e. Setup of timer registers.
Note 6.1: Use the last (rightmost) digit of your student number to identify the analogue sensor that you must use based on Table 6.1. For example, if your student number is “16004963”, then the last digit is an odd number and hence you must use the analogue sensor corresponding to the odd row being AD22103.
Note 6.2: Use the last (rightmost) digit of your student number to identify the baud rate that you must use based on Table 6.2. For example, if your student number is “16004963”, then you must use the baud rate corresponding to row number 3 being “9600”.
Last digit of student number Odd
Even
Sensor AD22103
AD22100
Last digit of stu。dent number
1 2 3 4 5 6 7 8 9
Link
httQS壮uk.rs-online.comLwebL12Ltem12erature-humidi过 sensor-icsL7095645L httQs:{Luk.rs-online.comLwebLQLtemQerature-humidity一 sensor-icsL5230076L
Table 6.1
Specified baud rate
1200 2400 4800 9600 19200 38400 57600 115200 230400 460800
Table 6.2
[25 marks]