Sunteți pe pagina 1din 15

MINISTERUL EDUCAIEI AL REPUBLICII MOLDOVA

UNIVERSITATEA TEHNIC A MOLDOVEI


Facultatea Calculatoare, Informatic i Microelectronic
Catedra Microelectronic i Ingineria Biomedical

Raport
Lucrare de laborator nr. 4
la disciplina
Proiectarea Microsistemelor
Tema: Dispositive de acionare.

A efectuat:

st.gr. ISBM-111, Arpentii Nicolae

A verificat:

lector asistent, Lazari Eugen

Chiinu 2014

Scopul lucrrii:
S se proiecteze un sistem care ar permite recepionarea comenzilor prin interfaa serial i interpretarea
lor ca comenzi de control a 2 motoare n curent continuu. Motoarele vor fi controlate prin intermediul
driver-ului L293D.

Sarcina:
Se consider c motoarele sunt plasate pe un cru, iar aciunile roilor vor determina direcia de micare
a carului. Setul de comenzi recepionat prin interfaa serial va implica schimbarea vitezelor roilor
conform funciilor ataate comenzilor respective.
Noiuni teoretice:
Controlarea unui motor de curent continuu cu ajutorul unui microcontroller si a unei punti H, prin
controlul unui motor DC se intelege atat reglajul turatiei cat si sensului de rotatie.
O punte H este un circuit electronic ce permite aplicarea unei tensiuni pe o sarcin n orice sens. Aceste
circuite sunt adesea folosite n robotic i alte aplicaii pentru a permite motoarelor de curent continuu s
ruleze nainte i napoi. Punile H sunt disponibile ca circuite integrate sau pot fi construite din
componente discrete, tranzistoare bipolare sau MOS.
Puntea H are numele derivat de la modul obinuit de desenare a circuitului. Aceasta este singura cale de tip
solid state de a comanda motorul n ambele direcii.
Mod de funionare:
Atunci cnd ntreruptoarele S1 i S4 (n conformitate cu Figura 1) sunt nchise i S2 i S3 sunt
deschise o tensiune pozitiv va fi aplicate la nivelul motorului. Prin deschiderea ntreruptoarelor S1 i S4
i nchiderea ntreruptoarelor S2 i S3, aceast tensiune este inversat, astfel s permit funcionarea
invers a motorului.

Figura 1. Schema funcional a punii H

Mersul lucrrii:
Am analizat sarcina lucrarii, n proectare am utilizat metoda top-down, am realizat schema bloc i
schema flux de date a sistemului dupa care am montat schema electric i am scris codul surs.
.

Figura 2. Proectarea top-down

Schemele bloc a sistemului:


Sunt reprezentate modulele principale a sistemului, interaciunea dintre ele, schema funcional i flux
de date .

Figura3. Schema funcional

Figura 4. Schema flux de de date

Schemele bloc:

Figura 5. Schema bloc a programului principal

Figura 6. Schema bloc a programului principal

Figura 7. Schema bloc pentru dirijarea directiei si turatiei

Figura 8. Schema bloc pentru dirijarea directiei si turatiei


Schema electric n Proteus pentru simulare:

Figura 9. Rotirea Motorului 1

Codul programului:
// main.c
#include
#include
#include
#include
#define

<avr/io.h>
<avr/interrupt.h>
<ownLib/UARTMethods.h>
"directionControl.h"
F_CPU 8000000UL

void portInit(void);
void main(void) {
portInit();
UART_Initialize( EIGHT_MHZ , SET ) ;
//wrongDestinationInit();
timer1Init();
//LCD_init();
//unsigned char buffer = 0;
asm("sei");
while(1){
//buffer = USART_Receive();
}
}
ISR(USART_RXC_vect){
USART_InterruptProcces();
}
void portInit(void){
DDRD |= ( 1 << PD3 ) | ( 1 << PD2 ) | (1 << PD4) | ( 1 << PD5 )
| ( 1 << PD6 )| ( 1 << PD7 );
//PORTD |= ( 1 << PD3 ) | ( 1 << PD7 ) ;
DDRB = 255;
DDRA = 255 ;
}

/directionControl.h
/*-----------------------------------------------------------File Name: directionControl.h
Created: 25.04.2014
Modified: 26.04.2014
Author: Arpetii N.
Description: "directioncontrol.h"
-------------------------------------------------------------*/
#include <avr/io.h>
#ifndef directionControl
#define directionControl
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#ifndef in1
//out1
#define in1 PD2
#endif
#ifndef in2
//out2
#define in2 PD3
#endif
#ifndef
#define
#endif

in3
in3 PD6

#ifndef
#define
#endif

in4
in4 PD7

//out3

//out4

//#define wiat1 _delay_ms(100);


//#define wait2 _delay_ms(15);
//values for counting how many button presses was
char count[8]={};
void decodData(unsigned char);
void wrongDestinationInit(void);
void wrongDestination(void);
void timer1Init(void);
void goBackAndRight();
void goBack(void);
void goBackAndLeft(void);
void goStrictLeft(void);
void stop(void);
void goStrictRight(void);
void goAheadAndLeft(void);
void goStrightAhead(void);
void goAheadAndRight(void);
void USART_InterruptProcces(void);
unsigned int step = 102;
#endif

// directionControl.c
#include <avr\io.h>
#include "directionControl.h"
void USART_InterruptProcces(void){
unsigned char receive = 0 ;
receive = ReceiveUart();
TransmitUART(receive);
decodData(receive);
}
void timer1Init(){
TCCR1A |= ( 1 << COM1A1 ) | ( 1 << COM1B1 ) | ( 1 << WGM11 ) | (
1 << WGM10 ) ;
//Clear OC1A/OC1B on compare match, set
OC1A / OC1B at TOP
//Fast PWM, 10-bit
TCCR1B |= ( 1 << WGM12 ) | ( 1 << CS10 ) ; //no prescaling
OCR1A = 0 ;
OCR1B = 0 ;
}
void decodData(unsigned char UDR_data){
switch(UDR_data){
case 0x31 ://go back and to the left 1
goBackAndRight();
break;
case 0x32 ://go back 2
goBack();
break;
case 0x33 ://go back and to the right 3
goBackAndLeft();
break;
case 0x34 ://go strict to the left 4
goStrictLeft();
break;
case 0x35 ://don't move 5
stop();
break;
case 0x36 ://go strict to the right 6
goStrictRight();
break;
case 0x37 ://go ahead and to the left 7
goAheadAndLeft();
break;
case 0x38 : //go straight ahead 8
goStrightAhead();
break;
case 0x39 ://go ahead and to the right 9
goAheadAndRight();
break;
default://do not nothing namely dont move
// wrongDestinationInit();
break;
}
}
void goAheadAndRight(void){//9
if(count[0] == 0 ){

resetOCRnAndCounter();
PORTD = ( 1 << PD2 )|( 0 << PD3 ) | ( 0 <<PD6 )|( 0 <<
PD7 ) ;//0b00000100;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
count[0] = 5 ;
}else {
PORTD = ( 1 << PD2 )|( 0 << PD3 ) | ( 0 <<PD6 )|( 0 <<
PD7 ) ;//0b00000100;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
if (step > 1024)
step = 1024 ;
}
}
void goStrightAhead(void){//8
if(count[1] == 0 ){
resetOCRnAndCounter();
PORTD = ( 1 << PD2 )|(
PD7 ) ;//0b01000100
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
count[1] = 5 ;
} else{
PORTD = ( 1 << PD2 )|(
PD7 ) ;//0b01000100
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
if (step > 1024)
step = 1024 ;
}
}
void goAheadAndLeft(void){//7
if(count[2] == 0 ){
resetOCRnAndCounter();
PORTD = ( 0 << PD2 )|(
PD7 ) ;//0b01000000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
count[2] = 5 ;
}else{
PORTD = ( 0 << PD2 )|(
PD7 ) ;//0b01000000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
if (step > 1024)
step = 1024 ;
}
}
void goStrictRight(void){//4
if( count[3] == 0 ){
resetOCRnAndCounter();

0 << PD3 ) | ( 1 <<PD6 )|( 0 <<

0 << PD3 ) | ( 1 <<PD6 )|( 0 <<

0 << PD3 ) | ( 1 <<PD6 )|( 0 <<

0 << PD3 ) | ( 1 <<PD6 )|( 0 <<

PORTD = ( 0 << PD2 )|( 1 << PD3 ) | ( 0 <<PD6 )|( 1 <<


PD7 ) ;//0b10001000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
count[3] = 5 ;
}else{
PORTD = ( 0 << PD2 )|( 1 << PD3 ) | ( 0 <<PD6 )|( 1 <<
PD7 ) ;//0b10001000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
if (step > 1024)
step = 1024 ;
}
}
void stop(void){//5
PORTD = ( 0 << PD2 )|( 0 << PD3 )
;//0b000000000;//
resetOCRnAndCounter();
}
void goStrictLeft(void){//6
if(count[4] == 0){
resetOCRnAndCounter();
PORTD = ( 1 << PD2 )|( 0 <<
PD7 ) ;//0b10000100;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
count[4] = 5 ;
}else{
PORTD = ( 1 << PD2 )|( 0 <<
PD7 ) ;//0b10000100;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
if (step > 1024)
step = 1024 ;
}
}
void goBackAndLeft(void){//1
if(count[5] == 0){
resetOCRnAndCounter();
PORTD = ( 0 << PD2 )|( 1 <<
PD7 ) ;//0b00001000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
count[5] = 5 ;
}else{
PORTD = ( 0 << PD2 )|( 1 <<
PD7 ) ;//0b00001000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
if (step > 1024)
step = 1024 ;
}
}

| ( 0 <<PD6 )|( 0 << PD7 )

PD3 ) | ( 0 <<PD6 )|( 1 <<

PD3 ) | ( 0 <<PD6 )|( 1 <<

PD3 ) | ( 0 <<PD6 )|( 0 <<

PD3 ) | ( 0 <<PD6 )|( 0 <<

void goBack(void){//2
if(count[6] == 0){
resetOCRnAndCounter();
PORTD = ( 0 << PD2 )|( 1 << PD3 ) | ( 0 <<PD6 )|( 1 <<
PD7 ) ;//0b10001000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
count[6] = 5 ;
} else{
PORTD = ( 0 << PD2 )|( 1 << PD3 ) | ( 0 <<PD6 )|( 1 <<
PD7 ) ;//0b10001000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
if (step > 1024)
step = 1024 ;
}
}
void goBackAndRight(void){//3
if(count[7] == 0){
resetOCRnAndCounter();
PORTD =( 0 << PD2 )|( 0 << PD3 ) | ( 0 <<PD6 )|( 1 << PD7
) ;//0b10000000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
count[7] = 5 ;
}else{
PORTD =( 0 << PD2 )|( 0 << PD3 ) | ( 0 <<PD6 )|( 1 << PD7
) ;//0b10000000;//
OCR1A = OCR1A + step ;
OCR1B = OCR1B + step ;
step += 102 ;
if (step > 1024)
step = 1024 ;
}
}
void resetOCRnAndCounter(void){
OCR1A = 0 ;
OCR1B = 0 ;
for(char i = 0 ; i < 8 ; i ++ )count[i] = 0 ; }

//UART.h
/*------------------------------------------------------------------File Name: UART.h
Created: 25.04.2014
Modified: 26.04.2014
Author: Arpetii N.
Description: "UART.h"
--------------------------------------------------------------------*/
#include <avr/io.h>
#include <math.h>
#ifndef UARTInit
#define UARTInit
#define EVEN 0 //bits for parity set
#define ODD 1
#define TRUE 1
#define FALSE 0
#define NONE 2
#define null 5
#define SET
1
#define EIGHT_MHZ
51
#define ONE_MHZ
6
#define FOUR_MHZ
25
#ifndef F_CPU
#define F_CPU 8000000UL
#endif
#endif

//USART.c
#include <avr\io.h>
#include "UARTInit.h"
unsigned char ReceiveUart(void){
while (! (UCSRA & (1 << RXC)) );
return UDR;
//TransmitUART(0x78);
}
/*
this functoin transmit data to UART
*
*/
void TransmitUART( unsigned char data ){
while (! (UCSRA & (1 << UDRE)) );
//Get that data outa here!
UDR = data;
}
/*
*with this function we can transmit a hole string
*
*/
unsigned char * ReceiveUartString(){
unsigned char string [50] , x , i = 0 ;
while (x!='\n'){
x = ReceiveUart( );
string [i+1] = x;
string [i] = '0';
return ( string );
}
}
//void UART_Initialize(char frequency , int baud , char
AsynchDoubleSpeed , char DataBitSize , char ParityEVENorODD , char
StopBits , char InterruptEnable)
void UART_Initialize(char frequency
, char InterruptEnable){
if(InterruptEnable == SET ) UCSRB |= ( 1 << RXCIE ) | ( 1 <<
; //Interrupt Enable
//Put the upper part of the baud number here (bits 8 to 11)
UBRRH = 0;//(unsigned char) (UBBRValue >> 8);

TXCIE )

//baud rate 9600


//Put the remaining part of the baud number here
UBRRL = frequency;//(unsigned char) UBBRValue;
//Enable the receiver and transmitter
//RXCIE: RX Complete Interrupt Enable
UCSRB |= (1 << RXEN) | (1 << TXEN);//
(1 << RXCIE )|(1 << RXEN) |
(1 << TXEN);
/*
URSEL - It is read as one when reading UCSRC.
USBS - one stop bit
UCSZ1 & UCSB0 8-bit character size
*/
UCSRC = (1<<URSEL)|(1<<USBS)|(1<< UCSZ1)|(1<<
UCSZ0);//0x8E;//10001110
}

Concluzie:
n aceast lucrare de laborator am ndeplinit sarcina care a fost pus, am realizat un sistem care poate
dirija 2 motoare DC, prin Virtual Terminal cu ajutorul tastelor controlam direcia motoarelor i turaia
lor, am folosit driver-ul de putere L293D care este comandat de la procesor printr-o combinaie binar
schimbnd direcia lor.

Bibliografie:
1. Conspectul de baz.
2. www.mcu-labs.com.

S-ar putea să vă placă și

  • S85 Manual
    S85 Manual
    Document7 pagini
    S85 Manual
    Nicolae Arpentii
    Încă nu există evaluări
  • Prelucrarea Semnalelor
    Prelucrarea Semnalelor
    Document7 pagini
    Prelucrarea Semnalelor
    Nicolae Arpentii
    Încă nu există evaluări
  • Optima CT520: Manual Tehnic de Referinţă
    Optima CT520: Manual Tehnic de Referinţă
    Document312 pagini
    Optima CT520: Manual Tehnic de Referinţă
    Nicolae Arpentii
    100% (1)
  • Oximetru
    Oximetru
    Document39 pagini
    Oximetru
    Nicolae Arpentii
    Încă nu există evaluări
  • Moldova IPath User Manual - Mo
    Moldova IPath User Manual - Mo
    Document8 pagini
    Moldova IPath User Manual - Mo
    Nicolae Arpentii
    Încă nu există evaluări
  • Lab 3
    Lab 3
    Document6 pagini
    Lab 3
    Nicolae Arpentii
    Încă nu există evaluări
  • Lucrare NR - 1 Varianta 2
    Lucrare NR - 1 Varianta 2
    Document19 pagini
    Lucrare NR - 1 Varianta 2
    Nicolae Arpentii
    Încă nu există evaluări
  • Lucrare NR - 3 Varianta 2
    Lucrare NR - 3 Varianta 2
    Document17 pagini
    Lucrare NR - 3 Varianta 2
    Nicolae Arpentii
    Încă nu există evaluări
  • Atestare IMTRI
    Atestare IMTRI
    Document5 pagini
    Atestare IMTRI
    Nicolae Arpentii
    Încă nu există evaluări
  • Lab 2
    Lab 2
    Document22 pagini
    Lab 2
    Nicolae Arpentii
    Încă nu există evaluări
  • Lab 6
    Lab 6
    Document10 pagini
    Lab 6
    Nicolae Arpentii
    Încă nu există evaluări
  • MSB Samara
    MSB Samara
    Document12 pagini
    MSB Samara
    Nicolae Arpentii
    Încă nu există evaluări
  • Laboratorul Nr.2
    Laboratorul Nr.2
    Document9 pagini
    Laboratorul Nr.2
    Ion Virlan
    Încă nu există evaluări
  • Lab 2
    Lab 2
    Document8 pagini
    Lab 2
    Nicolae Arpentii
    Încă nu există evaluări
  • Lab 1
    Lab 1
    Document12 pagini
    Lab 1
    Nicolae Arpentii
    Încă nu există evaluări
  • Lab 1
    Lab 1
    Document5 pagini
    Lab 1
    Nicolae Arpentii
    Încă nu există evaluări
  • Laboratorul 1
    Laboratorul 1
    Document4 pagini
    Laboratorul 1
    Nicolae Arpentii
    Încă nu există evaluări
  • Lab5 MP Cuhai D
    Lab5 MP Cuhai D
    Document9 pagini
    Lab5 MP Cuhai D
    Nicolae Arpentii
    Încă nu există evaluări