Page 234 - Mechatronics with Experiments
P. 234
220 MECHATRONICS
All of the input and output access is simply a matter of accessing a set of registers
corresponding to the inputs and outputs. Generally, there are three kinds of register for
any I/O:
1. Setup registers used to “setup” (configure) the operation of the I/O, that is, if a pin is
programmed to be a digital input, digital output, or analog I/O. This is typically done
once at the beginning of the application program.
2. Status/Control registers, used to determine the status of the I/O at any time, as well as
initiate actions, that is to tell an ADC converter to start a conversion or to determine
if the current ADC conversion process is completed.
3. Read/write registers, which are the “data” register for the I/O. For input, it is to be
read, for output, it is to be written. Once the I/Os are setup, reading or writing an I/O
is simply a matter of reading/writing the corresponding data register, just like reading
and writing to a variable in memory.
In embedded programming, the I/O control is a matter of writing to/reading from these
three groups of registers. This read/write operation may quite often read/write individual
bits of registers (i.e., writing 0 or 1 to a particular bit in a register, or reading to determine
if a particular bit in a register is 0 or 1), as well as the whole register byte-by-byte or
word-by-word. Therefore, we can say that at the lowest level (register level) programming
of an embedded controller, the programming involves the read/write operation of bits. High
level programming language support with processor specific library functions often are
used in order to make the program development generic and easily portable to different
microcontrollers by simply configuring the compiler libraries for different processors. For
real-time programming, understanding how I/O works and how real-time interrupts are
handled are key to successful real-time application software development.
4.3.1 Microcontroller Hardware
As users of microcontrollers in mechatronic systems, we need to understand the hardware of
microcontrollers. We will study this from the inside out. In the discussion, we are interested
in the functionality of the microcontroller components as opposed to how they are designed
or manufactured.
The main hardware features that one needs to understand for any microcontroller or
digital signal processor (DSP) are as follows:
1. the pin-out on the chip that identifies the role of each pin,
2. the registers in the CPU that define the “brain” structure and internal workings of the
microprocessor, memory, the bus structure, which defines how the CPU communi-
cates with the rest of the memory and I/O resources,
3. the support chips such as the real-time clock, watch-dog timer, interrupt controller,
programmable timers/counters, analog to digital converter (ADC), and pulse width
modulation (PWM) module.
Most of the output pins of the microcontroller are implemented as three-state devices
(the state of the line can be one of three states: LOW (OFF), HIGH (ON), High Impedance
states), which allows them to be configured as either input or output under software
control.
The application program is stored in the ROM type memory so that the program is
not lost when the power is turned OFF to the computer. As a result, whenever the power is
turned ON, the computer knows what to do (that is the program and necessary data in the
ROM). The data generated after the program starts to run and which is not needed when