You are on page 1of 5

# Requirements:

1.
AT89S52 microcontroller
2.
3.

Preset (10K)

4.
5.

## 555 timer (with apt. resistor and capacitor values)

7805 IC

6.
7.

L293D IC
DC motor

This project involves a combination of PWM (pulse width modulation) and ADC (Analog-Digital
converter) to drive a DC motor at various speeds and in both clock and anti directions. PWM is a
concept with which one can modify the pulse voltage varying it from 0% duty cycle to 100%. Duty cycle
represents the time for which pulse is high when compared to the full pulse length.
For eg:
This image below represents various percentage of duty cycles for a 4ms wave

This means for a 25% one, youll we get 25% of the input voltage and the criterion is same for
the rest of them. Now in the coding part I have made the changes in the duty cycle in accordance with
the digital output I get from the ADC. The ADC is connected to my microcontroller at PORT1. The preset
which I have used here to send the analog input can be replaced by a joystick with inbuilt preset to
make it more realistic and interesting to operate.
Now talking about the ADC, its an 8 bit analog to digital converter which means it converts all the
analog values to 8 bit digital data i.e. (0-255). The ADC requires a reference voltage according to which
it will generate digital values for changes in analog values. The resolution or step-up voltage is
19.531mV. This means that for every 19.531Mv rise in the analog input ADC will increase the digital
value by 1 starting from 0 and ending at 255.
The resolution depends upon the reference voltage as well as the type of ADC youre using. Here the
reference voltage is 5v while Im working on an 8 bit ADC therefore:
Resolution

## = 5(Reference voltage)/256(due to 8 bit i.e. 2^8=256) = 19.531mV

ADC also requires a clock frequency to work on. I have given it a 640 KHz using a 555 timer IC in astable mode.

## L293D is connected to microcontroller via pin P2^1 and P2^6

CIRCUIT DIAGRAM

SOURCE CODE
#include<reg51.h>
#include<delay.h>
sbit R=P3^0;
sbit WD=P3^1;
sbit INT=P3^2;
sbit n=P2^1;

sbit p=P2^6;
{
int temp;
R=1;
WD=0;
WD=1;
while(INT==1);
R=1;
R=0;
temp=P1;
return temp;
}
void main()
{
unsigned char value=128;
INT=1;
P1=0xff;
while(1)
{
if(value>125 && value<130)
{n=0;p=0;}
else if(value<=125)
{
n=0;p=1;
delay_msec(6-(value/25));
n=0;p=0;
delay_msec(value/25);
}
else if(value>=130)
{
value=255-value;
n=1;p=0;
delay_msec(6-(value/25));
n=0;p=0;
delay_msec(value/25);
}