Useful Tools

contact us contact tutor/group email to a friend accessibility options report a fault
Microcontrollers

Microcontrollers

Unit 2 -  Peripheral Modules in a Typical  Microcontroller


Unit Information


2.1 Introduction

Most microcontrollers contain a number of hardware modules.  In the past many of these were designed as separate chips in a conventional microprocessor system.  Integrating them into a single microcontroller chip allows for greater functionality in a single chip and saves space.

Typical devices are:

Figure 1 shows a single chip microcontroller and CPU. The CPU is the processing module of the microcontroller.

Fig 1 A Single Chip Microcontroller

A Single Chip Microcontroller

The diagram above illustrates these modules within a typical microcontroller which also contains ROM and RAM memory and ports to access and control the outside world.


2.2 Timer modules

A common requirement of microcontrollers is the ability to be able to turn on an output (such as an LED or relay) for a period of time. This can be done by turning on the device, then causing the microcontroller to decrement a specified number to zero (a process that takes the microcontroller a specified amount of time to do), then turning the device off again. The on time and off time can be varied dynamically by reprogramming the timer during program execution. Figure 2 illustrates this principle.

Fig 2 Timer Output Example

Timer Output Example

This method of turning a device on for a specified period of time is wasteful in the sense that the microcontroller could be doing other things whilst it is waiting for the device on time to elapse.  A hardware timer could be used instead and would perhaps allow the microcontroller to do other things during the on time period. Most microcontrollers have at least one timer module, usually with a number of inputs and outputs.

The inputs allow the timer to be used to measure the time of an input signal applied to the timer input. The microcontroller counts the number of pulses over a unit of time to determine the speed of rotation, as illustrated in figure 3.

Fig 3 Timer Input Example

Timer Input Example

In this example the rotating shaft produces a single pulse every revolution. The microcontroller measures the time taken for a complete revolution and so determines the angular velocity of the shaft.

Figure 4, below, illustrates how a timer output could be used to produce an output pulse train, possibly to drive some external logic.  The timer is set up so that an on time and off time can be generated by the timer unit.

Fig 4 Timer Output Example

Timer Output Example

[back to top]


2.2.1 Internal Timer Functions:

Figure 5 shows the timer in relation to the CPU and other components of a microcontroller.

Fig 5 Internal Timer Functions

 Internal Timer Functions

 

The timer unit can also be used for generating a delay.  The timer is programmed with a specified count value which will be counted down (decremented) to zero. When the timer unit reaches zero a flag is set.  This flag can be monitored by software so that the microcontroller will know when the timer unit has reached zero.  Since the time taken by the timer unit to decrement from the specified count value to zero is simply the count value multiplied by the time between decrement operations, a known delay period is produced.  The time between decrement operations is a function of the crystal clock oscillator frequency so it can be defined very accurately.  The microcontroller can be doing other things between monitoring the flag bit so this is less wasteful in processor time than the simple software delay. (We will look at these aspects in more detail later on in the course).

In figure 6, below, we see an LED prior to being turned on via the port bit PB0.  Just prior to turning on the LED, the timer unit is loaded with a count value (the actual value being dictated by the delay time required). In due course the timer unit count value will reach zero, at which point a flag bit will be set. The CPU, on seeing the flag bit set, will turn the LED off. The time taken for the timer unit to decrement the count value to zero will be the time that the LED is on.

Fig 6 Using Timer to Create a Delay

Using Timer to Create a Delay

Another way of using the timer to create a delay is to cause the timer unit to interrupt the CPU when the timer reaches zero.  This can be more efficient in processor time since the microcontroller can be doing other things uninterrupted until the timer reaches zero. The concept of interrupts will be expanded upon later in the course.

[back to top]


2.3 The Serial Port

A serial interface is a convenient way to connect to other systems. Figure 7 shows a serial port in relation to components of a microcontroller.

Fig 7 Microcontroller Serial I/O

Microcontroller Serial I/O

Some microcontrollers have a serial port to allow data to be transmitted to another microcontroller, PC or remote system via a two wire pair.  This can be a very convenient way of transmitting data between two devices.  A disadvantage can be the slower speed of data transfer that a serial port has over a byte wide parallel data port.  The transfer rate can be programmed from within a range of typically 300baud (300 bits per second) to 57600baud.

The serial port is usually referred to as a Serial Communications Interface (SCI).  Most SCI units contained in microcontroller chips are a sub-set of the more traditional Universal Asynchronous Receiver/Transmitter (UART) unit that is available in the standard PC.  The UART has additional signals that allow it to be connected to a modem. This should be borne in mind when considering microcomputer applications that require the use of a modem. Most SCI units can work in asynchronous mode, whilst some also support synchronous working.

In figure 8, below, we see a microcontroller with a SCI unit connected to another system (which could be a PC or another microcontroller) via the transmit and receive pair.  It should be pointed out that the logic levels from a SCI port are TTL.  Therefore, if the microcontroller is to be connected to a PC, a TTL to RS232 interface chip is required to convert the signal levels from TTL to RS232 levels.  A corresponding RS232 to TTL interface chip is included in the PC to perform the necessary signal level translation back to TTL levels for the UART chip used in the PC (a 16050 UART).  This has not been shown in the above diagram.

Fig 8 The Serial Port

The Serial Port

In some applications, a special purpose interface might be designed with its own serial interface.

In figure 9, below, diagram we see a remote display system controlled by a microcontroller via its SCI unit.  This arrangement offers a simple interface between the two units and could be the basis for a number of remote "repeater" displays (by re-transmitting the data from one LCD sub-system to another). The other system could be an LCD display with driver hardware and serial to parallel translation.

Fig 9 Serial Port to LCD Display

 Serial Port to LCD Display

[back to top]


2.4 Analogue to Digital Conversion

In the real world signals are often analogue in nature.  For example, we might need to monitor (log) analogue signals from a strain gauge, or from a transducer converting temperature to an electrical analogue signal (temperature transducer).
Since microcontrollers are sometimes required for these types of applications, some are fitted with an Analogue to Digital Converter (ADC).

In most cases, the ADC is of the Successive Approximation type and there are a number of analogue channels (between 4 and 8 is most common).

The analogue channel inputs are usually shared with one or more of the digital I/O ports. That is to say they are multiplexed with the digital ports and the decision to select whether the chip pins are to be used for analogue channel inputs or digital ports is made in software (during the initial configuration of the program on reset).  More on this later.

Figure 10 shows the ADC in relation to the other components of a microcontroller.

Fig 10 Analogue to Digital Converter

Analogue to Digital Converter

It is now common for an ADC to derive 10 or 12 bits. For more demanding applications the ADC performance would need careful examination.

For example:

Higher clocking speeds means less time to do things.

In general, most 8 bit microcontrollers have limited performance due to the limited ADC resolution and CPU performance.
They are restricted to simple data logging and measurement applications not requiring high precision. Most 8 bit microcontrollers are unable to perform complex calculations owing to their limited instruction set and speed.  For more intensive applications involving complex algorithms, a DSP is a better choice.

A simple typical application is illustrated below in figure 11.

Fig 11 The ADC

The ADC

In figure 11 we see a microcontroller being used to measure an analogue signal level and determine hi/low limits. The microcontroller includes an ADC module and one of its digital input ports has been configured (by software) to be an analogue input channel. The software running on the microcontroller will perform an Analogue to Digital conversion of the input signal, then determine whether the input signal is above or below some pre-defined limit.  It will then turn on the appropriate LED.

[back to top]



We have now covered some of the basic units found in a microcontroller.  Note that not all microcontrollers will contain all of these units.

Most manufacturers of microcontroller chips produce a range or family of microcontroller devices.  The family will range from simpler (and hence cheaper) microcontrollers with perhaps only I/O ports, and a Timer unit, through to high end devices containing all of the units discussed so far and more.

[back to top]


 

  2.5 Special Function Units

Some microcontrollers will contain other "special function" units such as

[back to top]


2.5.1 Serial Peripheral Port

A Serial Peripheral Port (SPP) is a special interface that can be used to connect the microcontroller to a particular peripheral device such as Serial EEPROMs, shift registers, display drivers (LDC etc) or a serial Analogue to Digital converter etc.  This saves on valuable I/O pins and leads to a neat interface between the microcontroller and the peripheral device.

The same interface can be used to connect two microcontrollers together so that they can pass data between each other.  This can allow a number of microcontrollers in a system to share data or allow one microcontroller (the master) to control a number of other microcontrollers (the slaves).

Some of the PIC microcontrollers have such a device called the Synchronous Serial Port (SSP) and this SSP module can operate in one of two modes:
Serial Peripheral Interface (SPI) or Inter-Integrated Circuit (I2C)

The Freescale SPI Module on 68HC(9)08 MCU (application note AN2878) microcontroller uses a device called the Serial Peripheral Interface (SPI) in a similar manner.

[back to top]


2.5.2 CAN Interface Module

Controller Area Network (CAN) interface is a rugged differential serial bus standard, introduced by Bosch in 1986 for connecting automotive electronic control units (ECUs) which is now used in numerous applications including factory automation, building automation, aircraft and aerospace as well as in cars, trucks and buses. CAN bus replaced bulky wiring harnesses with a two-wire differential cable. CAN was specifically designed to be robust in electromagnetically noisy environments and can utilize a differential balanced line like RS-485. It can be even more robust against noise if twisted pair wire is used. Nowadays it is used in many embedded control applications (e.g., industrial) that may be subject to noise. The messages it sends are small (8 data bytes max) and they are protected by a Cyclical Redundancy Checking (CRC) that guarantees a Hamming bit length of 6 (so up to 5 bits in a row corrupted will be detected by any node on the bus).

CAN provides low-speed, fault-tolerant transmission bit rates; up to 1 Mbit/s being possible at network lengths below 40 m. Decreasing the bit rate allows longer network distances (e.g. 500m at 125 kbit/s or up to 1km with 50Kbit/s ).

Serial data (following a pre-defined protocol) is transmitted around a number of sub-system (CAN interfacing) units.  The CAN interface is used to control such things as the operation of the vehicle lights, monitor the engine parameters, even control the braking system, using a distributed CAN bus (twin wire pair).  The heavy wiring can therefore be kept short and only a power distribution system is required to get power to the individual unit being controlled.  Each device to be controlled and each device sending data to another part of the automobile contains a CAN interface device.  Each CAN interface is called a node.

Data messages transmitted from any node on a CAN bus do not contain addresses of either the transmitting node or of any intended receiving node.  Instead, an identifier that is unique throughout the network labels the content of the message (eg. revolutions per minute, headlights on, etc).  All other nodes on the network receive the message and each performs an acceptance test on the identifier to determine if the message (and hence its content) is relevant to that particular node.

Some of the more prominent names manufacturing microcontroller chips have introduced CAN units into their range of microcontrollers.

For example,

[back to top]


2.5.3. Ethernet interface Module

The standard local area network (LAN) access method ("LAN," "LAN connection" or "network card") automatically implies Ethernet. Ethernet connects devices to a network as well as to a cable modem or DSL modem for Internet access. Ethernet is defined by the IEEE as the 802.3 standard.

Ethernet is wired in a star configuration with a hub or switch in the middle. Hubs, which predated switches, are shared media devices. All stations attached to the hub share the total bandwidth. Switches provide each sender and receiver pair with the full bandwidth and are significantly faster than hubs. Ethernet uses economical twisted pair cables and standard RJ-45 connectors. To extend distances, fiber-optic cable is also used (see 100BaseT, Gigabit Ethernet and FOIRL).

General Info:- Almost all PCs and Macs come with 10/100 Ethernet ports that connect internally to circuits on the motherboard. Ethernet can be added to older machines by plugging in a network adapter via PCI, PC Card or USB. A 10/100 Ethernet port supports two speeds: 10 Mbps (10BaseT) and 100 Mbps (100BaseT). Computers also come with 10/100/1000 ports, which includes Gigabit Ethernet at 1 Gbps. Gigabit Ethernet (GigE) is commonly used as a high-speed link between switches and servers. Ethernet devices negotiate with each other and transmit at the highest speed possible. However, if a 100 Mbps switch is communicating with a 10 Mbps client, the slower speed is used.

[back to top]


2.5.4. Universal asynchronous receiver/transmitter (UART)

A universal asynchronous receiver/transmitter (usually abbreviated UART) is a type of "asynchronous receiver/transmitter", a piece of hardware that translates data between parallel and serial interfaces. Used for serial data telecommunication, a UART converts bytes of data to and from asynchronous start-stop bit streams represented as binary electrical impulses.

UARTs are commonly used in conjunction with other communication standards such as EIA RS-232.

A UART is usually an individual (or part of an) integrated circuit used for serial communications over a computer or peripheral device serial port. UARTs are now commonly included in microcontrollers (for example, PIC16F628). A dual UART or DUART combines two UARTs into a single chip. Many modern ICs now come with a UART that can also communicate synchronously; these devices incorporate the word synchronous into the acronym to become USARTs.

[back to top]


2.5.5. Pulse Width Modulation (PWM)

Pulse width modulation (PWM) is a powerful technique for controlling analog circuits with a processor's digital outputs. PWM is employed in a wide variety of applications, ranging from measurement and communications to power control and conversion. By controlling analog circuits digitally, system costs and power consumption can be drastically reduced. Many microcontrollers and DSPs include on-chip PWM controllers, making implementation easy.

In a nutshell, PWM is a way of digitally encoding analog signal levels. Through the use of high-resolution counters, the duty cycle of a square wave is modulated to encode a specific analog signal level. The PWM signal is still digital because, at any given instant of time, the full DC supply is either fully on or fully off. The voltage or current source is supplied to the analog load by means of a repeating series of on and off pulses. The on-time is the time during which the DC supply is applied to the load, and the off-time is the period during which that supply is switched off. Given a sufficient bandwidth, any analog value can be encoded with PWM.

[back to top]


2.5.6. Other Modules embedded within microcontrollers

[back to top]


 

Study Task 1

Visit the Microchip web site and look at the range of microcontrollers that they provide. These microcontrollers are collectively called PIC microcontrollers, meaning that they are Peripheral Interface Controllers.

In particular, look at the following devices:

Note the:

This will give you a feel for the support provided by the particular microcontroller manufacturer - and this is just from the 16 series.


Study Task 2

Look at the following web sites:

Or from the home page on the Intel site, click 'embedded' under the 'Products' drop down menu, then click the microcontrollers link. Click on the 'MCS 51/251' link followed by the technical documents link.

The Applications Notes give an indication of some of the peripheral capabilities. Note the diversity of applications.

On the freescale site, look for the following device families and determine the number and type of peripheral modules available:-

In particular, consider the type of application these devices are targeted towards and the size of their memory map


Self Assessment Questions

Question 1

What are the main reasons for having a timer module on a microcontroller?

Answer

The microcontroller can execute instructions in microseconds. External operations usually need to occur at very much reduced rates. For example, the turning on and off of a LED indicator needs to be performed much more slowly that the time to execute the turn on/off instructions. Also the writing to an LCD takes much longer than the execution of microcontroller instructions. The main reason for using a Timer module to produce time delays is that it frees up the processor to do other things, or at least reduces the time the processor needs to spend performing these activities.


Question 2

What is the typical resolution for an Analogue to Digital Converter in the microcontroller devices you have seen?

Answer

Most microcontrollers that you look at which have an Analogue to Digital Converter (ADC) are now 10 bit types. There are also a few with 12 bit ADCs, and there are still quite a few 8-bit A-to-D's on the older devices.


Question 3

Some microcontrollers have a serial port. Could this serial port be used to connect to an external modem?

Answer

The serial ports available on most microcontrollers do not allow a modem to be connected to the serial port. This is because the serial port is a simple device that does not have the additional signals, such as CTS/RTS and DTR/DSR, that are needed for interfacing to a modem. This means that an application requiring a modem will need to use an external serial port such as a UART to connect to the modem device.


Question 4

Give some examples of microcontrollers that you have come across that contain a serial peripheral port. Are there any external devices that could be used with these ports?

Answer

In the PIC range of devices, the serial peripheral port is embedded within the PIC16C62/63/64 PIC16C677/687/689, PIC16F7X(X), PIC16F87, PIC16F871 to 877 & PIC16F88, to name a few.

In the Freescale HC05 range of microcontrollers there are three types of Serial Peripheral Ports:- SCI (Serial Communications Interface), SPI (Serial Peripheral Interface) and SIOP (Simple Synchronous Serial I/O Port). The SCI is a feature of the 68HC05-B16/-B32/-B6/-B8, both SCI and SPI are features of 68HC05-C8A/-C9A & 68HC705-C8A. The SIOP is a feature of the 68HC05-JJ6/-JP6/-P4A/-P6, 68HC705-JP7/-P6A within the HC05 family. These latter support both a Serial I/O port and a serial peripheral port (but more on this later).

The serial ports could be connected to and UART TX/RX lines, or the serial lines of another microcontroller. To connect to the serial port of a PC would require TTL to RS232 interface device - see unit 2 notes.


Question 5

With reference to the information contained on the Freescale web site, what are the differences between the HC05, HC08 and HC11 microcontroller devices in terms of the number and type of peripheral devices they contain?

Answer

The HC05, HC08 and the HC11 families of microcontroller contain a very wide range of peripheral devices. Most contain the basic modules discussed in this unit (Timer, Serial I/O, and ADC), whilst some do not have the ADC.

The HC05 utilises Single Chip Operation (except for 68HC05C0). There is NO Direct Control of the Stack Pointer. It has one 8-Bit Index Register, one 8-Bit Accumulator. 8-Bit Math with MUL Instruction. IDR Process (4MHz max bus)

The HC08 utilises Single Chip Mode. It has Direct Control of the Stack Pointer via PUSH/PULL Instructions. It has one 16-Bit Index Register, one 8-Bit Accumulator. 8-Bit Math with MUL and DIV Instructions. UDR Process (8 MHz max bus)

The HC11 can function in both Single Chip and Expanded Modes. It has Direct Control of the Stack Pointer via PUSH/PULL Instructions. It has two 16-Bit Index Register, two 8-Bit Accumulator or One 16-Bit Accumulator. 16-Bit Math with MUL and DIV instructions. IDR P Process (4 MHz max bus)



Question 6

What is the maximum amount of external memory that can be connected to the Freescale 68HC11 microcontroller family? Can this external memory be used for either program or data memory?

Answer

The 68HC11 family of microcontrollers supports the use of external memory by using the Ports B and C as an external data/address bus. The address bus can be up to 16-bits wide (8 from Port B and 8 from Port C) so it can handle up to 216 (65536) memory locations.

Have a look at one of the data sheets for a 68HC11 device and under the General Description section you should see a table showing the "Port Signal Functions", which covers both single mode and expanded mode. Here you will see all of Port B and Port C can be utilised as external address lines (ADDR0 to ADDR15) in extended mode.

The total amount of external memory is therefore 65536 - the memory available on the microcontroller chip itself.

 


Question 7

What are the main differences between the Freescale 68HC11 (HC11 Legacy) and 68HC12 (HC12 Legacy) microcontroller architectures?

Answer

Essentially, the 68HC11 (HC11 Legacy) is an eight bit microcontroller (having an 8 bit data bus width) whilst the 68HC12 (HC12 Legacy) is a sixteen bit microcontroller (having a 16 bit data bus). Both microcontrollers share the same basic architecture and instruction set. However, this does not mean that a program designed to run on a 68HC11 will run on a 68HC12.

 


Question 8

What are the main features of the Intel 87C196CA (MCS®96 range of microcontrollers)? What type of application have Intel targeted this microcontroller towards?

Similarly, what are the intended applications for the Intel 87C196JT?

Answer

From the Intel.com home-page click on 'Embedded' under the "Products" pull-down menu, then select 'Microcontrollers', then 'Automotive Products' and finally 'PowerTrain Control' for details on the 87C196CA.

This 87C196 device targets powertrain control (in automotive applications) with a broad selection of microcontrollers used in Engine Management applications. The MCS®96 microcontroller family offers a variety of peripherals for powertrain module designs, including the flexible Event Processor Array (EPA) for high-speed capture-and-compare, A/D convertors, the Pulse-Width Modulator (PWM), the Controller Area Network (CAN) protocol and a variety of memory combinations.

Similarly, for the 87C196JT, starting at the Intel.com home-page, click on 'Embedded' under the "Products" pull-down menu, then select 'Microcontrollers', then 'Automotive Products' and finally 'Chassis Control'.

This 87C196 device targets automotive chassis control. These cost-effective microcontrollers have flash memory and stand-alone CAN devices suitable for anti-lock braking systems (ABS) and vehicle dynamics control applications.

 

[back to top]


2.6 Conclusion

From your browse of the above web sites you should now have a "feel" for some of the range of microcontroller products currently available. It is clear that these devices can be applied to many embedded system designs from the simple hardware control applications up to powerful signal processing applications.

[On to the start of Module 3]

[back to top]


Updated 07.06.07 ML

Site Search

Powered by Google
Site Map