Documente Academic
Documente Profesional
Documente Cultură
Raport
Lucrare de laborator nr. 4
la disciplina
Proiectarea Microsistemelor
Tema: Dispositive de acionare.
A efectuat:
A verificat:
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.
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.
.
Schemele bloc:
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
// 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();
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 )
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.