Project 1 - Controlling a DC motor using PWM and monitoring its Running status
Overview of the Project:
Implement a system on the simulator for controlling a DC motor using L293 motor driver, monitor its status and print the running status of motor on the LCD Display.
Goals:
Implement a system on simulator for Controlling the DC motor using L293 motor driver.Displaying the running status of DC motor on the LCD display.
Key Highlights of the Project:
The DC motor can be controlled by using L293 motor driver.The speed of a DC motor can be controlled by varying its input voltage, for doing this is to use PWM (Pulse Width Modulation).
L293D IC is a typical Motor Driver IC which allows the DC motor to drive on any direction.
Expected Outcomes:
Implement a system on simulator to control a DC motor using PMWM.onitoring the running status of the DC motor using L293 motor driver which allows the DC motor to drive on any direction.Running status i.e. on which direction the DC motor is running is to be displayed on the LCD screen.
DC motor:
A DC motor is defined as a class of electrical motors that convert direct current electrical energy into mechanical energy.
LCD display:
LCD (Liquid Crystal Display) is a type of flat panel display which uses liquid crystals in its primary form of operation.
CODE:
#include
#define F_CPU 16000000ul
#include “avr/interrupt.h”
#include
#define sw_dir (PIND&(1<<1>
#define sw_dspd (PIND&(1<<2>
#define pw (PINC&(1<<3>
#define lcd_port PORTB
#define RS_high PORTD|=(1<<5>
#define RS_low PORTD&=~(1<<5>
#define EN_high PORTD|=(1<<6>
#define EN_low PORTD&=~(1<<6>
unsigned char i;
void lcd_cmd(char cmd) {
lcd_port=(cmd&0xf0);
RS_low;
EN_low;
_delay_ms(1);
EN_high;
lcd_port=((cmd<<4>
RS_low;
EN_low;
_delay_ms(1);
EN_high;
}
void lcd_data(char data)
{
lcd_port=(data &0xf0);
RS_high;
EN_low;
_delay_ms(1);
EN_high;
lcd_port=((data<<4>
RS_high;
EN_low;
_delay_ms(1);
EN_high;
}
void lcd_init()
{
lcd_cmd(0x28);
_delay_ms(5);
lcd_cmd(0x02);
_delay_ms(5);
lcd_cmd(0x01);
_delay_ms(5);
lcd_cmd(0x0C);
_delay_ms(5);
lcd_cmd(0x06);
_delay_ms(5);
lcd_cmd(0x80);
_delay_ms(5);
}
void cursorpos(char x, char y)
{
if ((x<1>2)||(y>16)||(y<1>
{
x=1; //x=rows
y=1; //y=columns
}
if (x==1)
{
lcd_cmd(0x7F+y);
}
else //(x=2)
{
lcd_cmd(0xBF+y);
}
}
void lcd_out(char x, char y, char *str)
{
cursorpos(x,y);
while (*str)
{
lcd_data(*str);
str++;
}
}
int adc_read(char channel)
{
unsigned int a, result;
ADMUX=channel;
ADCSRA=0X80;
ADCH=0x00;
ADCL=0x00;
ADCSRA|=(1<<6>
while((ADCSRA&0x40)!=0);
a=ADCL;
result=ADCH;
result=result<<8>
result=result|a;
return result;
}
int main(void)
{
DDRB=0xFF;
DDRA|=((1<<0>
DDRD&=~(1<<1>
DDRD|=(1<<5>
DDRD|=(1<<6>
DDRC&=~(1<<3>
PORTD|=(1<<2>
PORTC|=(1<<3>
i=64;
TCCR0=0X61;
GICR=(1< MCUCR=0X02; sei(); lcd_init(); while (1) { while(pw==0) { if (sw_dir==0) { PORTA=0b00000001; lcd_out(1,1,”Motor ON-CLW”); } else { PORTA=0b00000010; lcd_out(1,1,”Motor ON-ACL”); } OCR0=i; } PORTA=0X00; lcd_out(1,1,”Motor is_OFF”); } } ISR(INT0_vect) { i=i+20; } SIMULATION : Power Switch: OFF, Direction Switch: OFF, Speed Switch: OFF :: Motor is TURN OFF Condition Power Switch: ON, Direction Switch: OFF, Speed Switch: OFF :: Motor is TURN ON Condition Power Switch: ON, Direction Switch: ON, Speed Switch: OFF :: Motor is TURN ON and Direction of Rotation: REVERSE Power Switch: ON, Direction Switch: OFF, Speed Switch: ON :: Motor is TURN ON and Speed of Motor: INCREASED Expected Outcomes: