Professional Documents
Culture Documents
00 Course Embedded Systems FN
00 Course Embedded Systems FN
L
Str. Salzburg, nr. 8, 550018, Sibiu, Romania
• Who am I?
• What I do for a living?
• Why am I teaching?
Microprocessor are found in applications where tasks are unspecific like developing software, games,
websites
Microcontrollers are found in systems designed to perform a specific tasks. Specific means applications
where the relationship of input and output is defined
The processing performance of the Microprocessor is orders of magnitude higher than the
microcontroller
Normal execution of a given software application is contained within the bounds of one
program, or instruction stream. However, system designers and implementers also
have to understand how breaks in program flow occur, and how they may affect the
running program. Flow breaks fall into two general classes:
Systems with multiple interrupt inputs provide the ability to mask (inhibit)
interrupt requests individually and/or on a priority basis. This capability may be
built into the CPU or provided by an external interrupt controller. Typically,
there are one or more interrupt mask registers, with individual bits allowing or
inhibiting individual interrupt sources.
There is often also one non-maskable interrupt input to the CPU that is used to
signal important conditions such as pending power fail, reset button pressed, or
watchdog timer expiration.
….
Interrupt routine instruction n
POP
instruction 1
….
instruction n
Every microcontroller pin organized in ports that can be configurable, except some pins that are dedicated to
some special functions (voltage, debug, clk, etc). Pins can be configured as DIO (digital pins inputs or
outputs) or to be configured to have alternate function (used by other module: timers, spi, UART, PWM, etc).
Input
Parallel
Digital input μC
port
Output
Parallel
Digital output μC
port
The timer shown consists of a loadable 8-bit count register, an input clock signal, and an output
signal. Software loads the count register with an initial value between 0x00 and 0xFF. Each
subsequent transition of the input clock signal increments that value.
When the 8-bit count overflows, the output signal is asserted. The output signal may thereby
trigger an interrupt at the processor or set a bit that the processor can read. To restart the timer,
software reloads the count register with the same or a different initial value.
Watchdog Timer
PWM
DC Motors
The process of restarting the watchdog timer's counter is sometimes called "kicking
the dog." The appropriate visual metaphor is that of a man being attacked by a
vicious dog. If he keeps kicking the dog, it can't ever bite him. But he must keep
kicking the dog at regular intervals to avoid a bite. Similarly, the software must
restart the watchdog timer at a regular rate, or risk being restarted.
ADC
Signal
generator
Analog signal
• mode
value
μC
• resolution
How many bits would you need to divide 10 v into .01 v intervals?
To get the answer to the question consider the following.
•If you divide 10 v into .01 v intervals you need 1000 intervals.
•If you need 1000 intervals you need to think about a power of 2 that is larger than
1000.
•The smallest power of 2 that is larger than 1000 is 210 which is equal to 1024.
•That means that you need 10 bits in the converter, and the count in the
counter/register will run from 0 to 1023.
•And that leads us to observe that real converters often go to 10.23v, not 10v because
that gives perfect .01v increments between resolvable voltages.
•And another converter might run from -5.12v to +5.11v for the same reason.
- Serial communication
- RS-232 Interface
- Endianness
• A parallel port sends and receives data eight bits at a time over eight separate wires
or lines. This allows data to be transferred very quickly
• A serial port sends and receives data, one bit at a time over one wire. While it takes
eight times as long to transfer each byte of data this way, only a few wires are
required.
• Although this is slower than parallel communication, which allows the transmission
of an entire byte at once, it is simpler and can be used over longer distances
• The cabling between equipment for parallel communication can be no more than 20
meters total, with no more than 2 meters between any two devices;
• Serial communication can be extended up to 1200meters
• The serial port on your PC is a full-duplex device meaning that it can send and
receive data at the same time. In order to be able to do this, it uses separate lines for
transmitting and receiving data.
The only advantage of synchronous data transfer is the Lower overhead and thus,
greater throughput, compared to asynchronous one. But it has some disadvantages
such as,
1.Slightly more complex and
2.Hardware is more expensive
Disadvantages of SPI
1. Requires more pins on IC packages than I²C
2. No in-band addressing. Out-of-band chip select signals are required on shared busses.
3. No hardware flow control
4. No slave acknowledgment
5. Multi-master busses are rare and awkward, and are usually limited to a single slave.
6. Without a formal standard, validating conformance is not possible
7. Only handles short distances compared to RS-232, RS-485, or CAN.
- Preprocessor
- Preprocessor directives
- Compiler
- Linker
The preprocessor modifies the text of the source code file via a variety
of text substitution and manipulation operations. That modified source is
subsequently passed to the C compiler for compilation.
Preprocessor commands are lines in program that start with “#” and are
not finished with “;”:
• #define
• #include
• #ifdef
• #endif
For example, given a header file foo.h The preprocessor will convert main.c to
a file main.i that looks like
extern int group_size;
void do_stuff(int n); extern int group_size;
void do_stuff(int n);
and a source code file main.c
int main(int argc,const char* arg[])
#include "foo.h“ {
int main(int argc,const char* arg[]) group_size = 12;
{ do_stuff(20);
group_size = 12; }
do_stuff(20);
}
Once defined, these macros can be used in code much as you would use any other function.
float f(float x)
{
return 3.2*CUBE(x)-4.2*SQ(x)+10.7*x+3.0;
}
The preprocessor will use a simple text substitution mechanism to replace the code above with
the expanded form of the macros:
float f(float x)
{
return 3.2*x*x*x-4.2*x*x+10.7*x+3.0;
}
Links the compiled codes of application software, object codes from library and OS kernel
functions.
Linking necessitates because of the number of codes to be linked for the final binary file.
For example, standard codes for to program a delay task, must link with the assembled
codes.
The delay code sequential from a beginning address.
The assembly software codes also sequential from another beginning address.
Both the codes have to at the distinct addresses as well as at the available addresses in the
system. Linker links these
After linking, re-allocation of the sequences of placing the codes before actually placement of the
codes in the memory
Linked file in binary for run on a computer commonly known as executable file or simply '.exe'
file.
- Macros
- Memory allocation
- Data initialization
- Stack
The C language supports two kinds of memory allocation through the variables in C programs:
• Static allocation is what happens when you declare a static or global variable. Each static
or global variable defines one block of space, of a fixed size. The space is allocated once,
when your program is started (part of the exec operation), and is never freed.
• Automatic allocation happens when you declare an automatic variable, such as a function
argument or a local variable. The space for an automatic variable is allocated when the
compound statement containing the declaration is entered, and is freed when that
compound statement is exited.
A third important kind of memory allocation, dynamic allocation, is not supported by C variables
but is available via GNU C Library functions.
In C/C++, an initializer is an optional part of a declarator. It consists of the '=' character followed by an
expression or a comma-separated list of expressions placed in curly brackets (braces). The latter list
is sometimes called the "initializer list" or "initialization list", although the term "initializer list" is formally
reserved for initialization of class/struct members in C++. A declaration which includes initialization is
commonly called definition.
int i = 0;
int k[4] = {0, 1};
char tx[3]="fa";
char ty[2]="fa";
struct point {int x; int y;} p = { .y = 13 , .x = 7 };
Data initialization may occur without explicit syntax in a program to do so. For example, if static
variables are declared without an initializer, then those of primitive data types are initialized with the
value of zero of the corresponding type, while static objects of class type are initialized with their
default constructors.
- Constants
- Pointers
- Functions
#include <stdio.h>
int main ()
{
int var = 20; /* actual variable declaration */
int *ip; /* pointer variable declaration */
ip = &var; /* store address of var in pointer variable*/
This method copies the address of an argument into the formal parameter. Inside the
Call by reference function, the address is used to access the actual argument used in the call. This
means that changes made to the parameter affect the argument.
By default, C uses call by value to pass arguments. In general, this means that code within a
function cannot alter the arguments used to call the function and above mentioned example while
calling max() function used the same method.