Académique Documents
Professionnel Documents
Culture Documents
• Von Neuman
• Caracteristici:
• Magistrala comuna
pentru memoria de
program si de date
• Exemplu tipic:
• Motorola HC11
• Arhitectura Harvard
• Caracteristici:
• magistrale distincte
pentru program si date
• Exemplu tipic
• Atmel AVR
Consecinte ale arhitecturii Harvard
– The presence of the second bus makes the following things possible:
While an instruction is executed, the next instruction can be fetched
from the program memory. This technique is called pipelining and
brings a significant increase of the computer speed.
The program memory can be organized in words of a different size,
usually larger, than the data memory. Wider instructions mean a
greater data flow to the CPU, and therefore the overall speed is
higher.
Such architecture, along with reducing and optimizing the instruction
set, allow that most instructions execute in a single machine cycle.
Since the Harvard architecture is often accompanied by the reduction
of the size and complexity of the instruction set, the computers with
this architecture are also called RISC. (Reduced Instruction Set
Computers) For example, some PIC microcontrollers have an
instruction set of only 35 instructions, compared to more than 100 of
HC11. The speed increase is even higher.
Consecinte asupra organizarii spatiului de adrese
• Harta memoriei in
cazul unui
microcontroller HC11
• Harta memoriei
pentru un
microcontroller
din seria Atmel
AVR
• Se observa ca aici
exista 3 spatii de
adrese
Registrele interne ale CPU
• HC11 • AVR
• Doi acumulatori A si B. Pot fi • 32 acumulatori R0-R31
concatenati pentru a forma un • R26-R27, R28-R29, R30-R31
registru dublu D can be concatenated to form the
• Doua registre index X si Y X, Y, Z , registers
• Stack pointer • Stack pointer SP
• Registrul de stare CPU denumit • registrul de stare CPU denumit
CCR SREG
• Numaratorul de program PC • Numaratorul de program
Interfetele periferice
• Any peripheral
interface contains
one or more
control and status
registers, and one
or more data
registers
• These registers are,
normally, located
in the address
space of the data
memory, and are
accessed as RAM
locations
Interfete periferice uzuale
Definitie:
• An interrupt is a mechanism that allows an
external event to temporarily put on hold the
normal execution of the program, forcing the
execution of a specific subroutine. Once the
interrupt service subroutine completes, the main
program continues from the point where it was
interrupted.
Procesul de tratare a unei intreruperi
• The next step is the execution of the interrupt service routine (ISR).
This is a program sequence similar to a subroutine, but ended with a
special instruction called Return from Interrupt (RTI, RETI).
• Observatie importanta: STAREA masinii trebuie salvata prin soft
inainte de executia rutinei de intrerupere si restaurata dupa executia
rutinei de intrerupere.
• The final step in handling an interrupt is the actual return to the main
program. This is done by executing a RTI (RETI) instruction as
mentioned before. When this instruction is encountered, the contents of
PC, saved in step 2, is retrieved from stack and restored, which is
equivalent to a jump to the point where the program was interrupted.
Intreruperi - note importante
The stack is essential for the interrupt system. Both the PC and the
CPU status are saved in the stack when handling interrupts.
Therefore, the SP must be initialized by software before enabling
the interrupts.
The interrupt service routine must save the CPU status and restore
it before returning to the main program.
If two or more interrupt requests occur simultaneously, they are
serviced in a predetermined, order according to a hardwired
priority
Controlul asupra intreruperilor
.......
.ORG $000C
RJMP ANA_COMP ;unconditional jump to the
;interrupt handler
.......
ANA_COMP:
.......
RETI
Porturile de intrare-iesire ale
microcontrollerelor
BAUD 7 6 5 4 3 2 1 0
TCLR - SCP1 SCP0 RCKB SCR2 SCR1 SCR0
RESET 0 0 0 0 0 0 0 0
Bitii registrului BAUD - Controlul prescaller-ului
Example
Knowing that the oscillator frequency is 8 MHz, and that the out-
put frequency of the baud generator must be 16 times the actual
baud rate, determine the value to write in the BAUD register in or-
der to obtain 9600 baud communication speed.
The input clock for the prescaller is the system clock E.
fE=fOSC/4=2MHz=2000000Hz
The output clock must have the frequency:
f1=9600*16=153600 Hz
This gives the global division rate: 2000000/153600=13.
Choose the prescaller to divide by 13 (SCP1:SCP0=1:1), and the
secondary counter to divide by 1 (SCR2:SCR1:SCR0=0:0:0). The
resulting value for BAUD register is 00110000b=30H.
SCSR - SCI Status Register
• SCSR 7 6 5 4 3 2 1 0
• RESET 0 0 0 0 0 0 0 0
Bitii de stare din SCSR
• TDRE – Transmitter Data Register Empty
• 0 – SCDR busy
• 1 – SCDR ready for a new operation
• TC — Transmit Complete Flag
• 0 = Transmitter busy
• 1 = Transmitter ready
• RDRF — Receive Data Register Full Flag
• 0 = SCDR empty
• 1 = SCDR full
• IDLE —Rx Idle Line Detected Flag
• 0 = RxD line is active
• 1 = RxD line is idle
• OR — Overrun Error Flag
• 0 = No overrun
• 1 = Overrun detected
• NF — Noise Error Flag
• FE — Framing Error
• All error bits are cleared by reading SCSR followed by a read from SCDR.
Registrul SCCR1
SCCR1 7 6 5 4 3 2 1 0
R8 T8 - M WAKE - - -
RESET 1 1 0 0 0 0 0 0
SCCR2 7 6 5 4 3 2 1 0
RESET 1 1 0 0 0 0 0 0
UCR 7 6 5 4 3 2 1 0
• DTE=Data
Terminal
Equipment (ex.
computer, PLC,
etc.)
• DCE=Data
Communication
Equipment (ex.
Modem)
Standardul RS232
• Multidrop simplex
• Sunt admise pana la 10
receptoare conectate la
acelasi transmitator.
• RS422 nu permite realizarea
unor topologii multipoint, cu
alte cuvinte, pe o linie de
comunicatie poate fi
conectat un singur circuit
driver. Acest neajuns a fost
rezolvat prin introducerea
standardului de interfata
RS485.
Standardul RS485
TFLG1 7 6 5 4 3 2 1 0
RESET 0 0 0 0 0 0 0 0
WDCTR 7 6 5 4 3 2 1 0
• PINC.0 intrarea de
armare/dezarmare
• PINC.1 - zona 1 - delayed
• Z2-Z4 zone instant
conectate la PINC.2-
PINC.4
• PORB.0 - LED
semnalizare starea de
armat
• PORTB.1 releu de alrma
Analiza starilor posibile
• Starea de repaus - starea 0 - sistemul este
dezarmat. Se ignora alarmele, dar se testeaza
intrarea ARM/DISARM. Daca aceasta se
activeaza se trece in starea 1 (prearmare) si se
porneste un timer pentru EXIT DELAY.
• In starea 1 (prearmat), zonele instant (Z2-Z4)
genereaza alarma. Zona intarziata este ignorata. Se
testeaza expirarea timerului EXIT DELAY. La
expirare se trece in starea 2 (armare)
Analiza starilor posibile - continuare
• Starea 2 - sistem armat. Zonele instant genereaza
alarma. La activarea zonei intarziate Z1 se
porneste un timer pentru ENTRY DELAY si se
intra in starea 3 (prealarma sau asteptare
dezarmare).
• Starea 3. Se asteapta activarea intrarii de
dezarmare, sau expirarea timerului de ENTRY
DELAY. Daca pana la expirarea timerului nu a
fost dezarmat sistemul, se genereaza alarma.
Analiza starilor posibile - continuare
• Starea 4 - alarma.
• Se activeaza releul pentru comanda sirenei
• se testeaza timerul asociat cu sirena
• Daca a expirat timerul, sirena este oprita dar
sistemul ramane armat si se revine in starea 2.
• Se testeaza si intarea de dezarmare. Daca aceasta
se activeaza pe durata cat sirena este ON, se
opreste sirena si se revine in starea 0.
Lucruri demne de retinut
• Secventa comanda-confirmare prin limitator sau
time-out cu avarie este foarte raspandita in
practica.
• Modalitatea de a gandi programul ca un automat
finit este extrem de productiva - simplifica analiza,
programul este usor de depanat, si scade sansa de
a scapa din vedere unele aspecte ale evolutiei
sistemului.
PROIECTAREA SISTEMELOR CU
MICROPROCESOARE
Cursul nr. 11
di
L Ri V K
dt
di Regim
0 stationar
dt
R 0
V K Turatia este proportionala cu
tensiunea la borne
Comanda motorului folosind un
semnal PWM
Tp
D
T
T
1
Vout y(t )dt
T0
Vmax t [ DT ,T ]
y(t )
0 t [0, DT ]
DT
1 DT
Vout Vmax dt Vmax DVmax
T 0 T
Schema bloc a solutiei hardware
Implementarea unui regulator
proportional
Vp – valoarea prescrisa a turatiei
Vm - valoarea masurata a turatiei
e(t)= Vp-Vm – eroarea de reglaj
Se pune problema generarii Vout(t) in asa fel incat
e(t)->0 in orice moment.
Regulatorul proportional genereaza Vout=Kp*e(t)
Kp este o constanta de proportionalitate
Solutia software
• Se porneste de la proiectul template
• Se creaza un nou proiect dc_motor1, care
contine modulele analog, timer si pwm
• Se definesc variabilele (de tip octet) Vp,
Vm
• Se defineste o variabila (int) error (e(t))
• Se defineste o variabila (int) Kp si se
initializeaza Kp=50
Solutia software
Kp=50;
while (1)
{
if(TTAB[0]==0)
{
TTAB[0]=2; //20ms interval intre doua actualizari
Vp=read_adc(0);
Vm=read_adc(1);
compute_error();
OCR2=reglaj();
}
};
}
Functiile folosite
void compute_error(void)
{
error=(int)Vp-(int)Vm;
}
unsigned char reglaj(void)
{
Vout=Kp*error;
if(Vout<0) return(0);
if(Vout>255) return(255);
return(Vout&0xFF);
}
Analiza rezultatelor
Ti N
ei
1 1 i 0
Vi e(t )dt t 0 * ei
Ti 0 N * t0 i 0 N
Calculul componentei derivative
df (t ) f f (t n ) f (t n 1 )
f ' (t )
dt t tn tn 1
tn tn 1 1
f ' (t ) f (t n ) f (t n 1 )
Programul complet
while (1)
{
if(TTAB[0]==0)
{
TTAB[0]=1;
Vp=read_adc(0);
Vm=read_adc(1);
error=(int)Vp-(int)Vm;
IBUF[ibptr++]=error;
if(ibptr>=Ti) ibptr=0;
OCR2=reglaj(); //executia propriu-zisa
}
if(TTAB[1]==0)
{
TTAB[1]=Td;
calc_deriv();
}
}; //end while
Principalele functii
unsigned char reglaj(void)
{
calc_medie();
Vout=Kp*error;
Vout=Vout+Ki*medie;
Vout=Vout+Kd*derivata;
if(Vout<0) return(0);
if(Vout>255) return(255);
return(Vout&0xFF);
}
void calc_medie(void)
{
int i;
medie=0;
for(i=0;i<Ti;i++) medie=medie+IBUF[i];
medie =medie/Ti;
}
void calc_deriv(void)
{
Vp=read_adc(0);
Vm=read_adc(1);
error=(int)Vp-(int)Vm;
derivata=error-prev_error;
prev_error=error;
}
Proiectarea sistemelor cu
microprocesoare
Curs 12
Alte familii de microcontrollere
Intel 80C51
• Primul si cel mai popular microcontroller, dar nu
si cel mai performant
• Magistrala de date de 8 biti, 16 biti pentru
magistrala de adrese
• Arhitectura este Von Neumann, cu pagini distincte
si spatii de adrese distincte pentru memoria de
program si de date.
• 128 octeti RAM, 4K ROM, fara EEPROM
• Doua timere, UART
• Produs initial de Intel, dar preluat si imbunatatit de
Atmel, Philips, TI, ST Microelectronics etc.
I80C51 - pinout
I8051 functionarea cu bus extern
Particularitati ale 80C51
• Dispune de 4 banc-uri de cate 8 registre interne de
8 biti R0-R7. La un moment dat, un singur banc
este ―vizibil‖ pentru CPU.
• Cele 4x8 registre sunt vizibile in spatiul de adrese
al memoriei de date (0x00-0x1F).
• Mai are doua acumulatoare A si B, si un registru
index numit Data Pointer DPTR.
• Registrul SP e de 8 biti!! – rezulta ca stiva poate fi
setata doar in memoria interna.
• SP se incrementeaza la PUSH (invers fata de
majoritatea microprocesoarelor uzuale).
80C51 avantaje si dezavantaje
• Avantaje:
- E foarte bine documentat si sustinut cu
unelte software
- Sunt disponibile numeroare exemple de
proiecte
Dezavantaje:
- E relativ sarac in resurse
- Nu are facilitatea ISP
Microcontrollerele PIC seria ―low end‖
Microchip PIC – seria mid range
Microchip PIC seria high end
Microchip PIC caracteristici
• Arhitectură HARVARD
• Spatiu de adrese unic desi au bus-uri diferite
pentru ROM, RAM si periferice
• 31 registre generale
– 16 registre vizibile în orice moment
– R14: LR (Link Register)
– R15: PC (Program Counter)
– De obicei, R13 este stack pointer-ul SP
ARM(4)
• Au doua seturi de instructiuni: unul
―normal‖ pe 32 de biti si unul ―thumb‖ pe
16 biti.
• Se pot combina cele două seturi
• Comutarea între starea ARM şi starea
Thumb: cu instrucţiunea BX (Branch and
eXchange)
• Rolul thumb este sa reduca necesarul de
memorii externe
Exemplu de procesoare ARM7 seria LPC2xxx
de la NXP (Philips)
LPC2103 minimal
LPC2xxx resurse on chip