You are on page 1of 3

HW5

5. If PIC18F458 is rated as 40 MHz, what is the


maximum frequency that can be connected to it?
Ans: 40 MHz
8. The MCLR pin is normally (LOW, HIGH) and needs a
(LOW, HIGH) signal to be activated.
Ans: MCLR pin is normally HIGH and needs a LOW signal to be
activated.
17. MCLR is an (input, output) pin.
Ans: Input
22. Upon reset, all the bits of ports are configured as
(input, output).
Ans: Input
26. True or false. When the system is powered up, the
power-up timer (PWRT) and oscillator start-up timer
(OST) keep the PIC18 in the reset state until the
voltage and frequency are stable.
Ans: True

c) 1101100 = 108
108 x 5 mV = 0.540 V

1101100 = 108
108 x 1.3 mV = 0.135 V

18. True or false. A/D of the PIC18 is an 8-bit ADC.


Ans: False
22. True or false. Upon power-on reset, the A/D module
of the PIC18F452/458 is turned on and ready to go.
Ans: False
24. True or false. The A/D module of the PIC18F452/458
can convert only one channel at a time.
Ans: True
26. True or false. The A/D module of the PIC18F452/458
can use the Vdd for Vref+.
Ans: True
28. In the A/D of PIC18 what happens to the old data if
we start conversion again before we pick up the last
data?
Ans: It gets lost.

30. True or false. The CONFIG registers use the same


address space as program ROM.
Ans: False

30. In the PIC18, what should be the Vref value if we


want a step size of 2 mV?
Ans: 2 mV x 1024 = 2.048 V

34. Which CONFIG register is used to set the brown-out


reset voltage for the PIC18F458?
Ans: CONFIG2L

32. With a step size of 1 m V, what is the analog input


voltage if all outputs are 1s?
Ans: 1 mV x 1023 = 1.023 V

37. Show the CONFIG directive for a PIC18F458 system


with the following options:

HW7

(a) OSCI-0SC2 is connected to 20 MHz and it is the


only source of the clock for the system.
Ans: CONFIG OSC = HS
(b) The brown-out voltage is set for 4.2 V and the
power-up timer is enabled.
Ans: BORV = 42, PWRT = ON
(c) No watchdog timer
Ans: WDT = OFF
(d) No overflow on stack, no background debugger,
and no LVP
Ans: CONFIG DEBUG = OFF, LVP = OFF, STVR = OFF
42. True or false. The INHX32 option can be used for
ROM sizes of more than 64 kilobytes.
Ans: True
45. True or false. The INHX32 option can be used for
ROM of any size.
Ans: False
HW6
11. Which of the following ADC sizes provides the best
resolution?
(a) 8-bit (b) l0-bit (c) 12-bit (d) 16-bit (e) They are all the
same.
12. In Question 11, which provides the smallest step
size?
Ans: 16-bit
14. With Vref= 1.28 V, find the Vin for the following
outputs: (Assume an 8 bit A/D)
Ans:
a) Step size = 1.28/256 = 5 mV
Step size =
128/1024 = 1.25 mV
255 x 5 mV = 1.275 V
255 x 1.25 mV = 0.318 V
b) 10011001 = 153
153 x 5 mV = 0.765 V
V

10011001 = 153
153 x 1.25 mV = 0.19125

1. Which technique, interrupt or polling, avoids tying


down the microcontroller?
Ans: Interrupt
3. In the PICI8 what memory area is assigned to the
interrupt vector table?
Ans: 0x0008 and 0x0018
4. True or false. The PICI8 programmer cannot change
the memory address location assigned to the interrupt
vector table.
Ans: True
7. Do we have a memory address in the interrupt
vector table assigned to the Timer0 interrupt?
Ans: No, all interrupts got to the same location (high or low)
9. To which register does the GIE bit belong?
Ans: INTCON
11. What is the state of the GIE bit upon power-on
reset, and what does it mean?
Ans: GIE is set to 0 (zero) which means that the interrupts are
disabled on power up.
14. The TMR0IE bit belongs to register ________.
Ans: INTCON
15. How many bytes of address space in the interrupt
vector table are assigned to the high priority
interrupt?
Ans: 16 bytes
18. True or false. The INTCON register is not a bitaddressable register.
Ans: False
23. True or false. For each of Timer 0 and Timer 1,
there is a unique address in the interrupt vector table.
Ans: False
HW8
33. True or false. An address location is assigned to
each of the external hardware interrupts INTO, INTI,

and INT2.
Ans: False

Restores GIEH bit, re-enabling both high-and low-priority


interrupts.

34. What address in the interrupt vector table is


assigned to INT0, INT1 and INT2? How about the pin
numbers on PORTB?
Ans: 0x0008 high priority; 0x0018 low priority. Pins 33, 34,
and 35 = INT0-2 interrupt lines. INT0 is always a high priority
interrupt.

Each interrupt source, except INT0, has three bits to


control its operation.
1. Flag bit to indicate that an interrupt event has occurred
2. Enable bit that allows program execution to branch to the
interrupt vector address when the flag bit is set
3. Priority bit to select high priority or low priority
Resolution 1 / 2n * Range
Example Range = 10 volts, n = 10
Resolution = 10/1024 = 0.0098 volts or 9.8 millivolts
Range = 10 millimeters
Resolution = 0.0098 mm

37. Show how to enable all three external hardware


interrupts.
Ans: BSF INTCON, INT0IE
BSF INTCON3, INT1IE
BSF INTCON3, INT2IE
39. True or false. Upon reset, all the external hardware
interrupts are negative edge- triggered.
Ans: False
42. The INTIIF bit belongs to the register ____________.
Ans: INTCON3
43. True or false. The last two instructions of the ISR
for INTI are: BCF INTCON3, INT1IF RETFIE
Ans: True
47. True or false. INTO-INT2 are part of the PEIE group.
Ans: False
48. True or false. Upon power-on reset, all of INTO-INT2
are positive edge triggered.
Ans: True

Converting Offset Binary to Decimal Value


Determining a Sensors Output Value when A/D displays
results in offset binary.
Output Value (in decimal) = (R * A/D Reading)/2n R/2 where:
R = Range of A/D, n = A/D register size, A/D Reading = value
read, A/D time = acquisition time + conversion time
Example Given: Range = 5volts = 10v, n=10 bits
Reading = 1F2H = 498 decimal
Find:
Signal Output Value = 498*10/1024 5 = 1.367 volts
Questions from previous exams
1. If Iref for the 8 bit D/A converter discussed in the text is
2ma, what would be the current for a digital input of
00000001?
Ans: 1/256*2 = 0.0078

51. True or false. INTO-INT2 must be configured as an


input pin for a hardware interrupt to come in.
Ans: True

2. If the PICs A/D converter is used with Vref set to 2.0 volts,
what would be the step size?
Ans: 2/1024 = 0.001.953v or ~2mV.

52. Which register holds the INTEDGx bits?


Ans: INTCON2 register

3. If the PICs A/D converter with Vref set to 2.0 volts is used
to interface with a distance sensor that indicates a 200 mm
displacement for 2 volts and 0 volts for 0 mm displacement,
what what would be the step size in mm?
Ans: 200mm/1024 v = 0.1953mm

76. True or false. In PIC18 an interrupt inside an


interrupt is not allowed.
Ans: False
Chap 11: PIC18 Interrupt Process
Finishes instruction it is executing and save address of next
instruction (PC) in stack. In the case of a high priority
interrupt, the GIE is disabled. In the case of a low priority
interrupt only the low priority interrupt is disabled.
Jumps to 0008 or 0018
Gets address of ISR and, via GOTO, begin execution of ISR
Last instruction should be REFIE (return from interrupt exit).
Pops the address of the next instruction which was interrupted
from the stack and begins execution at that address. It also
enables the GIE (high priority, GIEH), or GIEL

4. Find the current needed to energize a relay if the coil


resistance is 1,200 ohms and the coil voltage is 5 V
Ans: I = E/R = 5/1200 = 4.167 mA
5. The Watchdog timer option in the Configuration Register is
useful for resetting the processor when the voltage drops
below a selectable minimum Vref voltage for the PIC18.
Ans: False.
6. In the LAB 4 - PIC18F452 wiring, you used the low power
option.
Ans: False.

Chap 11: Interrupts - PIC18


Multiple Interrupt Sources 17 Separate Interrupt Sources
Power-on Reset - location 0000
Two interrupt priorities high, low
Two Interrupt vectors
0x0008: High Priority- location 0008
0x00x18: Low Priority - location --0018

Open-Collector
Open-Collector devices are commonly used to connect
multiple devices to a bus (i.e., one carrying interrupt or writeenable signals). This enables one device to drive the bus
without interference from the other inactive devices if openCollector devices are not used, then the outputs of the
inactive devices would attempt to hold the bus voltage high,
resulting in unpredictable output.

Chap 11: Interrupt Processing


Low Priority
The CPU completes the execution of current instruction
The low-priority interrupt enable bit (GIEL) is cleared.
The contents of the program counter is stacked
The program counter is loaded with 0x0018

When a device is in the high-impedance state, the pullup


resistor keeps the line at logic 1. The line stays there until the
device goes into the logic 0 state, and begins to sink current.
This current flow creates a voltage drop across the pull-up
resistor, and the line drops to the logic 0 voltage.

High Priority
Same actions as low priority
Plus, saves STATUS, WREG, and BSR into the PIC (not the
stack only one level).
RETFI - FAST:
Restores PC, and STATUS, WREG, BSR (The low priority will
not include these)

Open Drain
An open drain terminal is connected to ground in the low
voltage (logic 0) state, but has high impedance in the logic 1
state. This prohibits current flow, but as a result, such a
device requires an external pull-up resistor which is also
connected to the positive voltage

Switch Types
SPST Single Pole Single Throw
SPDT Single Pole Double Throw
DPDT Double Pole Double Throw
Relays
A relay is an electrically operated switch that are used where
it is necessary to control a circuit by a low-power signal (with
complete electrical isolation between control and controlled
circuits), or where several circuits must be controlled by one
signal.
Mechanical relays consists of an armature, spring, and a set of
electrical contacts. Instead of a person closing a mechanical
switch as in the previous slide, an electromagnet (the
magnetic field is produced by the flow of electric current) is
energized causing the armature to close the contact of two or
more electrical contacts as illustrated in the following side.
Note: An opto-isolator or optical isolator, is a component that
transfers electrical signals between two isolated circuits by
using light.
Practice Assignment
1. Given: A/D Converter, +- 5 Volts, 12 bit, offset binary data
format: For the following offset binary readings (hex) compute

the corresponding decimal voltage readings corresponding


decimal voltage readings.
a. 7F6 = 2038*10/2^12-5 = 4.976-5 = -0.02441 volts
(2.) a. Neg# FF6 (toggle Sign Bit) = 1111 1111 0110 = 2
0110 = 2 s complement - 000 0000 1001 +1 = 00A or
10*10/4096 = -0.02441
b. 35F = 863 *10/4096 -5 = -2.893.
(2.) b. Neg# 1011 0101 1111 = 2s complement - 0100 1010
0000 +1 = 0100 1010 0000 +1 = - 4A1 = -11850/4096 = 2.893
c. 800 = 2048*10/4096 - 5 = - 0
(2.) c. 800 = 0000 0000 0000 (Toggle sign) -> positive # =
000 0000 0000 =0
d. FF0 = 4080 *10/4096 - 5 = 4.961
(2.) d. 7F0= 0111 1111 0000 = pos# 7F0 = 2032*10/4096 =
4.961
3. Repeat problems 1 and 2 for an eight bit converter, but
with the hex digits: F6 = 246*10/256 -5 = 4.609
a. 2. 76 pos# =118*10/256 = 4.609
b. 5F = 95*10/256-5 = -1.289
2 DF 1101 1111 2s com p = 0010 0000+1 0010 0001 =
330/256 = - 1.289

You might also like