Challenge

Project 1 - Controlling a DC motor using PWM and monitoring its Running status

TSE-ABINAYA INBAMANI  batch 15

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.

/*
 * Project_1.c
 *
 * Created: 24-02-2023 22:50:36
 * Author : vimal
 */ 

#include      // we are using I/P register of Avr
#define F_CPU 16000000ul  // define cpu frequency
#include "avr/interrupt.h" // we are using external interrupt pin
#include  //delay funtion
#define sw_dir (PIND&(1<<1)) //d1 pin is declared as push button for direction control
#define sw_spd (PIND&(1<<2)) //d2 pin is declared as push button for speed control
#define pw (PIND&(1<<3))  //c3 declared push button for power ON/OFF
#define lcd_port PORTB  //Portb pins are dedicated for lcd data
#define RS_high PORTD|=(1<<5) //d5 pin used forRS
#define RS_low PORTD&=~(1<<5) 
#define EN_high PORTD|=(1<<6) //d6 pin used for EN
#define EN_low PORTD&=~(1<<6) 
unsigned char i;   // variable declared to increase the duty cycle in PWM.

void lcd_cmd(char cmd)
{
	lcd_port=(cmd&0xf0); //4 bit for LCD mode
	RS_low;
	EN_low;
	_delay_ms(1);
	EN_high;
	lcd_port=((cmd<<4)&(0xf0));
	RS_low;
	EN_low;
    _delay_ms(1);
	EN_high;
	
}

void lcd_data(char data)
{
	
	lcd_port =(data&0xf0);  //4 bit LCD mode
	RS_high;
	EN_low;
	_delay_ms(1);
	EN_high;
	lcd_port =((data<<4)&(0xf0));
	RS_high;
	EN_low;
	_delay_ms(1);
	EN_high;
}

void lcd_init()
{
	lcd_cmd(0x02);_delay_ms(5); // return cursor to home
	lcd_cmd(0x01);_delay_ms(5); // clear screen
	lcd_cmd(0x0C);_delay_ms(5); //display ON  cursor OFF
	lcd_cmd(0x06);_delay_ms(5); //increment cursor
	lcd_cmd(0x80);_delay_ms(5); //force cursor to begin 1st line
	lcd_cmd(0x28);_delay_ms(5); //used for 4 bit lcd mode
}

void lcd_out(char X,char Y,char *str)
{
	cursorpos(X,Y);
	while(*str)
	{
		lcd_data(*str);
		str++;
	}
}

void cursorpos(char x, char y)
{
	if ((x<1||x>2)||(y>16||y<1))
	{
		x=1;
		y=1;
	} 
	if (x==1)
	{
		lcd_cmd(0x7f+y);
	}
	else
	{
		lcd_cmd(0xBF+y);
	}
}

int main(void)
{
	DDRB=0XFF;  // declaring all B pins as output
	DDRA|=((1<<0)|(1<<1)); // A0-A1 pins as output
	DDRD&=~(1<<1); //D1 Pin input
	DDRD&=~(1<<2); //D2 pin input
	DDRD|=(1<<5); //D5 Pin output
	DDRD|=(1<<6); //D6 pin output
	DDRC&=~(1<<3); //C3 pin input
	PORTD|=(1<<2); //enabling internal pull up resistor for D2
	PORTD|=(1<<3); //enabling internal pull up resistor for D3
	i=64;  // initializing i= 64 baz we are running the motor with 25% duty cycle
	TCCR0=0X61; // NON INVERTING MODE,PWM PHASE CORRECT MODE, NO PRESCALARS
	GICR=(1<
  • 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.
  • 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).
    • Implement the system for controlling DC motor.
    • Controlling the speed of the DC motor using PMW.
    • Displaying the present running status of DC machine on LCD display.L293D IC is a typical Motor Driver IC which allows the DC motor to drive on any direction.
    • Implement a system on simulator to control a DC motor using PMW
    • Monitoring 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.

OUTPUTS:

hardware to be selected AT mega32, 2*16 LCD(HD44780),DC  motor(12V),10k resistor,L293 motor driver, voltage source and push buttons.

in simulation we dont need to given motor supply current and the driver supply into driver pins as we do in hardware implementation.

L293 Motor driver circuit:

1A & 2A: these terminal decide direction of rotation of motor.

1,0 these pin respectively drive the motor in clock direction . 

0,1 responsible for anticlockwise rotation.

11,00 has not turing effect.

1y,2y terminaks are to be connected to the termuinals ofdc motor.

EN-enable pins are also used to control the speed of dc motor. if you apply PWM signal to these enables pins then the motor driver IC L293D can contol the speed of both motors.

C3 Pussh button of ON/OFF.In the switch is off Motor is OFF CAUTION showing on display.

C3 push button on motor is running clockwise direction.

 C3 & D1 push button on Motor is running anti clockwise . 5v passing this line

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.