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.

time delay + adc problem

Status
Not open for further replies.

sahu

Advanced Member level 2
Joined
Oct 9, 2009
Messages
516
Helped
68
Reputation
130
Reaction score
62
Trophy points
1,308
Location
Uttar pradesh (INDIA)
Activity points
3,876
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 .
 

In a delay loop, mcu can,t do anything else until delay is finished . If you want to recheck ch_0 for<800 during this 6 min period, you do polling or use interupt or use both (it is the smart code, you want). This is called multitasking.
For example, allocate a register to count time interval
loop:
check ch_0 for<800--if it is yes or register=36 skip to ch_1 and reset register to 0--
otherwise
call a delay of 10 seconds--
add 1 to a register which holds counts of 10 second delays.
repat this loop until register value is equal to 36 (10 sec x 36 equals 6 min)
 
Last edited:

In a delay loop, mcu can,t do anything else until delay is finished . If you want to recheck ch_0 for<800 during this 6 min period, you do polling or use interupt or use both (it is the smart code, you want). This is called multitasking.
For example, allocate a register to count time interval
loop:
check ch_0 for<800--if it is yes or register=36 skip to ch_1 and reset register to 0--
otherwise
call a delay of 10 seconds--
add 1 to a register which holds counts of 10 second delays.
repat this loop until register value is equal to 36 (10 sec x 36 equals 6 min)

can u give me 1 example ?
 

I'm experiencing difficulty in understanding your question. I believe in this I'm not alone.

You'd better depict you problem more clearly to get expected response of the community.
 

I'm experiencing difficulty in understanding your question. I believe in this I'm not alone.

You'd better depict you problem more clearly to get expected response of the community.

about o\l sense .
1_ if (ch_0>800) Wait 6 min . if ofter 6 min Agnes mcu sense ch_0>800 . it will go return(OVER_LOD_SENCE);
if ch_0<800 , then no action.

2_ if (ch_0>800) Wait 6 min . in duration 6 min (ch_1>1000) it will go return(HIGH_VOLTAGE);

my need 2 ADC {ch_0(AN0) & ch_1(AN1) sensing (working)At same time .
hope u understand , what i want to say u |||:?:
sorry for my bad English ...........:-(
 

It's not clear what MCU you are using. In general a very straightforward approach of delay a specific time interval is to use a timer:

1. set the initial value of the timer according to the time to delay and the frequency of the oscillator.
2. poll the overflow flag of the timer repeatedly using form like 'while(TMRxIF == 0);' to detect the moment the desired time has elapsed.

Hope that helps.
 

about o\l sense .
1_ if (ch_0>800) Wait 6 min . if ofter 6 min Agnes mcu sense ch_0>800 . it will go return(OVER_LOD_SENCE);
if ch_0<800 , then no action.

2_ if (ch_0>800) Wait 6 min . in duration 6 min (ch_1>1000) it will go return(HIGH_VOLTAGE);

my need 2 ADC {ch_0(AN0) & ch_1(AN1) sensing (working)At same time .
hope u understand , what i want to say u |||
sorry for my bad English ...........

What i understood is,
1) There are two ADC channels monitored, named ch_0 and ch_1.
2) See if ch_0 is greater than 800, then wait for six minutes.
3) then i dont understand?
See if ch_0 is greater than 800, then overload sense and no action?
If during this six min time sample ch_1 and see if ch_1 is greater than 1000, then output hi voltage?
 

You can have a dedicated variable, say 'ten_minutes', for your 10min delay in the timer ISR, and poll it constantly while you can still do other work:



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
unsigned char ten_minutes = 0;
 
/*****************************************************************************
  Timer1 Interrupt, executed every 10 ms
 ****************************************************************************/
#INT_TIMER1 
void TIMER1_isr(void) 
{
   // Increment time_elasped to keep track of ms
   time_elasped++;
 
   if (time_elasped == 100)  //high voltage cut led blink frequency @ 1000 ms
   {
        seconds++;
        //...
        time_elasped = 0;
   }
 
  if(Seconds == 60) 
  {
      Minutes++; Seconds=0; ten_minutes++;
      if(Minutes == 60) Minutes=0; 
  }
}
 
// ...
int ProcessMains_volt(void) 
{ 
    ch_0 = getchreading(0); 
    Process_ch_0();     // Do something with ch_0 o\p lod sence 
    if (ch_0>800)      // lod > 130 % Wait 10 min sence now
    {
        ten_minutes = 0;
        while(ten_minutes < 10)
         {
             ch_0 = getchreading(0); 
             Process_ch_0();
             Process_ch_1();
             // ...
          }         
         return(OVER_LOD_SENCE); 
    }     
    // ...
}



Hope I've understood your question and that helps.
 

You can have a dedicated variable, say 'ten_minutes', for your 10min delay in the timer ISR, and poll it constantly while you can still do other work:



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
unsigned char ten_minutes = 0;
 
/*****************************************************************************
  Timer1 Interrupt, executed every 10 ms
 ****************************************************************************/
#INT_TIMER1 
void TIMER1_isr(void) 
{
   // Increment time_elasped to keep track of ms
   time_elasped++;
 
   if (time_elasped == 100)  //high voltage cut led blink frequency @ 1000 ms
   {
        seconds++;
        //...
        time_elasped = 0;
   }
 
  if(Seconds == 60) 
  {
      Minutes++; Seconds=0; ten_minutes++;
      if(Minutes == 60) Minutes=0; 
  }
}
 
// ...
int ProcessMains_volt(void) 
{ 
    ch_0 = getchreading(0); 
    Process_ch_0();     // Do something with ch_0 o\p lod sence 
    if (ch_0>800)      // lod > 130 % Wait 10 min sence now
    {
        ten_minutes = 0;
        while(ten_minutes < 10)
         {
             ch_0 = getchreading(0); 
             Process_ch_0();
             Process_ch_1();
             // ...
          }         
         return(OVER_LOD_SENCE); 
    }     
    // ...
}



Hope I've understood your question and that helps.

thank u Mr. min2max for Ur guidance . tomorrow i will check it then inform hear .


ALERTLINKS; said:
What i understood is,
1) There are two ADC channels monitored, named ch_0 and ch_1.
2) See if ch_0 is greater than 800, then wait for six minutes.
3) then i dont understand?
See if ch_0 is greater than 800, then overload sense and no action?
If during this six min time sample ch_1 and see if ch_1 is greater than 1000, then output hi voltage?

i clear u what i want
1_There are two ADC channels monitored, named ch_0 (AN0) and ch_1 (AN1).

2_if ch_0 is greater than 800, then wait for six or ten minutes. agen read ch_0 ,if ofter six or ten minutes ch_0 is greater than 800 . mcu go overload sense case.

3_ If during this six or ten min time sample ch_1 and see if ch_1 is greater than 1000, then mcu go hi voltage case.

Hope U will understood my question (problem).
 

In the while(ten_minutes < 10) block you can read ch_1 ( in way of //... )and react accordingly.
 

You can have a dedicated variable, say 'ten_minutes', for your 10min delay in the timer ISR, and poll it constantly while you can still do other work:



Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
unsigned char ten_minutes = 0;
 
/*****************************************************************************
  Timer1 Interrupt, executed every 10 ms
 ****************************************************************************/
#INT_TIMER1 
void TIMER1_isr(void) 
{
   // Increment time_elasped to keep track of ms
   time_elasped++;
 
   if (time_elasped == 100)  //high voltage cut led blink frequency @ 1000 ms
   {
        seconds++;
        //...
        time_elasped = 0;
   }
 
  if(Seconds == 60) 
  {
      Minutes++; Seconds=0; ten_minutes++;
      if(Minutes == 60) Minutes=0; 
  }
}
 
// ...
int ProcessMains_volt(void) 
{ 
    ch_0 = getchreading(0); 
    Process_ch_0();     // Do something with ch_0 o\p lod sence 
    if (ch_0>800)      // lod > 130 % Wait 10 min sence now
    {
        ten_minutes = 0;
        while(ten_minutes < 10)
         {
             ch_0 = getchreading(0); 
             Process_ch_0();
             Process_ch_1();
             // ...
          }         
         return(OVER_LOD_SENCE); 
    }     
    // ...
}



Hope I've understood your question and that helps.
its meaning
Code:
int ProcessMains_volt(void) 
{ 
    ch_0 = getchreading(0); 
    Process_ch_0();     // Do something with ch_0 o\p lod sence 
    if (ch_0>800)      // lod > 130 % Wait 10 min sence now
    {
        ten_minutes = 0;
        while(ten_minutes < 10)
         {
             ch_0 = getchreading(0); 
             Process_ch_0();
             Process_ch_1();
             // ...
          }         
         return(OVER_LOD_SENCE); 
    }
when ch0 reach>800 & wait 10 min
then work
Code:
while(ten_minutes < 10)
         {
             ch_0 = getchreading(0); 
             Process_ch_0();
             Process_ch_1();
             // ...
          }
its work till ch0 reach>800 & it not
return(OVER_LOD_SENCE);
.
Hope u understood my question and help me.
 

Unfortunately it seems like I can not follow you.:oops:
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top