Sie sind auf Seite 1von 8

Interfacing D.C.

Motor with ATmega32 using L293D


Components Required

ATmega32 microcontroller

AVR Programmer Board

Crystal

Capacitors

Motors

L293D IC

+5V supply

Battery equivalent to voltage rating of motor

Breadboard

Connecting Wires

Motor Controller

L293D - Dual D.C. Motor Controller

Enable-1 controls the output of output1 and output2.

Enable-2 controls the output of output3 and output4.

Vss is connected to +5V.

Vs is connected to a voltage equal to the voltage rating of the motor.

Enable 1-2 and Input 1-4 comes from the microcontroller.

If speed control using PWM is not needed, the Enable Pins can be directly connected
to +5V.

All 4 grounds are shorted to a common ground.

Output 1-4 goes to the motor.

Circuit Diagram

Description

PC0 and PC3 are connected to Enable 1 and Enable 2 respectively.

PC1,PC2,PC4 and PC5 are connected to Input 1-4.

OUT1 and OUT2 are connected to the terminals of first motor and OUT3 and OUT4
are connected to the terminals of the second motor.
A crystal is connected to XTAL1 and XTAL2 pins to provide the clock pulse.
Reset is connected to +5V.

Source Code
/*The following code will make the motor to run forward for 2 seconds
and then backward for 2 seconds for infinite time*/
#include <avr/io.h>
#include <util/delay.h>
#define F_CPU 1000000UL
int main()
{
DDRC = 0xFF;
// PORTC as output port
PORTC = 0x00;
//Initially all pins as output low
PORTC|=(1<<PC0)|(1<<PC3);
//C0 and C3 are connected to enable
while (1)
// Infinite Loop
{
/*Forward Motion*/
PORTC|=(1<<PC1)|(1<<PC4);
//#1

PORTC&=~((1<<PC2)|(1<<PC5));
//#2
_delay_ms(2000);
//#3
/*Backward Motion*/
PORTC&=~((1<<PC1)|(1<<PC4));
//#4
PORTC|=(1<<PC2)|(1<<PC5);
//#5
_delay_ms(2000);
//#6
}
return 0;
}
# 1 . PORTC|=(1<<PC1)|(1<<PC4);
1<<PC1 will generate a character 00000010 and 1<<PC4 will genarate a character
00010000.
Taking OR of this values will generate 00010010. Now OR of this value and the initial
condition of
PORTC will make the Bits 1 and 4 as high independent of all other pins
of PORTC.
# 2 . PORTC&=~((1<<PC2)|(1<<PC5));
1<<PC2 will generate a character 00000100 and 1<<PC5 will genarate a character
00100000.
Taking OR of this values will generate 00100100 and NOT of this value will generate
11011011.
Now AND of this value and the initial condition of PORTC will make the
Bits 2 and 5 as low
independent of all other pins of PORTC.
# 3. _delay_ms(2000);
A delay of 2 seconds after which the motor will change its direction.
# 4 . PORTC&=~((1<<PC1)|(1<<PC4));
1<<PC1 will generate a character 00000010 and 1<<PC4 will genarate a character
00010000.
Taking OR of this values will generate 00010010 and NOT of this value will generate
11101101.
Now AND of this value and the initial condition of PORTC will make the
Bits 1 and 4 as low
independent of all other pins of PORTC.
# 5 . PORTC|=(1<<PC2)|(1<<PC5);
1<<PC2 will generate a character 00000100 and 1<<PC5 will genarate a character
00100000.
Taking OR of this values will generate 00100100. Now OR of this value and the initial
condition of
PORTC will make the Bits 2 and 5 as high independent of all other pins
of PORTC.

# 6. _delay_ms(2000);
A delay of 2 seconds after which the motor will change its direction.

Source Code for Normal Run of DC motor


#include <avr/io.h>
#define F_CPU 1000000UL
int main()
{
DDRC = 0xFF;
PORTC = 0x00;
PORTC|=(1<<PC0)|(1<<PC3);
//C0 and C3 are connected to enable
PORTC|=(1<<PC1)|(1<<PC4);
//C1 and C4 as output high
PORTC&=~((1<<PC2)|(1<<PC5));
//C2 and C5 as output low
while(1)
// Infinite Loop
;
return 0;
}
ThankYou for Reading.

Interfacing Motor DC dengan ATmega32 menggunakan


L293D
Komponen Diperlukan

Mikrokontroler ATmega32

AVR Programmer board

Kristal

Kapasitor

Motor

L293D IC

+ 5V supply

Baterai setara dengan rating tegangan motor

Papan breadboard

Menghubungkan Kabel

Motor Pengendali

L293D - Ganda Motor DC Kontroler

Enable- 1 kontrol output dari output1 dan output2.

Aktifkan-2 mengontrol output dari output3 dan output4.

VSS terhubung ke + 5V.

Vs terhubung ke tegangan sama dengan tegangan rating dari motor.

Aktifkan 1-2 dan 1-4 Masukan berasal dari mikrokontroler.

Jika kontrol kecepatan menggunakan PWM tidak diperlukan, Aktifkan Pins dapat
langsung terhubung ke + 5V.

Semua 4 alasan korsleting untuk kesamaan.

Output 1-4 pergi ke motor.

Circuit Diagram

Deskripsi

PC0 dan PC3 terhubung ke Enable 1 dan 2 masing-masing Aktifkan.

PC1, PC2, PC4 dan PC5 terhubung ke input 1-4.

OUT1 dan OUT2 dihubungkan ke terminal motor pertama dan OUT3 dan OUT4
yang terhubung ke terminal motor kedua.
Sebuah kristal terhubung ke XTAL1 dan XTAL2 pin untuk memberikan pulsa clock.
Reset terhubung ke + 5V.

Kode sumber
/ * Kode berikut akan membuat motor untuk berjalan ke depan selama 2 detik
dan kemudian mundur selama 2 detik untuk waktu yang tak terbatas * /
#include <avr / io.h>
#include <util / delay.h>
#define F_CPU 1000000UL
int main ()
{
DDRC = 0xFF; // PORTC sebagai port output
PORTC = 0x00; // Awalnya semua pin sebagai output yang rendah
PORTC | = (1 << PC0) | (1 << PC3); // C0 dan C3 terhubung untuk mengaktifkan
while (1) // Infinite Loop
{
/ * Teruskan Gerak * /
PORTC | = (1 << PC1) | (1 << PC4); // # 1
PORTC & = ~ ((1 << PC2) | (1 << PC5)); // # 2
_delay_ms (2000); // # 3
/ * Gerak Mundur * /

PORTC & = ~ ((1 << PC1) | (1 << PC4)); // # 4


PORTC | = (1 << PC2) | (1 << PC5); // # 5
_delay_ms (2000); // # 6
}
return 0;
}
# 1. PORTC | = (1 << PC1) | (1 << PC4);
1 << PC1 akan menghasilkan karakter 00.000.010 dan 1 << PC4 akan genarate karakter
00.010.000.
Mengambil OR nilai ini akan menghasilkan 00010010. Sekarang OR dari nilai ini dan
kondisi awal dari PORTC akan membuat Bits 1 dan 4 independen tinggi dari semua pin
lainnya dari PORTC.
# 2. PORTC & = ~ ((1 << PC2) | (1 << PC5));
1 << PC2 akan menghasilkan karakter 00.000.100 dan 1 << PC5 akan genarate karakter
00.100.000.
Mengambil OR nilai ini akan menghasilkan 00100100 dan tidak dari nilai ini akan
menghasilkan 11011011. Sekarang DAN nilai ini dan kondisi awal dari PORTC akan
membuat Bits 2 dan 5 independen rendah semua pin lainnya dari PORTC.
# 3. _delay_ms (2000);
Penundaan dari 2 detik setelah motor akan mengubah arah.
. # 4 PORTC & = ~ ((1 << PC1) | (1 << PC4));
1 << PC1 akan menghasilkan karakter 00.000.010 dan 1 << PC4 akan genarate karakter
00.010.000.
Mengambil OR nilai ini akan menghasilkan 00010010 dan tidak dari nilai ini akan
menghasilkan 11101101. Sekarang DAN nilai ini dan kondisi awal dari PORTC akan
membuat Bits 1 dan 4 independen rendah semua pin lainnya dari PORTC.
. # 5 PORTC | = (1 << PC2) | (1 << PC5);
1 << PC2 akan menghasilkan karakter 00.000.100 dan 1 << PC5 akan genarate karakter
00.100.000.
Mengambil OR nilai ini akan menghasilkan 00100100. Sekarang OR dari nilai ini dan
kondisi awal dari PORTC akan membuat Bits 2 dan 5 independen tinggi dari semua pin
lainnya dari PORTC.
# 6. _delay_ms (2000);
Penundaan dari 2 detik setelah motor akan mengubah arah.

Kode sumber untuk normal Run motor DC


#include <avr / io.h>
#define F_CPU 1000000UL
int main ()
{
DDRC = 0xFF;
PORTC = 0x00;

PORTC | = (1 << PC0) | (1 << PC3); // C0 dan C3 terhubung untuk mengaktifkan


PORTC | = (1 << PC1) | (1 << PC4); // C1 dan C4 sebagai output tinggi
PORTC & = ~ ((1 << PC2) | (1 << PC5)); // C2 dan C5 sebagai output yang rendah
sementara (1) // Infinite Loop
;
return 0;
}
Terima kasih telah membaca.

Das könnte Ihnen auch gefallen