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 :-
/*
* DC Motor.c
*
* Created: 24-12-2022 14:23:28
* Author : Pankaj
*/
#define F_CPU 1600000000L
#define sw (PINB&(1<<0))
#include <avr/io.h>
#include <avr/interrupt.h>
#include<util/delay.h>
unsigned char i;
int main(void)
{
DDRB&=~(1<<0); // PB0 input pin for direction control
PORTB |=(1<<0); // Active pull up
DDRC=0xFF; // Define PORTC As an Output port
i=30;
OCR0=i; // for 25% duty cycle in non inverted phase correct PWM
TCCR0=0x64; // Phase correct PWM ,Non inverted 310372Khz, 16Mhz crystal, so N=1
DDRB |=(1<<PB3); // Make PB3o/p
DDRD &=~(1<<PD2); // Make PD2 an i/p pin (INT0 pin )
PORTD|=(1<<PD2); // Activate pull up
GICR=(1<<INT0); // Enable external interrupt0
MCUCR =0x02; // Make interrrupt0 Negative edge triggered
sei(); // enable interrupts
while (1)
{
if(sw==0)
PORTC=0x01; // 0000 0001
else
PORTC=0x02; // 0000 0010
OCR0=i;
}
return 0;
}
ISR (INT0_VECT)
{
i=i+10;
}
ISR (INT2_VECT)
{
i=i+10;
}
Microchip Studio Code

Motor in CLOCKWISE DIRECTION AT 25 % DUTY CYCLE

Motor in ANTICLOCKWISE DIRECTION AT25 % DUTY CYCLE
