SKEDSOFT

Mechatronics

Polling and Interrupts

There are two basic methods for the microprocessor to control input and output. These are polling and interrupt.

Polling is just that, the microprocessor periodically checking various peripheral devices to determine if input or output is waiting. If a peripheral device has some input or output that should be processed, a flag will be set.

The problem is that a lot of processing time is wasted checking for inputs when they are not changing. Servicing an interrupt is an alternative method to control inputs and outputs.

In this method, a register in the microprocessor must have set an interrupt enable (IE) bit for a particular peripheral device. When an interrupt is initiated by the peripheral, a flag is set for the microprocessor.

The interrupt request (IRQ) line will go active, and the microprocessor will service the interrupt. Servicing an interrupt means that the normal processing of the microprocessor is halted (i.e., interrupted) while the input/output is completed.

In order to resume normal processing, the microprocessor needs to store the contents of its registers before the interrupt is serviced.

This process includes saving all active register contents to a stack, a part of RAM designated for this purpose, in a process known as a push. After a push, the microprocessor can then load the address of the Interrupt Service Routine and complete the input/output.

When that portion of code is complete, the contents of the stack are reloaded to the registers in an operation known as a Pop (or Pull) and normal processing resumes.

 

Input and Output Transmission

Once the input or output is ready for transmission, there are several modes that can be used. First, data can be moved in either parallel or serial mode.

Parallel mode means that multiple bits (e.g., 16 bits) move in parallel down a multiple pathway or bus from source to destination.

 Serial mode means that the bits move one at a time, in a series, down a single pathway. Parallel mode traffic is faster in that multiple bits are moving together, but the number of pathways is a limiting factor.

 For this reason parallel mode is usually used for components located close to one another while serial transmission is used if any distance is involved. Serial data transmission can also be differentiated by being asynchronous or synchronous. Asynchronous

data transmission uses separate clocks between the sender and receiver of data. Since these clocks are not synchronized, additional bits called start and stop bits are required to designate the boundaries of the bytes being sent. Synchronous data transmission uses a common or synchronized timing source. Start and stop bits are thus not needed, and overall throughput is increased.

A third way of differentiating data transmission is by direction. A simplex line is a one direction only pathway. Data from a sensor to the microcontroller may use simplex mode.

 Half-duplex mode allows two-way traffic, but only one direction at a time.

 This requires a form of flow control to avoid data transmission errors. Full-duplex mode allows two-way simultaneous transmission of data.

The agreement between sending and receiving units regarding the parameters of data transmission (including transmission speed) is known as handshaking.

HC12 Microcontroller Input–Output Subsystems

There are four input–output subsystems on the Motorola HC12 microcontroller that can be used to exemplify the data transmission section above.

 The serial communications interface (SCI) is an asynchronous serial device available on the HC12. It can be either polled or interrupt driven and is intended for communication between remote devices. Related to SCI is the serial peripheral interface (SPI). SPI is a synchronous serial interface.

 It is intended for communication between units that supportSPI like a network of multiple microcontrollers. Because of the synchronization of timing that is required, SPI uses a system of master slave relationships between microcontrollers. The pulse width modulation (PWM) subsystem is often used for motor and solenoid control.

 Using registers that are mapped to both the PWM unit and the microprocessor, a PWM output can be commanded by setting values for the period and duty cycle in the proper registers.

 This will result in a particular on-time and off-time voltage command. Last, the serial in-circuit debugger (SDI) allows the microcontroller to connect to a PC for checking and modifying embedded software.