Answer to Question #288937 in Mechanical Engineering for sten

Question #288937

specify and select a microcontroller from current available devices and include the following within the report:

• an explanation of the hardware interfaces of a selected microcontroller of the topic/ application that was assigned/selected and

• a critical evaluation of the software architecture that operates within your selected microcontroller in terms of its subsystems and characteristics that required to perform the application functions.


1
Expert's answer
2022-02-07T21:02:02-0500

microcontrollers(how such small microcontrollers work and operate.)

  Time after time I see beginners try to get started in embedded electronics, only to be overwhelmed and not know where to start. Some even make the mistake of trying to write their own code without rst gaining a thorough understanding of the microcontroller/microprocessor they’re working with, the programming language they’re working with, or even basic programming concepts. Not to worry though... this article should pose a good primer to get your feet wet in the world of embedded electronics.

This article does not attempt to teach about any specic microcontroller/microprocessor, but is more of a primer to explain the general concepts which apply to all microcontrollers/microprocessors.

What is a microcontroller?

A microcontroller is a tiny microcomputer on a chip. It has a CPU, RAM (Random Access Memory), special function registers, program ROM memory, data ROM memory, anywhere from one to several parallel I/O (Input/Output) ports, and can have a host of on chip peripherals including but not limited to Analog-to- Digital Converter (ADC), Digital-to-Analog Converter (DAC), Serial UART, one or several timers, comparators/on chip voltage reference, capture/compare/PWM (Pulse Width Modulation) module, Master Synchronous Serial Port for SPI (Serial Peripheral Interface)/I2C (Inter Integrated Circuit) communications, USB port, ethernet port, on chip oscillators, along with a host of other peripherals.

What is a microprocessor (wait, you mean there’s actually a difference)?

A microprocessor is everything a microcontroller is but without the program ROM on chip. The program code resides off-chip in a separate external EPROM chip.

Program ROM and Data ROM

The on-chip ROM memory (Read Only Memory) on a microcontroller is like a microcontroller’s hard drive. It has two partitions. One partition is reserved for the storage of the program code while the other partition is reserved for permanent storage of data that is used by the chip during normal program execution. On a given PIC microcontroller with say 8K of program space, the program space would occupy ROM addresses 0x0000 – 0x1FFF (or 0 – 8191 in decimal). The data space would start at program ROM address 0x2100. If the data ROM space were 256 bytes long, the data ROM space would occupy ROM addresses 0x2100 – 0x21FF (or 8448 – 8704 in decimal).

CPU

CPU stands for Central Processing Unit. It is basically the “brains” of the microcontroller. It is what fetches the instructions from the code memory and executes the instructions that it fetches

Data RAM

The data RAM (Random Access Memory) is the data space that is used for temporarily storing constant and variable values that are used by the microcontroller during normal program execution. The amount of physical RAM space on a given microcontroller varies from one microcontroller to the next. The data RAM on a microcontroller is organized into several “registers”, each with its own unique “address”. A RAM register on an 8 bit microcontroller can hold a total of 8 bits, or one byte of data. A typical RAM space specication may specify that it is 256 x 8. This means that there are a total of 256 registers in the RAM, and those registers can hold 8 bits each.

A register is just a location in memory that you can write data to or read data from. Some of us refer to registers as “locations”.

Special Function Registers

The special function registers (or simply SFR’s) on a microcontroller are just like the registers in data RAM. You can write data to them as well as read data from them. Where they differ is that some SFR’s directly control the on-chip hardware on the microcontroller while others are controlled by the on-chip hardware on the microcontroller.

Each bit in an SFR is assigned to a function. In the SFR’s you have control bits and ag bits. Control bits are like “switches” that turn a function on or off depending on if you write a 1 or a 0 to that bit location in the SFR. Flag bits are like “indicator lights” that indicate whether or not a given condition exists depending on whether the ag bit is a 1 or a 0. Control bits directly control the hardware. Flag bits are controlled by the hardware. In any given program, we typically write to control bits while we read ag bits (some ag bits must be manually cleared by writing to them depending on the microcontroller...more on this later).

Each piece of hardware on the microcontroller will have at least 1 SFR assigned to it. Some hardware may have several SFR’s assigned to it. Consult your microcontroller’s data sheet to learn more about its specic SFR organization.

Conguration Bits

Most microcontrollers have special bits known as the “conguration bits”. These bits congure special options on the microcontroller including but not limited to –

Oscillator Type

* Watchdog Timer On/Off

* Power Up Timer On/Off

* Brown Out Reset On/Off

* Low Voltage Programming On/Off * Fail Safe Clock Monitor On/Off

* Internal/External Switchover On/Off

On a PIC microcontroller, there are even conguration bits for program code protection and data code protection. These bits prevent the program or data spaces from being read by external programming hardware to keep others from stealing your code. On an Atmel AT89S chip (8051 derivative), this is set by what is known as the “lock bits”.

Some refer to the conguration bits as the “fuse bits”. This comes from the old days of microprocessors that had actual “fuses” on chip that would get blown if certain fuse bit controlled functions were turned off. These fuses were “one time programmable”...once they were blown, there was no “unblowing” them. However, with the advent of ash memory available on modern microcontrollers, there are no more literal “fuses” on the chip. But the term itself carried over due to the conguration bits essentially providing the same control as the fuse bits did.

The ALU (Arithmetic and Logic Unit)

This piece of hardware is essentially responsible for all of the math and logic operations that are performed by the microcontroller. On most microcontrollers, the ALU will have 3 ag bits associated with it –

The Zero Bit – This ag bit gets set to a 1 by the hardware whenever a math operation results in a zero result. It will be cleared to a 0 by the hardware whenever a math operation results in a non-zero result.

The Carry/Borrow Bit – This ag bit works as a carry bit for addition operations while working as a borrow ag for subtraction operations. A “carry” occurs when the result of an addition operation results in a value larger than what the register is capable of holding. An 8 bit register can hold a maximum value of 255 (FF in hex or 11111111 in binary).

If an addition operation results in a result of greater than 255, the carry ag gets set to 1. If an addition operation results in a result of less than 255, no carry takes place so the carry ag gets cleared to 0.

The Digit Carry/Borrow Bit – This ag bit does the same thing as the carry/borrow ag, but it only works to indicate if a carry/borrow takes place between bits 3 and 4 only.

The carry/borrow bit is a handy ag that allows us to compare two values to see if one value is greater than/less than the other value. Example...we have two values: VALUE1 and VALUE2. In code we perform this operation –

VALUE1 – VALUE2 = VALUE3

Once the subtract operation has been executed, we then read/check the high/low state of the carry/borrow bit.

If VALUE2 is greater than VALUE1, the result of the subtraction will be negative, which will clear the carry/borrow bit to 0. If VALUE2 is less than VALUE1, the result of the subtraction will be positive, which will set the carry/borrow bit to 1.




The ONLY way to know exactly how to work with your microcontroller and its hardware is to consult its datasheet. The datasheet explains every SFR, every piece of on chip hardware, the absolute maximum electrical ratings, the program/data memory organization, how the parallel ports are wired and how they work, the instruction set summary (for those of you who code in assembly language), etc etc. Pretty much everything that you as the programmer will need to know about your microcontroller is in the microcontroller’s datasheet.


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS