Vous êtes sur la page 1sur 40

1

Microprocessor System and Embedded Software

Assignment
2

Contents:

Introduction 3

Objectives 4

Design Consideration 5

Block Diagram 13

Explanation &Innovation 14

Flow Chart 17

C Codes 18

Hardware Implementation and Results 24

Discussion 31

Conclusion 33

References 34

Appendix 35
3

Introduction:

Washing machines are the devices which are used for cleaning of the clothes without a person
rubbing, scrubbing or beating the clothes by oneself and getting dirty. Washing machines have
an important place in the modern society, without it one can’t imagine how difficult and tiresome
life would be (present days). Washing machines are used to reduce human labor and save time.
Now days we can see various kinds of washing machines, especially the fully automatic ones as
they are the front runners in sale, customers want to have fully automatic machines instead of
semi-automatics.

We build a simple washing machine spin timer using microcontroller (PIC 16f877a).
Microcontrollers and microprocessors are used to control various electronic devices such as
cellular phones, laptops, monitoring systems, controlling systems etc. Microcontrollers and
microprocessors are used to perform repetitive operations exactly the same way time after time.
They are cheap to produce and all their components are in the same package. They very rarely
fail in operation.

For the system created developer is using 1 PIC 16f877a, 1 DC Motor, 1 DIP Switch (8 ways),
few resistors, 3 LED’s, 2 SPDT Switches, 2 7-Segment Displays, 1 Training Kit and 1 SK40c.

The functioning of the system is fairly simple, the speed of motor is controlled according to the
time, the time is set according to the DIP switch input, the time is shown on the 7-segments
displays, the switches provided are used to control the circuit in various manners and at last there
are LED’s which act as indicators or alarms as per need in the system.

Developer used C language for coding the system using the MPLAB software, has shown the
simulation using Proteus software and has finally made a very simple prototype for presentation
purpose.
4

Objectives:

The Objects for this system can be the design consideration specified by specified by the
lecturer, which are:

1. To set the time using a DIP switch (maximum value is 99)

2. The setting values should be displayed on the seven segment display

3. The spin process should begin when the start button is pressed and then

 START the Motor (LED ON)


 The display value on the seven segments should start counting down

4. When the value is zero, STOP the motor (LED OFF)

5. Modify the spin timer by increasing or decreasing the rotational speed

Other modifications have been done or added in the system by the developer which is discussed
below.
5

Design Consideration:

For the simple washing machine spin timer system developed by the developer. He has used a
PIC 16f877a as the CPU or the brains of the system, which works on the C codes provided to it
using MPLAB software via an USB burner.

 DIP 8-ways switch is used as input, whose maximum value can be 0-255, it is used to
control the countdown timer, we have coded the PIC in such a way that count is
maximum at 99, does not go pass it

 2 7-Segment Displays are used to show the countdown as in numerically

 System starts as the Power switch is turned on and stops as its off

 System pauses as soon as Start\Pause switch is turned off and starts as its on

 When value of DIP switch is above 99, the 7-segment displays still show value of 99

 When the value of DIP switch is below 99, the 7-segment displays show whatever value
is at DIP switch

 When value on 7- segment displays is above 45 the DC Motor runs at its full speed

 When value on 7-segment displays is below 45 and above 0 DC Motor runs at half speed

 When value on 7-segment displays is equal to 00 the DC Motor stops

 A LED is connected parallel to the DC Motor as indicator


6

 A Power ON/OFF LED is used to indicate if the system is on or off

 When value on 7-segment displays goes to 00 from higher values after countdown there
is an indicator LED which indicated the spin is over and motor has stopped

 Various variations of the switches states are used to control the system in various manner
(SW1 and SW2) (00,01,10,11) (conditions)

PIC 16F877A Microcontroller:

Microcontroller is the brain of the system; all the decisions are taken by it autonomously. We are
using this particular series of PIC microcontroller because:

 It is very simple yet very powerful to use

 It can be programmed and reprogrammed numerous times

 It is small in size while have sufficient input/ output ports

 It has low current consumption

 It has onboard multichannel analog to digital convertor

 It has in- built PWM function

Below are some of the features present in the PIC 16F877A, its pin and block diagram:
7

Pin Count 40 pin - PDIP

Program Memory 14KB or 8K 14-bit Flash

Max Crystal Speed 20MHz

RAM bytes 368

EEPROM bytes 256

Timers 2 x 8 bit, 1 x 16-bit

Digital Communication 1xA/E/USART, 1 x MSSP(SPI/I2C)

Capture/ Compare/ PWM 2 x CCP

ADC 8ch, 10-bit

Comparators 2
8
9

(Register File Map)


10

DC Geared Motor (Developer would use LED while presentation as does not have DC Motor):

Developer would be using four SPG50-10K dc geared motors to provide the power to the
fan or the mixer inside Tank B.

Below are the properties of this dc geared motor:

Voltage 12V DC
Output Power 3.4 W
Rated Speed 170 RPM
Rated Current 0.9 A
Rated Torque 196 mN.m

For controlling the DC Geared motor we are using the motor driver MD10B. It is
designed to drive high current brush motor or application. It is designed for wide range of
robotics and automotive applications. The board incorporates most of the components of
the typical applications. With minimum interface, the board is ready to be plugged and
play. Simply add in power, this driver is ready to drive high current motor. It has been
designed with capabilities and features of:
11

 Industrial grade PCB with heavy copper material for high current applications
 Each component is soldered properly and tested
 Support up to 10A maximum
 5V logic level compatible inputs
 12V as Vcc
 PWM speed control up to 10KHz
 Bi-directional control for 1 motor
 Very low standby power consumption
 System ground is isolated from motor’s power source with opto-isolator
 4 Schottky diode as clamping diode
 Dimension: 6cm x 4.5cm
12

(Connection of the driver to MCU)


13

Block Diagram:
14

Explanation and Innovation:

For our system we are using 8-way DIP switch as input, which can have 0-255 states. For our
system we need 0-99 states at max. This DIP switch is needed for giving the input value for
countdown. Then we have 2 more SPDT switches, one (SW1) is required to power ON and OFF
the system, while the other one (SW2) is required to PAUSE and START the system only when
first switch is ON. The counting down of the initial value of number as assigned by DIP switch
can be seen on 2 7-Segments displays. For controlling the system we have used 1 PIC 16f877a
microcontroller, the switches (including reset switch in SK40c) are the inputs and the 2 7-
segments displays are the main output. We have one led defined as POWERLED which indicates
if SW1 is ON or OFF, then we have DC Motor which rotates only when SW1 is ON and SW2 is
START, connected to DC Motor in parallel is indicator LED and we have an ALARMLED
which indicates when countdown has finished and 7 segment displays show 00. Now developer
would explain the logic behind the system used.

Firstly user has to power on the system by toggling SW1 to ON, if SW1 is OFF system won’t
work at all. So once when SW1 is ON, the PIC checks for the input from DIP switch, if the value
on DIP switch is above 99, the program (C Language) makes it equal to 99 which is displayed on
the 7-segment displays, if there is any value on DIP which is lesser than 99 it would be shown on
7- segment displays. Now, considering SW2 is in PAUSE state, we toggle it to START, the
system starts counting down, take initial value on DIP switch is 55. When SW1 is START, the
POWERLED is ON, now when the countdown begins, if the value on 7-segments is above 45
the DC Motor will run at full speed and indicator LED would be ON (stable), when the value on
7-segments is below or equal to 45 and above 00 the DC Motor will run at lesser speed and
indicator LED would be ON (blinking), finally when value on 7-segments reaches 00 the DC
Motor will stop running and indicator LED would be OFF and suddenly ALARMLED would be
ON indicating the spin is over (outputs).

Similarly, considering the above situation if DIP switch is 55 and SW2 is START the countdown
begins which can be seen on the 7- segments. Now suddenly SW1 is OFF the POWERLED
15

would be OFF, DC Motor would stop rotating, 7-segments will display 00 and ALARMLED
would come on indicating spinning is over, whatever condition might be.

Now, if again as first the DIP switch is 55 and SW2 is START the countdown begins which can
be again seen on the 7-segments, suddenly SW2 is PAUSE, the countdown pauses then it there,
consider the value on 7-segment was 48 when SW2 was toggled to PAUSE the 7-segment would
show 48, while DC Motor would stop rotating, countdown down pauses and POWERLED still
remains ON. Again SW2 is toggled from PAUSE to START the system starts counting down
from where it left that is 48, the DC Motor starts rotating again at full speed as value on 7-
sements above 45, countdown starts and POWERLED still remains on.

This was the working of the simple washing machine timer system. For the simulation developer
has used DC Motor and 7-segments displays (Binary to HEX decoder) but in real life the
developer has used just LED’s instead as, could not get DC Motor and 7-segments displays
(Binary to HEX decoder). The developer tried to use the code of conversion of HEX to BCD and
HEX to decimal but due to less time to debug he did not use the code as code wasn’t working
properly (needed more time for trial and error).

The innovations which developer has put into the system are:
(All of which have been explained above as a whole system)

 Using ON/OFF switch separately instead of SK40c


 Using START/PAUSE switch
 POWERLED
 ALARMLED

ON/OFF switch can be used by a user to turn on or off the washing machine, START/PAUSE
can be used by user in case he wants to add more clothes to wash or wants to add more washing
powder in between of wash, POWERLED is to indicate the system is ON and the ALARMLED
helps the user to know the wash is over.
16

The innovation which developer wished to add was changing the direction of motor for a
particular interval of time repeatedly (for 1-2 wash), wished to add servo motor which could be
used to control opening of water into the system and finally use a LCD for display instead of 7-
segments in Proteus or LED’s in prototype, but as time was less these all remained just wishes
(Developer did do the task which he wished above in Mechatronics Design).
17

Flow Chart:
18

Codes (C Language):

#include <pic.h> //Header files


#include <htc.h>

#ifndef _XTAL_FREQ
#define _XTAL_FREQ 20000000 //Defining crystal frequency
#endif

//===============configuration==============================

__CONFIG (0x3F32);

//===============define IO port=============================

#define ALARM RA0 //When i==0 or goes to it then LED ON


#define POWERLED RA1 //When SW1==1 LED ON if SW1==0 then LED OFF
#define SW1 RB0 //ON & OFF switch
#define SW2 RB1 //START & PAUSE switch
#define DIP PORTC //Input for the timer or counter
#define DISPLAY PORTD //7 Segments, LCD or LED
#define DCMOTOR RE0 //Spinner

//==============FUNCTION PTOTOTYPE=========================

void delay(unsigned short n); //Assigning for Delay

//====================MAIN================================

void main()
{
TRISA=0b00000000; //All outputs
TRISB=0b11111111; //All inputs
TRISC=0b11111111; //All inputs
TRISD=0b00000000; //All outputs
TRISE=0b00000000; //All outputs
19

int i; //Declaring i as integer and i==PORTC


i=PORTC;

if(SW1==0 && SW2==0) //If OFF and PAUSE


{
POWERLED=0; //POWERLED OFF
DISPLAY=0b00000000; //7 Segments shows 00
DCMOTOR=0; //DC Motor doesn't rotate
ALARM=0; //ALARMLED OFF
}

if(SW1==0 && SW2==1) //If OFF and START


{
POWERLED=0; //POWERLED OFF
DISPLAY=0b00000000; //7 Segments shows 00
DCMOTOR=0; //DC Motor doesn't rotate
ALARM=0; //ALARMLED OFF
}

if(SW1==1 && SW2==0) //If ON and PAUSE

{
POWERLED=1; //POWERLED ON
DCMOTOR=0; // DC Motor doesn't rotate
if(i>99) //Value on DIP switch is more than 99
{
DISPLAY=0b01100011; //Display 99 on 7 segments
}
if(i<=99) //Value on DIP switch is less than or equal to 99
{
DISPLAY=i; //Display the value of which is at DIP switch
}

if(SW1==1 && SW2==1) // If ON and START


20

{
POWERLED=1; //POWERLED ON
if(i>99) //Value on DIP switch is more than 99
{
i=99; //Display 99 on 7 segments
while(i>45) //While value of i is more than 45
{
i=i--; //i=i-1 (decrementing)
DISPLAY=i; //Display value of i after decrement
delay(50000); //Delay between change of values
DCMOTOR=1; //DC Motor rotates at full speed
while(SW2==0) //While Pause
{
DISPLAY=i; //Display the value of last i on 7-segments
DCMOTOR=0; //DC Motor doesn't rotate
POWERLED=1; //POWERLED ON
if(SW1==0) //If OFF
{
break; //Come out of loop immediately
}

}
if(SW1==0) //If OFF
{
PORTD=0x00; //7 Segments shows 00
DCMOTOR=0; //DC Motor doesn't rotate
i=0; //Value of i assigned to be 00
}

while(i<=45 && i>0) //While value of i is less or equal to 45 and above 0


{
i=i--; //i=i-1 (decrementing)
DISPLAY=i; //Display value of i after decrement
delay(50000); //Delay between change of values
DCMOTOR=1; //DC Motor runs at full speed
21

delay(8000); //For this much interval


DCMOTOR=0; //DC Motor doesn't rotate
delay(4000); //For this much interval
while(SW2==0) //While Pause
{
DISPLAY=i; //Display the value of last i on 7-segments
DCMOTOR=0; //DC Motor doesn't rotate
POWERLED=1; //POWERLED ON
if(SW1==0) //If OFF
{
break; //Come out of loop immediately
}

}
if(SW1==0) //If OFF
{
PORTD=0x00; //7 Segments shows 00
DCMOTOR=0; //DC Motor doesn't rotate
i=0; //Value of i assigned to be 00
}
}

while(i==0) //While i==0 or becomes equal to 0


{
DISPLAY=0x00; //7 Segments shows 00
DCMOTOR=0; //DC Motor doesn't rotate
ALARM=1; //ALARMLED ON

if(i<=99) //Value on DIP switch is more than 99


{
i=i; //Value of i is same as that on DIP switch
while(i>45) //While value of i is more than 45
22

{
i=i--; //i=i-1 (decrementing)
DISPLAY=i; // Display value of i after decrement
delay(50000); //Delay between change of values
DCMOTOR=1; //DC Motor rotates at full speed
while(SW2==0) //While Pause
{
DISPLAY=i; //Display the value of last i on 7-segments
DCMOTOR=0; //DC Motor doesn't rotate
POWERLED=1; //POWERLED ON
if(SW1==0) //If OFF
{
break; //Come out of loop immediately
}
}
if(SW1==0) //If OFF
{
PORTD=0x00; //7 Segments shows 00
DCMOTOR=0; //DC Motor doesn't rotate
i=0; //Value of i assigned to be 00
}
}

while(i<=45 && i>0) //While value of i is less or equal to 45 and above 0


{
i=i--; //i=i-1 (decrementing)
DISPLAY=i; //Display value of i after decrement
delay(50000); //Delay between change of values
DCMOTOR=1; //DC Motor rotates at full speed
delay(8000); //For this much interval
DCMOTOR=0; //DC Motor doesn't rotate
delay(4000); //For this much interval
while(SW2==0) //While Pause
{
DISPLAY=i; //Display the value of last i on 7-segments
DCMOTOR=0; //DC Motor doesn't rotate
POWERLED=1; // POWERLED ON
23

if(SW1==0) // If OFF
{
break; //Come out of loop immediately
}
}
if(SW1==0) //If OFF
{
PORTD=0x00; //7 Segments shows 00
DCMOTOR=0; //DC Motor doesn't rotate
i=0; //Value of i assigned to be 00
}
}

while(i==0) //While i==0 or becomes equal to 0


{
DISPLAY=0x00; //7 Segments shows 00
DCMOTOR=0; //DC Motor doesn't rotate
ALARM=1; //ALARMLED ON
}
}
}
}
//=================delay==============================
void delay(unsigned short n) //Assigning for Delay
{
for(;n>0;n--); //For any given number, when n is still greater than 0, n=n-1
}
24

Hardware Implementations and Results:

Following are the Proteus Simulation and the hardware implementation images:

(When Circuit is played for the first time, POWERLED=0)

(When at DIP switch all 1’s and SW1=1 and SW2=0, POWERLED=1)
25

(When at DIP switch 00000011 and SW1=1 and SW2=0, POWERLED=1)

(When at DIP switch all 1’s, SW1=1 and SW2=1, DCMOTOR=1, POWERLED=1)
26

(When at DIP switch 5 - 1’s, SW1=1 and SW2=0, DCMOTOR=0, POWERLED=1)

(When at DIP switch 5 - 1’s, SW1=1 and SW2=1, DCMOTOR=0, POWERLED=0,


ALARM=1) (Countdown to 00)
27

(When at DIP switch all 1’s, SW1=0 and SW2=1, DCMOTOR=0, POWERLED=0,
ALARM=1) (Suddenly SW1=0)

(When at DIP switch all 1’s, SW1=0 and SW2=1, DCMOTOR=0, POWERLED=0,
ALARM=0) (When at starting SW1=0)
28

(Print of the Circuit)


29

(When DIP Switches or Switches in training kit, all are zero)

(When DIP Switches or Switches in training kit, all are ones)


30

(When SW1=0 or STOP)

(When SW2=0 or PAUSE)


31

Discussion:

In the simple washing machine spin timer system developed, the DIP switches are working
perfectly in sync with the 7- Segments Display and the PIC. Whenever there is change in the DIP
switches manually the output changes. Plus the SW1 which is used to ON/OFF the circuit is
doing work same as if sk40c power switch was on and off, also the SW2 which is used for
PAUSE/START is doing the work exactly thought of by the developer and the DC Motor is
perfectly being controlled by the switches using the PIC.

There is still room for lot of improvement in the design, mainly more controlling options such as
more speeds, various alarms at various intervals, changing of direction of motor, control of water
supply, display etc. Developer already has the logic for conversion of HEX TO BCD and
BINARY TO DECIMAL but due to time restrained couldn’t successfully apply to the system, as
the system was getting unstable while the logic for conversion was applied, so needed more time
to try out the code. Here below are some of the codes which could be applied:

For BINARY from DIP switches to DECIMAL to display –

i=0;
if(RC0==1) i=i+1;
if(RC1==1) i=i+2;
if(RC2==1) i=i+4;
if(RC3==1) i=i+8;
if(RC4==1) i=i+16;
if(RC5==1) i=i+32;
if(RC6==1) i=i+64;
if(RC7==1) i=i+128;
return i;
32

For HEX TO BCD –

unsigned char convert (unsigned char i)


{
unsigned char y;
unsigned char x;
unsigned char z;
y = (i / 10) << 4;
x=i % 10;
z=x+y;
return (z);
}

Development of this system has taken a lot of time and was very tough, mainly because of the
coding of the PIC 16f877a. The hardware or components selection and connection wasn’t that
tough but, user had to try 100’s of combination to finally come up with the code with works fine
still not perfect.

It is even tougher as developer can’t see what is happening inside and has to rely on his logic and
experience. And there isn’t any one way of solving a problem using codes, there are so many
different methods so, it gets even tougher to find one which suits ones design.
33

Conclusion:

The system created by the developer using the DIP switch, PIC 16f877a, SPDT switches, 7
Segment displays, DC Motor, LED’s and resistors works absolutely fine. But it took many
hardships to reach to this position of even making the system work (as developer has very low
knowledge of C). The developer is happy because in the end his outputs were perfectly being
controlled by the inputs but still there are some clashes in the outputs due to some logic error in
coding which was hard to find.

First developer had tried to compile code many times using MPLAB but failed due to some or
other error, then when MBPLAB code was compiled when it was put in Proteus to simulate it did
not work due to some error which developer could not understand, he had to change his logic and
try again and again, finally when it worked in Proteus, developer loaded it into actual PIC. Then
again same thing, the prototype did not work, developer had to check and recheck the codes and
the circuit for the slightest mistake.

After doing this assignment developer came to know one thing for sure nothing is easy in life,
and without pain there is no gain. This assignment taught the developer to be patient and keep on
trying without giving up because without experience one can’t learn, one has to fail to learn.

This assignment has taught the developer more about how does the internals of the
microcontroller and microprocessor work, how does the functions happen inside them, plus
learnt more about the C language and ASM coding, which would be really helpful to get ready
for the FYP.

So, to conclude all the developer has made the block diagram of the circuit, has made the flow
chart, has written the codes for the PIC, has done simulation in Proteus and finally did the
prototype of the system he developed.
34

References:

 http://www.mikroe.com/eng/chapters/view/14/chapter-1-world-of-microcontrollers/
accessed on 27th MAY,2011

 http://www.piclist.com/techref/microchip/math/radix/index.htm accessed on 27th


MAY,2011

 http://engknowledge.com/microcontroller_interfacing_multyplexing_7_segment.a
spx accessed on 29th MAY,2011

 http://www.mcuexamples.com/PIC-Seven-Segment-Displays.php accessed on
29th MAY,2011

 http://www.digitalbirth.co.uk/blog/item/0-99-count-down-timer accessed on 29th


MAY,2011

 http://www.microchip.com accessed on 29th MAY,2011


35

Appendix:
36
37
38
39
40

Vous aimerez peut-être aussi