Hi,
The following code is for a level sensor(float type) based circuit that turns on a motor via a solid state relay(with opto-isolators) according to lower and upper level limit switches. The motor starts when lower limit switch is open and stops when upper limit switch is closed.
The following code always turns the motor on after the initial delay, even during the following starting conditions: lower limit switch closed, upper limit switch open/closed. The motor seems to be triggered by the upper limit switch. Kindly take a look at the code. I was unable to find any error.
P.S. The input pin P1.3 voltage was measured as low, but even then the motor starts. How is the control reaching inside the ' if(llvl==1)' statement?
The following code is for a level sensor(float type) based circuit that turns on a motor via a solid state relay(with opto-isolators) according to lower and upper level limit switches. The motor starts when lower limit switch is open and stops when upper limit switch is closed.
The following code always turns the motor on after the initial delay, even during the following starting conditions: lower limit switch closed, upper limit switch open/closed. The motor seems to be triggered by the upper limit switch. Kindly take a look at the code. I was unable to find any error.
Code:
/***************************** Header Files Declaration ***************************************************/
#include<reg52.h>
#include<stdio.h>
#include<intrins.h>
sbit onl = P2^2;//on indication
sbit offl = P2^3;//off indication
sbit out1= P3^7;//output to relay
bit hlvl;//high level input variable
bit llvl;//low level input variable
void delay(int n)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<100;j++)
{
}
}
}
void motor_on()
{
out1=0;
offl=0;
onl=1;
return;
}
void motor_off()
{
out1=1;
onl=0;
offl=1;
return;
}
void main()
{
P1 = 0xFF;
motor_off();
delay(1000);
while(1)
{
//reading input pins
hlvl = P1^3;
llvl = P1^4;
if(llvl==1) // if low level sensor becomes open, motor is turned on
{
motor_on();
}
if(hlvl==0)//if high level sensor becomes closed, motor is turned off
{
motor_off();
}
}
}