swapan
Full Member level 4
- Joined
- Feb 20, 2009
- Messages
- 204
- Helped
- 27
- Reputation
- 54
- Reaction score
- 24
- Trophy points
- 1,298
- Location
- Kolkata
- Activity points
- 2,839
Hi Friends
Following various codes in C published in this forum and gaining a little knowledge I have started a small project for experiment. Please see the code
As per code it was intended when supply is applied first time and the value of applied signal at AN0 is within normal range, a delay of 5 seconds will be there to activate the Relay. But in practice it is seen that the Relay operates almost at the moment supply is made through. I have used delay upto 10 seconds. But the result is same.
Help is earnestly requested to point the fault out.
swapan
Following various codes in C published in this forum and gaining a little knowledge I have started a small project for experiment. Please see the code
Code:
void main_check();
int adc_main, old_value, difference_value;
void main() {
TRISIO = 0x9;
GPIO = 0;
CMCON = 7;
ANSEL = 1;
GPIO.GP2 = 0;
adc_main = ADC_Read(0);
if (adc_main > 900) {
GPIO.GP1 = 1; // High Indication LED ON
GPIO.GP4 =0; //Low Indication LED OFF
GPIO.GP5 =0; //Normal Indication LED OFF
GPIO.GP2= 0; //RELAY OFF
old_value = adc_main; // To record present value.
}
else if (adc_main < 560) {
GPIO.GP1 = 0; // High Indication LED OFF
GPIO.GP4 =1; // Low Indication LED ON
GPIO.GP5 =0; // Normal Indication LED OFF
GPIO.GP2= 0; //RELAY OFF
old_value = adc_main; // To record present value
}
else {
GPIO.GP1 = 0; // High Indication LED OFF
GPIO.GP4 =0; // Low Indication LED OFF
GPIO.GP5 =1; // Normal Indication LED ON
Delay_ms(1000);
Delay_ms(1000);
Delay_ms(1000);
Delay_ms(1000);
Delay_ms(1000);
GPIO.GP2= 1; //RELAY ON
}
do {
main_check();
}while (1);
}
void main_check() {
adc_main = ADC_Read(0);
if (adc_main > old_value) {
difference_value = adc_main - old_value;
}
else {
difference_value = old_value - adc_main;
}
if (difference_value >= 100) { // Hysteriasis
if (adc_main > 900) {
GPIO.GP1 = 1; // High Indication LED ON
GPIO.GP4 =0; //Low Indication LED OFF
GPIO.GP5 =0; //Normal Indication LED OFF
GPIO.GP2= 0; //RELAY OFF
old_value = adc_main; // To record present value.
}
else if (adc_main < 560) {
GPIO.GP1 = 0; // High Indication LED OFF
GPIO.GP4 =1; // Low Indication LED ON
GPIO.GP5 =0; // Normal Indication LED OFF
GPIO.GP2= 0; //RELAY OFF
old_value = adc_main; // To record present value
}
else {
GPIO.GP1 = 0; // High Indication LED OFF
GPIO.GP4 =0; // Low Indication LED OFF
GPIO.GP5 =1; // Normal Indication LED ON
GPIO.GP2= 1; //RELAY ON
old_value = adc_main; // To record present value
}
}
}
As per code it was intended when supply is applied first time and the value of applied signal at AN0 is within normal range, a delay of 5 seconds will be there to activate the Relay. But in practice it is seen that the Relay operates almost at the moment supply is made through. I have used delay upto 10 seconds. But the result is same.
Help is earnestly requested to point the fault out.
swapan