Answers to Questions

Answers to Questions

Answers to Questions Answers 1 1. 2. 3. 4. 5. 6. 7. 8 9. 10. 11. 12. Processor, memory and I/O A microcontroller has processor, memory and I/O o...

119KB Sizes 0 Downloads 96 Views

Answers to Questions Answers 1 1. 2.

3.

4. 5.

6. 7. 8

9. 10. 11.

12.

Processor, memory and I/O A microcontroller has processor, memory and I/O on one chip, while the microprocessor needs separate memory and I/O chips to form a working system. Output address from program counter on the address bus, select memory location containing instruction code and copy it back to the instruction register via the data bus. Flash ROM can be electrically re-written many times but is non-volatile. The data has to be converted to serial form in a shift register and transmitted one bit at a time on a single line, while parallel data is transferred 8 (or more) bits at a time. Ports A and E default to analogue input on power up or reset. The Special Function Register is dedicated to a specific function, while the General Purpose Register can store any user data. From data sheet Table 13.2: Instruction code 5 00 0000 1000 1100 Op-code 5 0000001 Register operand 5 000 1100 The port data direction registers are only accessible in bank 1, so the bank select bit RP0 must be set. The hardware timer runs simultaneously with the program execution, so the MCU can proceed with the program while the delay count is made. The first column contains the address of the memory location where the instruction will be stored, usually starting at zero. The second is the hexadecimal machine code that will be downloaded to the chip. The third is the line number in the source code text file. The fourth is the source code mnemonic (instruction and operand). The last may be used for comments. Plug the programmer unit into the host PC (USB) and the target board (6-pin connector). Write the program in MPLAB and assemble it. Select the software simulator and debug the program. Select the programmer and connect to the target. Download the program and run in the hardware (set MCLR). Total

361

(3) (3)

(3)

(3) (3)

(3) (3)

(3) (3) (3) (5)

(5)

(40)

362 Answers to Questions Answers 2 1. (a) Load the working register with the number 0FFh (sets all bits) (b) Jump to a subroutine starting with the label ‘delay’ and return afterwards

(2) (2)

(a) CODE: indicates start of program code (b) EQU: declares a constant label (c) #INCLUDE: insert source code text file GOTO, SLEEP; program will run through blank locations and repeat Address, register Power-up timer enable, watchdog timer enable, clock oscillator type select A bit test is used to determine whether the next instruction is skipped or not (BTFSS, BTFSC). This is usually followed by a GOTO or CALL to change the program sequence. If this instruction is skipped, program execution continues on the original path. Often the zero flag is tested to control a branch. The zero flag test is combined with a decrement or increment in DECFSZ and INCFSZ to provide counting loops and similar sequences. Program jumps to subroutine code, executes and returns; macro code is inserted each time by the assembler. A subroutine the program uses less memory, but a macro using the same code is faster. Start/end, process/sequence, input/output, branch/selection, subroutine/ function. A subroutine is a programmed jump (CALL) and return; the return address is stored automatically on the stack, so that when the routine has been completed, a RETURN instruction causes the return address to be replaced in the program counter, taking the execution point back to the instruction following the call. The interrupt is an asynchronous external event which forces a jump to program address 004, from where an interrupt service routine is executed. This is terminated with RETFIE, return form interrupt, to take the execution point back to the original position. The stack is used in the same way as in the subroutine to store the return address. C can be used for any type of MCU and is easier to understand and more powerful than assembler. Total

(2) (2) (2) (3) (2) (3) (5)

2.

3. 4. 5. 6.

7.

8. 9.

10.

(4)

(5) (5)

(3) (40)

Answers 3 1. 2. 3. 4.

They are the standard mathematical models for electronic components. The clock settings for simulation are set in the MCU component properties dialogue. It is the reset input which must be high to allow the chip to run. It is also the programming voltage input, so must be isolated from the target supply. 10 3 1029 3 25 3 103 5 250 μs 2 4 kHz clock 21 kHz output

(3) (3) (3) (3)

Answers to Questions 363 5. 6. 7. 8. 9. 10.

MPLAB simulates only the MCU and produces only numerical results. VSM simulates the whole circuit and displays an animated schematic. Step into steps into subroutines and step over runs through them at full speed. The breakpoint stops the program at a particular line so the MCU status can be checked or a timing measurement made. The oscilloscope displays a limited number (4) of analogue signals of any amplitude. The logic analyser displays numerous digital (logic) only. The netlist specifies all the components in a circuit and their connections. It is passed to the PCB layout system to create a circuit board. In-circuit debugging allows the program to be tested in the real hardware to complete the final fault finding stage. Total

(3) (3) (3) (3) (3) (3) (30)

Answers 4 1. 2. 3. 4.

5. 6. 7.

8.

9. 10.

If the switch is connected between the input and 0 V, the pull-up resistor, ensures that the input is high when the switch is open. Capacitor, software delay, timer delay. Hardware timers allow timing operations to proceed simultaneously with other program processes, giving a more efficient use of the processor. The timer pre-scaler is a digital frequency divider which reduces the frequency of the input clock by a factor of 2, 4, 8, etc., which increases the timer range by the same factor. The segments must be illuminated in the correct combination to display digits 0 to 9. The data table provides the required binary output code for each digit. The BCD display has an internal hardware decoder so that it displays the digit corresponding to the input binary code (0 9). The rows are connected to MCU outputs and set high. The columns are connected to inputs and pulled high. Each output is taken low in turn. If a key is pressed, a low input is detected on that column, identifying the key. The LCD can operate with 4-bit input, receiving 8-bit control and data codes in 2 nibbles. An enable input strobes the data in, and a register select input indicates if the input code is a command or display data. ASCII is a standard seven bit code representing characters found on a keyboard. They are used in serial communication of text data. Keypad

(3) (3) (3) (3)

(3) (3) (3)

(3)

(2) (4)

Rows Columns

PIC LCD

Data RS E

Total

(30)

364 Answers to Questions Answers 5 1. 2. 3. 4. 5.

6.

7.

8.

10010011 5 5 128 1 16 1 2 1 1 5 147d 123410 5 5 10011010010 (using division by 2 and remainders) 3FB016 5 5 0011 1111 1011 0000 5 5 1630410 (using binary weighting) 1001 3 0101 (59 3 5) 5 0101 1 0101000 5 101101 5 1 1 4 1 8 1 32 5 45 9942 5 49r1, 4942 5 24r1, 2442 5 12r0, 1242 5 6r0, 642 5 3r0, 342 5 1r1, 142 5 0r1 99 5 5 01100011 5 5 64 1 32 1 2 1 1. For 299, sub 1: 01100011-1 5 01100010 and complement: 10011101 Answer 299 5 5 9D16 16-bit FP number 5 0 00100 1001000000 MSB 5 0 5 1ve number Exponent 5 01100 5 12; Offset 15: 12 2 15 5 23; Exponent multiplier 5 223 5 0.125 Significant fraction 5 0.5 1 0.0625 5 0.5625; Significand 5 1.5625 Result 5 1.5625 3 0.125 5 0.195 5610 BCD 5 5 (5 3 10) 1 6 5 5 (0101 3 1010) 1 0110 5 101000 1 1010 1 0110 5 111000 Check: 0110011 5 32 1 16 1 8 5 5610 41 h, 7Ah, 23 h Total

(3) (3) (3) (3)

(6)

(6)

(3) (3) (30)

Answers 6 1. 2. 3. 4.

5. 6. 7. 8. 9. 10.

12-bit ADC gives 212 5 4096 steps. 100/4096 5 0.024% per step The full-scale input is divided into 28 5 256 steps for conversion to binary. With a 2.56 V reference, this converts into exactly 2.56 V/256 5 10 mV per step Three bits are used to select 1 of 8 input channels AN0 AN7. If the 10-bit result is left justified, the high 8 bits of the ADC result are placed in the ADRESH register, with the low 2 in the high bits of ADRESL. If right justified, the low 8 bits are placed in ADRESL, and the high bits in the low 2 bits of ADRESH. Gain and input resistance are infinite, output resistance is zero. A common single supply (5 V) can be used for MCU and interface. It restricts output swing and may not reach zero. G 5 19/1 1 1 5 20 (a) Vs 5 2 (1.0 1 0.5) 5 3.0 V (b) Vd 5 2 (1.0 2 0.5) 5 1.0 V The capacitor slows down the output transient response and reduces the cut off frequency. Current in offset resistor 5 (1.0 2 0.5)/10 k 5 0.05 mA Voltage across feedback resistor 5 0.05 mA 3 22 k 5 1.1 V Output voltage 5 1.0 1 1.1 5 2.1 V

(3) (3) (3) (3)

(3) (3) (3) (3) (3)

(5)

Answers to Questions 365 11.

12.

Gain 5 22/10 5 2.2 GBWP 5 2.2 3 BW 5 1 MHz BW 5 45 kHz When output 5 0 V, VL 5 15/25 3 5 5 3 V, VH 5 25/35 3 5 5 25/7 5 3.57 V Total

(3) (5) (40)

Answers 7 1. 2.

3. 4.

5.

6.

7.

8. 9. 10. 11. 12.

Two of: simple design, high off resistance, good isolation. One of: slow, high power consumption, bulky. Base current 5 4.6 2 0.6/1000 5 4 mA Collector current 5 4 3 50 5 200 mA Volt drop 5 0.2 3 10 5 2 V It is a voltage controlled current source, with high input impedance. Zero and 15 V applied at the gate will switch it off and on. The DC motor needs a commutator to reverse the armature current on each half revolution, so that the torque is developed in one direction only. Discharge and wear cause unreliability. The thyristor is equivalent to a latching pair of transistors, which passes direct current when the gate is pulsed. The triac is formed of back to back thyristors and switches alternating current. The software option can be implemented by the MCU toggling an output with a delay. Alternatively, a separate hardware oscillator based on the 555 timer chip can be switched on an off by the MCU. Pulse Width Modulation uses a pulse waveform to control a current switch connected to the load. If the ON time (duty cycle) increases as a percentage of the overall period, the average current in the load, and hence the power dissipated increases. See Figure 7.12(c). The switches in the bridge (FETs) are turned on in pairs to allow the current to flow in either direction in the motor. 360/15 5 24 steps/rev. Speed 5 96 steps/sec-96/24 5 4 revs/s It can be made physically small with a high power to weight ratio and reliability due to the absence of commutator and brushes. 200 slots/100 ms-2000 slots/s-2000/50 5 40 revs/s-40 3 60 5 2400 rpm. The DC motor drive is simpler in construction, more efficient, and higher speeds and torque are possible, but it needs a feedback system for position control and a gearbox for low speeds. The stepper can positioned without feedback and holds its position but is less inefficient and is complex to drive. Total

(2) (1)

(4) (3) (3)

(3)

(3)

(3)

(3)

(3) (3) (4) (5)

(40)

366 Answers to Questions Answers 8 (3 Marks Each) 1. 2. 3.

4. 5.

6.

7.

8.

9.

10.

No clock is sent with the data signal. To increase the signal to noise ratio, and the distance sent, by increasing the signal amplitude. Line attenuation and noise limits the distance in proportion to the sending amplitude. SPI signals are sent at TTL levels (5 V) only, while RS232 uses amplitude up to 50 V p-p. ASCII (9) 5 39 h 5 0111001 Parity bit 5 0 (MSB last) Sequence LSB first 5 10011100 Slave select is a hardware input to an SPI device which enables slave transmission, generated by the master controller. I2C uses software addressing, where the required device and location are selected by an address sent on the serial data line. In I2C, a control code and address must be sent before the data, making up to 5 bytes in all, plus control bits. In SPI, only data bits are sent as the slave device is selected in hardware (slave select). Also, SPI can run at 5 MHz clock, I2C only 1 MHz CAN was developed first, with special control units and was more expensive. LIN was designed to do the same job more cheaply, using the USART port on any MCU with a line transceiver. Data 5 10110010 0 xor 0 5 0, 0 xor 1 5 1, 1 xor 1 5 0 Result 5 01 10 01 01 10 10 01 10 The differential signal gives reversible current in a pair of wires that can be more reliably detected at the receiver than a single ended voltage. The twisted pair ensure any interference on the line cancels out. Collisions occur unpredictably in ethernet CSMA operation, so signals transmission time is unreliable. Industrial networks use alternative methods such as token passing which give predictable response times. Total

(30)

Answers 9 1. 2. 3. 4. 5.

6.

More reliable, faster, remote sensing An opto-sensor counts the steps on the strip to position the print head. The rate of change of the output divided by the rate of change of the input, corresponding to the gradient of the characteristic. Accuracy is the extent to which a measurement is consistent with the agreed standard, precision is the smallest output change measureable. Any 3 of: temperature sensing resistor (metal film/wire), semiconductor junction (p-type and n-type silicon), thermocouple (dissimilar metals), thermistor (solid semiconductor), resistance (platinum wire). 4.

Answers to Questions 367 7. 8.

9.

10.

100 kΩ Strain gauges are connected as a bridge circuit to provide a differential output that eliminates the large offset voltage when used with a single supply, to maximise the output amplitude and to provide inherent temperature compensation The instrumentation amplifier is a differential configuration, which eliminates offset in the source voltage, has a high input impedance suitable for the high source impedance of the strain gauge bridge and has a high gain suited to the low sensitivity of the strain gauge bridge. 2.35 V 5 10 cm, 0.41 V 5 80 cm Sensitivity 5 (2.35 2 0.41)/(10 2 80) 5 227.7 mV/cm Voltage change from max 5 2.35 2 1.50 5 0.85 V Distance change 5 850/27.7 5 30.69 cm Distance 5 10 1 30.7 5 40.7 cm

Answers 10 1. 2. 3. 4. 5. 6. 7. 8. 9.

Five of: number of I/O pins, program memory size, peripherals available, data memory, instruction set, developer expertise, cost. Accurate stable voltage, sufficient current, low noise and ripple. XLP 5 Extra Low Power (MCU) Minimises power consumption in battery powered applications. Parallel block arrow, serial single arrow Analogue single arrow with labelling and representation of waveform Three of: high frequency crosstalk, high power dissipation, unreliable transmission down long connections, limited component speed. Connect to the same I2C bus as the memory and assign the sensor address 1 via its hardware address pins. LM35 output changes by 10 mV/ C Output 5 1.000 1 (25 3 0.01) 5 1.25 V LM35 is linear and has a calibrated output of 10 mV/ C. LDR is non-linear, covering a wide range of light levels and resistance values. L 5 104/3(52logR) 5 104/3(523.3) 5 184 Ω