Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

time delay + adc problem

Status
Not open for further replies.

sahu

Member
I'm facing problem time delay during dual ADC i\p at same time.
Code:
int ProcessMains(void) 
 { 
    ch_0 = getchreading(0); 
    Process_ch_0();      // Do something with ch_0 o\p lod sence 
     if (ch_0>800)  // lod 130 % Wait 6 min 
        Delay60000ms 
       return(OVER_LOD_SENCE); 
       
    ch_1 = getchreading(1);  
    Process_ch_1();      // Do something with ch_1 o\p volt 
       if (ch_1>1000) 
       return(HIGH_VOLTAGE); 
     
        if (ch_1<950) 
       return(NORMAL_VOLTAGE); 

 }
Actually I want if (ch_0>800) mcu wait 6 min,
when ADC reach >800 delay start hear
if (ch_0>800) yet 6 min, then return(OVER_LOD_SENCE)

if (ch_0<800) during 6 min. it will go predefine return abc case.
im using CCS C .
 
You do realize, that function will ALWAYS return over_lod_sense.. Delay6000ms hasn't got a ";" at the end

it should read
Code:
  if (ch_0>800)  // lod 130 % Wait 6 min 
      {
       Delay60000ms ;   // end statement
       return(OVER_LOD_SENCE); 
      }

now it will only return O_L_S when it evaluates ch > 800..
 
Last edited:
You do realize, that function will ALWAYS return over_lod_sense.. Delay6000ms hasn't got a ";" at the end

it should read
Code:
  if (ch_0>800)  // lod 130 % Wait 6 min 
      {
       Delay60000ms ;   // end statement
       return(OVER_LOD_SENCE); 
      }

now it will only return O_L_S when it evaluates ch > 800..

one main problem is hear
when ADC reach >800 delay start hear(6 minutes)
ok |||
between delay(6 minutes) other ADC ch_1 not working
ch_1 = getchreading(1);
Process_ch_1(); // Do something with ch_1 o\p volt
if (ch_1>1000)
return(HIGH_VOLTAGE);
ETC
 
In you original code
Code:
int ProcessMains(void) 
 { 
    ch_0 = getchreading(0); 
    Process_ch_0();      // Do something with ch_0 o\p lod sence 
     if (ch_0>800)  // lod 130 % Wait 6 min 
        Delay60000ms                      EVEN WITH THE MISSING  ';'
       return(OVER_LOD_SENCE);      THIS IS EXECUTED ANYWAY
 
    ch_1 = getchreading(1);            WHICH MEANS THIS NEVER IS.
    Process_ch_1();      // Do something with ch_1 o\p volt 
       if (ch_1>1000) 
       return(HIGH_VOLTAGE); 
 
        if (ch_1<950) 
       return(NORMAL_VOLTAGE); 
 
 }
 
In you original code
Code:
int ProcessMains(void) 
 { 
    ch_0 = getchreading(0); 
    Process_ch_0();      // Do something with ch_0 o\p lod sence 
     if (ch_0>800)  // lod 130 % Wait 6 min 
        Delay60000ms                      EVEN WITH THE MISSING  ';'
       return(OVER_LOD_SENCE);      THIS IS EXECUTED ANYWAY
 
    ch_1 = getchreading(1);            WHICH MEANS THIS NEVER IS.
    Process_ch_1();      // Do something with ch_1 o\p volt 
       if (ch_1>1000) 
       return(HIGH_VOLTAGE); 
 
        if (ch_1<950) 
       return(NORMAL_VOLTAGE); 
 
 }

yes |||
 
I think our wires were crossed.... What is it you want the function to do....If the flow is like ths..

read ch_0..
process ch_0
if ch_0 is bigger than 800 then delay 6 seconds then return O_L_S (finished)

read ch_1..
process ch_1
if ch_1 is bigger than 1000 then return H_V (finished)
or return N_V (finished)

In either case if ch_0 is bigger than 800 then ch_1 is ignored.


Are you wanting to halt like this.

Code:
int ProcessMains(void) 
 { 
    int x = 600;
    ch_0 = getchreading(0); 
    Process_ch_0();     // Do something with ch_0 o\p lod sence 
     if (ch_0>800)      // lod 130 % Wait 6 min 
         {
         while(x--)
            {
             Delay1000ms;
             ch_0 = getchreading(0); 
             Process_ch_0();                  // Do something with ch_0 o\p lod sence 
             if(ch_0 < 800) return abc;
             }         
       return(OVER_LOD_SENCE);      
      }
    ch_1 = getchreading(1);            WHICH MEANS THIS NEVER IS.
    Process_ch_1();      // Do something with ch_1 o\p volt 
    if (ch_1>1000) 
       return(HIGH_VOLTAGE); 
 
    if (ch_1<950) 
       return(NORMAL_VOLTAGE); 
 
 }

you'll need to keep acessing the ch_0 reading to check if it goes lower.
 
Last edited:
I think our wires were crossed.... What is it you want the function to do....If the flow is like ths..

read ch_0..
process ch_0
if ch_0 is bigger than 800 then delay 6 seconds then return O_L_S (finished)

read ch_1..
process ch_1
if ch_1 is bigger than 1000 then return H_V (finished)
or return N_V (finished)

In either case if ch_0 is bigger than 800 then ch_1 is ignored.


Are you wanting to halt like this.

Code:
int ProcessMains(void) 
 { 
    int x = 600;
    ch_0 = getchreading(0); 
    Process_ch_0();     // Do something with ch_0 o\p lod sence 
     if (ch_0>800)      // lod 130 % Wait 6 min 
         {
         while(x--)
            {
             Delay1000ms;
             ch_0 = getchreading(0); 
             Process_ch_0();                  // Do something with ch_0 o\p lod sence 
             if(ch_0 < 800) return abc;
             }         
       return(OVER_LOD_SENCE);      
      }
    ch_1 = getchreading(1);            WHICH MEANS THIS NEVER IS.
    Process_ch_1();      // Do something with ch_1 o\p volt 
    if (ch_1>1000) 
       return(HIGH_VOLTAGE); 
 
    if (ch_1<950) 
       return(NORMAL_VOLTAGE); 
 
 }

you'll need to keep acessing the ch_0 reading to check if it goes lower.

thank u sir for Ur guidelines
above change work as u say .
but my main problem is hear .....
In either case if ch_0 is bigger than 800 then ch_1 is ignored.
as i want " in case if ch_0 is bigger than 800 & it(mcu) sty in delay mode & during delay mode ch_1 is don't ignored "
because ch_0= current sens adc & ch_1= voltage sens adc.
so if (mcu) sty in delay mode & ch_1 is ignored by mcu & ch_1 >1000 (HIGH_VOLTAGE ) .we found HIGH_VOLTAGE . mcu not go high volt cut mode
it is one error .
 
set a return value of 1 = O_L_S, 2 = ABC, 3 = HV and 4 = NV

Code:
int ProcessMains(void) 
   { 
   static int x = 0;
   int returnvalue = 0;
    
   ch_0 = getchreading(0); 
   Process_ch_0();     // Do something with ch_0 o\p lod sence 
   if (ch_0>800)        // lod 130 % Wait 6 min 
      {
      if( x++ == 600 )
         returnvalue  = OVER_LOD_SENCE; 
      Delay1000ms;
      }
   else(ch_0 < 800) 
      returnvalue  = ABC;
       
   ch_1 = getchreading(1);           
   Process_ch_1();      // Do something with ch_1 o\p volt 
   if (ch_1>1000) 
       returnvalue = HIGH_VOLTAGE; 
 
    if (ch_1<950) 
       returnvalue = NORMAL_VOLTAGE; 
       
    return returnvalue;
 
 }

The only way I can figure it out
 
Last edited:
set a return value of 1 = O_L_S, 2 = ABC, 3 = HV and 4 = NV

Code:
int ProcessMains(void) 
   { 
   static int x = 0;
   int returnvalue = 0;
    
   ch_0 = getchreading(0); 
   Process_ch_0();     // Do something with ch_0 o\p lod sence 
   if (ch_0>800)        // lod 130 % Wait 6 min 
      {
      if( x++ == 600 )
         returnvalue  = OVER_LOD_SENCE; 
      Delay1000ms;
      }
   else(ch_0 < 800) 
      returnvalue  = ABC;
       
   ch_1 = getchreading(1);           
   Process_ch_1();      // Do something with ch_1 o\p volt 
   if (ch_1>1000) 
       returnvalue = HIGH_VOLTAGE; 
 
    if (ch_1<950) 
       returnvalue = NORMAL_VOLTAGE; 
       
    return returnvalue;
 
 }

The only way I can figure it out

im right ?
Code:
 /*****************************************************************************
  ProcessMains return values
 ****************************************************************************/
#define NORMAL_VOLTAGE 0
#define HIGH_VOLTAGE 1
#define LOW_VOLTAGE 2
#define OVER_LOD_SENCE 3  // 130 % yet 6 min
 
Well.. If you have four return values....and lets say ch_0 is out of range ie.. >800, then you call ch_1 will overwrite the return value. and you still have a situation where ch_1 returned ok and ch_0 return wasn't seen... So!! if O_L_S was bit 0, ABC was bit 1, High voltage was bit 2 and normal voltage was bit 3 you would see both ch_0 and ch_1 return conditions (actually you only need two as there are only two conditions for both )
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top