It is required to design the controller for a washing machine. The system is com
ID: 3919641 • Letter: I
Question
It is required to design the controller for a washing machine. The system is composed of the following components:
• PIC16F84A microcontroller
• A DC motor, and an H bridge
• An electronic valve to control the flow of water
• A switch to select the washing cycle type, we have a cycle for white clothes and a cycle for coloured clothes
• A push button to start the washing cycle
• A heating element to heat the water
The washing machine operates as follows:
1) The system waits for the start button to be pushed
2) The heater is turned on for a period of time: 40 seconds for coloured clothes and 80 seconds for white clothes
3) The water valve is turned on for 80 seconds
4) Motor is rotated clockwise for 20 seconds
5) Motor is rotated counter clockwise for 20 seconds.
6) Repeat steps (4) and (5) for a period of time: 40 minutes for coloured clothes, and 80 minutes for white clothes
Write a program in C to operate the system, Assume a delay of 20 seconds is available.
Explanation / Answer
#include <htc.h>
#define _XTAL_FREQ 8000000
void main()
{
TRISB2 = 1; // input port for push button
TRISB3 = 1; // input port for cycle type (1 for white-default)
TRISB4 = 0; // output port for water valve
TRISB5 = 0; // output port for heater
TRISB1 = 0; // output port for motor
TRISB7 = 0; // output port for motor
TRISA1 = 0; //optput port for motor
TRISA3 = 0; //optput port for motor
int i;
if(!TRISB2)
{
Delay_ms(100);
if(!TRISB2)
{
TRISB4 = 1;
Delay_ms(80000); // water valve turned on
TRISB4 = 0;
if(TRISB1)
{
TRISB5=1;
Delay_ms(80000); // heater turned on
TRISB5 = 0;
for(i=0;i<120;i++)
{
TRISA1 = 1;
TRISB1 = 0;
TRISA3 = 0;
TRISB7 = 1;
Delay_ms(20000);
TRISA1 = 0;
TRISB1 = 1;
TRISA3 = 1;
TRISB7 = 0;
Delay_ms(20000);
}
}
else
{
TRISB5=1;
Delay_ms(40000); // heater turned on
TRISB5 = 0;
for(i=0;i<60;i++)
{
TRISA1 = 1;
TRISB1 = 0;
TRISA3 = 0;
TRISB7 = 1;
Delay_ms(20000);
TRISA1 = 0;
TRISB1 = 1;
TRISA3 = 1;
TRISB7 = 0;
Delay_ms(20000);
}
}
}
TRISB2=1;
}
Check the pins for the H-bridge Im not sure with it
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.