Challenge

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

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

AIM:

To implement the system for controlling the speed of the DC motor using PWM and Displaying the present running status of DC machine on LCD display.

Tools used:

PC with Microchip IDE, SimulIDE softwraes

Program:

/*
 * project1.c
 *
 * Created: 04-11-2022 14:33:24
 * Author : Kavitha
 */ 


#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;		//Port B as output
	DDRD |=(1<<5);	//Port D as output for PWM - enable input for L293D
	DDRC |=(1<<0);  //PORTC as output & As input pins for L293D
	DDRC |(1<<1);	//PORTC as output & As input pins for L293D
	sei();			//Enable global interrupt
	GICR=(1<<7)|(1<<6);//Enable INT0 & INT1 - for switch connections
	PORTD=(1<<2)|(1<<3);//Enable Pull up
	lcd_init();
	TCCR1A=0x81;
	TCCR1B=0x01;
	TCNT1L=0;
	TCNT1H=0;
	while(1)
	{
		if(a==1)
		{
			lcd_out(1,1,"Motor Clockwise");
			OCR1AL=0X3F;
		}
		else
		{
			OCR1AL=0X7F;
			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:

Simulation results:

Conclusion:

Thus using PWM the speed and direction control of DC motor has been implemented and also its running direction displayed in the LCD using microchip & SimulIDE software tools.

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.