Uploaded by jacksonmtonga70

Lecture 3

advertisement
28/01/2021
Lecture 3: More on embedded hardware
• Thus far we have looked at various memory devices however we shall
tackle more on memory as we start to put things into practice. Aspects on
the various RAM devices, bootstrapping and linked lists will be looked at
when we tackled applications of C programming.
• Before we continue looking at other subsystems of a microcontroller, there
is need to understand what controls the speed at which tasks are executed.
The speed of operation is controlled by an external time base which may
be provided by an external quartz crystal, a programmable oscillator, a
ceramic resonator or an internal time base.
• µC can operate up to 50MHz depending on the required speed of
operation. For example to control a 24 h clock time whose mechanical
speed is slower compared to that of µC, a 32.768 KHz time base is used.
MC 401 - CBU SE
19
19
The Timing Subsystem
The main clock is sent throughout the µC to provide synchronisation of the
subsystems. To this effect most µC are equipped with a timing subsystem. The
following parameters which most of you have already come across affect signal
timing and are critical for certain µC operations such as motor control:
• Frequency: Signal frequency is the number of cycles per second completed by a
repetitive signal. It is expressed in units of Hertz (Hz).
• Period: The period is the time increment in seconds required for a repetitive
signal to complete a single cycle. The period is the reciprocal of the frequency (T
= 1/ f ).
• Duty cycle: The duty cycle indicates the percentage of time for which the signal
is active in a single period.
• Pulse width modulation (PWM):PWM signals are frequently used to control
motor speed. The digital PWM signal is converted to an effective DC value by
the mechanical inertia of the motor as well as the low pass filter characteristics
of the inductance inherently present in a motor. Note in Figure 3.1 how various
effective DC voltages can be delivered to a load by simply adjusting the duty
cycle of the digital PWM signal.
MC 401 - CBU SE
20
20
1
28/01/2021
Timing Concepts
To take full control of the time base operations
in the microcontroller, most of the devices are
equipped with a multichannel timing system.
These channels in the system may be configured
to do the following:
• Measure parameters of the input signal such
as the period and the duty cycle.
• Generate precision output pulses or
repetitive signals
• Count incoming pulses present in the input
signal
• Generate PWM signals
These abilities can be harnessed during practical
applications as we shall see later in the course.
Figure 3.1: Timing Concepts
MC 401 - CBU SE
21
21
Port Systems
• Recall from the µC structure in our second lecture that there is a range of
ports available to connect the device to the outside world.
• The ports are usually arranged as an eight bit input/output port system.
• A data direction register can be used to set the direction of a given port ie.
Input or output.
• These ports are used for the input and output of digital signals, they can be
equipped with functions such as analogue-to-digital conversion (ADC), serial
communication and network interfacing. We shall discuss these feature briefly
in this lecture but dwell on them as the course progresses.
• What happens when the design requires more ports than what the
microcontroller has? The ports have a time multiplexed capability which
allows the function of each port to alternate at a given interval of time.
MC 401 - CBU SE
22
22
2
28/01/2021
ADC and Communication for interfacing
Brief introduction to ADC
• ADC subsystems present in the µC enable the conversion of time varying
analogue signals such as temperature, vibration, humidity from the
outside world to binary 1s and 0s suitable for use by the µC.
• The continuous signal is expressed as a series of digital snapshots with
thresholds determining if a value should be a binary 1 or 0.
• Depending on the design, the programmer can determine how often ADC
operations are required. A temperature reading that has to be stored in
memory may require ADC every time the thermometer gives a reading.
MC 401 - CBU SE
23
23
Communication systems
The two most common types of communication systems for µCs are :
• Serial
• RS 232
USB communication is also fast becoming popular for most applications.
To send and receive data over data over long distances serial communication is used for
microcontrollers.
To best understand µC serial communications the following common terms should be
known:
• Simplex mode: In this mode, the serial communication is accomplished by transmitting
data in one direction at a time.
• Duplex mode: In this serial communication mode, data can be transmitted and
received
from both ends of the communication link at the same time.
• BAUD rate: The rate of bits sent or received. It describes the number of bits
communicated per second.
MC 401 - CBU SE
24
24
3
28/01/2021
Com systems cont.
• ASCII code: The American Standard Code for Information Interchange
code is used in communication to encode alphabets, numbers,
punctuation, and control characters using a seven-bit representation.
ASCII is a subset of the international Unicode standard.
• Bit time: The time required to transmit or receive a single bit.
• Serial line code: A specific encoding mechanism used to transmit and
receive information.
Note: It is important that both the transmitter and receiver use a
common line code, BAUD rate, and parity setting for proper
communications.
MC 401 - CBU SE
25
25
The RS-232 Protocol
Many peripheral devices are equipped to communicate with an RS-232 compatible interface. The “RS-232” is
an Electronic Industry Association (EIA) standard formally designated EIA-232-D. This standard specifies the
different aspects of a serial communication interface including:
• electrical specifications,
• functional signal specification,
• mechanical specification, and
• procedural specifications.
A variety of chips are available to translate microcontroller compatible signals to RS-232 compatible signals.
The RS-232 standard represents a logic high with a −10 VDC level and a logic low with a +10 VDC level. These
chips are equipped to provide interfacing for a two way (transmit and receive) communication system. That is,
the output serial bit stream from a microcontroller to a RS-232 compatible peripheral device must be
converted to a RS-232
signal. The serial bit stream returning from the peripheral device must be converted from the RS-232 format
back to microcontroller compatible signal levels.
MC 401 - CBU SE
26
26
4
28/01/2021
The interrupt system!
Figure 3.2 shows the normal sequence of a
program which is fetch, decode and execute.
However, sometimes there exists a high
priority event that needs to interrupt this
normal sequence. When such a high priority
or status occurs, the
µC temporarily
suspends normal operation to execute event
specific actions. A fault can be an example of
a high priority event.
Figure 3.2: The concept of interrupts
This action of servicing an event is referred to as an interrupt service routine. It is important
that this interruption is orderly and allows smooth continuation of normal operation after the
interrupt service. To do this a µC uses what is known as a stack. A stack is a temporary storage
location set aside as a part of RAM.
MC 401 - CBU SE
27
27
Interrupts cont.
When an interrupt occurs the microcontroller will finish executing the current
instruction. It will then place context information, key register values and the
return address to the normal program, on the stack. The interrupt service
routine (ISR) will then be executed. The ISR consists of the microcontroller
activity required by the interrupt. When the ISR is finished, control will return to
the program that was executing when the interrupt occurred. The context
information previously stored on the stack will be used to restore the controller
to its pre-interrupt configuration.
Interrupts are usually generated by hardware and software malfunctions. The
two most common interrupts available to a designer are:
• Real time interrupt (RTI)
• External Interrupt Request (IRQ)
MC 401 - CBU SE
28
28
5
28/01/2021
Interrupts cont.
• The RTI is common and usually performs checks on critical system status
issues like the battery level. This interrupt can also be used to update the real
time clock.
• On the other hand, the IRQ has an external hardware pin which can be
activated by putting say a jumper across it. Once activated the ISR is
generated and executed.
• This allows an external system to alert the µC that an external fault has
occurred. An example of this is in a motorised gate operation. If something
external is blocking the gate from opening like a rock, an IRQ can be issued to
alert the µC of this condition. Otherwise the µC will continue issuing an
instruction to open the gate and cause the motor to get damaged.
End of Lecture 3!
MC 401 - CBU SE
29
29
6
Download