Challenge

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.

Deliverables of this project:

  • 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.

Expected Outcomes:

  • 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.

CODE:

/*
 * Project 1.c
 *
 * Created: 23-03-2023 19:21:23
 * Author : asus
 */ 

#include <avr/io.h>
#define F_CPU 16000000L
#include<util/delay.h>
#include "avr/interrupt.h"
#define lcdport PORTB
#define rs_high PORTD|=(1<<0);
#define rs_low PORTD&=~(1<<0);
#define en_high PORTD|=(1<<1);
#define en_low PORTD&=~(1<<1);
int a;
void lcd_command(unsigned char cmd);
void lcd_data(unsigned char data);
void lcd_init();
void cursorpos(char x, char y);
void lcd_print(char row, char column, unsigned int value, int digits);
void lcd_out(char x, char y, char *str);
int adc_read(char channel);


int main(void)
{
	
	DDRB =0xff;
	DDRD |=(1<<5);
	DDRC |=(1<<0);
	DDRC |=(1<<1);
	sei();
	GICR=(1<<7)|(1<<6);
	PORTD=(1<<2)|(1<<3);
	lcd_init();
	TCCR1A=0x81;
	TCCR1B=0x01;
	TCNT1L=0;
	TCNT1H=0;
	while(1)
	{
		
		if(a==1)
		{
			lcd_out(1,1,"Motor Clockwise");
		}
		else
		{
			lcd_out(1,1,"Motor AntiClockwise");
		}
	}
}
ISR(INT0_vect)
{
	PORTC|=(1<<0);
	PORTC&=~(1<<1);
	a=1;
	lcd_cmd(0x01);_delay_ms(5);
	
}
ISR(INT1_vect)
{
	
	PORTC|=(1<<1);
	PORTC&=~(1<<0);
	a=2;
	lcd_cmd(0x01);_delay_ms(5);
}
void lcd_cmd(unsigned char cmd)
{
	lcdport= cmd;
	rs_low;
	en_low;
	_delay_ms(1);
	en_high;
}
void lcd_data(unsigned char data)
{
	lcdport=data;
	rs_high;
	en_low;
	_delay_ms(1);
	en_high;
}
void lcd_init()
{
	
	lcd_cmd(0x38);_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);
	lcd_cmd(0xC0);_delay_ms(5);
	
	
}
void cursorpos(char x, char y)
{
	if((x<1||x>2)||(y<1||y>16))
	{
		x=1;
		y=1;
	}
	if(x==1)
	lcd_cmd(0x7F+y);
	else
	lcd_cmd(0xbf+y);
}
void lcd_out(char x, char y, char *str)
{
	cursorpos(x,y);
	while(*str)
	{
		
		lcd_data(*str);
		str++;
	}
}

OUTPUT:

Clock wise:

Anticlock wise:

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.