Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

experimental code in C

Status
Not open for further replies.

swapan

Full Member level 4
Full Member level 4
Joined
Feb 20, 2009
Messages
204
Helped
27
Reputation
54
Reaction score
24
Trophy points
1,298
Location
Kolkata
Visit site
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

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
 

Hello!

As you don't provide schematics, we cannot check how the relay is wired and therefore
cannot reply to your question.
Does your relay signal power a transistor? Is it a low side or high side transistor?
Etc...
You may try to use the debugger, set the relay signal to 1, see what happens, then set it to 0.


Dora.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top