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.

[PIC] Continuously monitor using interrupt ?? How to use interrupt??

Status
Not open for further replies.

shubham kumar

Member level 3
Joined
Sep 11, 2014
Messages
59
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Location
bangalore
Activity points
511
I am using PIC18F452 and MikroC.
My doubt is not specifically related to this controller.

I am trying to make a program, in which I have to continuously monitor the temperature. Controller do the calculations as normal work and Whenever there is a change by (+ or -)2degree (or 2 units) the controller must notify or do certain specified task and come back to normal work.
How do I do that. Please tell me the logic.

I thought of writing the program in timer interrupt and the timer will check for the change whenever the timer flag overflows. but that doesn't help as what if each time the timer overflows and temperature increase by 2 degree and decrease by 1 degree (in that case I controller will not detect it).
I thought of connecting the temperature input to INT1 but there also that change is not detectable.

It is something like whenever there is 2degree change it will take that as interrupt. I know that if it is in the ISR till then it will not detect any further change but even then I didn't found a way to do that.

Please tell me the logic
 

Something like this might help.


Code C - [expand]
1
2
3
4
5
6
7
if(currVal >= prevVal + 2)//start ISR and set a flag in ISR and come out from ISR
 
if(myFlag) {
    //do what you want and clear the flag
    
    myFlag = 0;
}

 

I don't believe that the problem is primarly related to interrupts or would be solved using interrupts.

Temperatures are varying rather slowly compared to code execution time, even in a really fast heater zone. So all you need is a piece of code to be executed repeatedly, usually in the main loop. In some cases, a timer or ADC interrupt may trigger the code, but that doesn't mean that the code has to be executed in an interrupt context.
 

Yes, 2 degree change in temperature will take some time and only a few milli seconds is needed to check if current temperature is 2 degrees more than previous temperature value. ISR is not needed. You can just set a flag if temperature has risen 2 degrees or more and then set a flag and execute the code needed if flag is set. The thing is the prevVal should not be changed with new value unless the difference between currVal and prevVal is 2 or more degrees.
 

Okzz.. here is one logic I am thinking

Code:
Void interrupt ()
{
 if(TMR1IF_bit)
         {
     //set clear necessary flags etc.
if(T_present >= T_previous+2)
            {  
     //do some some calculations etc. CAL1
     // T_previous=T_current

}}}

void main()
{
      // set flags, timer priorities, T1CON, INTCON etc.
       //start timer
while(1)
     {
   //do something CAL2
     }
}

In this what I am doing is, it will check for temperature is changed by 2units whenever the timer flag is raised, till then it will be working in main.

OR should I do something like:

Code:
void main() {

while(1)
{

if(T_present >= T_previous+2)
           { // do something calculation CAL1
              T_previous=T_current
           }

//do something CAL2

if(T_present >= T_previous+2)
           { // do something calculation CAL1
            T_previous=T_current
           }

//do something CAL2

if(T_present >= T_previous+2)
           { // do something calculation CAL1
             T_previous=T_current
            }

//do something CAL2

}

Or can you suggest any other method.
 
Last edited:

Only this much is required to do. Even it takes 1 sec for the while(1) to execute once it is more than enough. Even the flag is not needed.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
void main() {
 
    while(1)
    {
 
        if(T_present >= T_previous + 2)
            {   // do something calculation CAL1
                    T_previous=T_current
            }
 
    }
}

 

Thanks milan.rajik,

but but my code inside this condition is very large (CAL1)
Code:
 if(T_present >= T_previous + 2)
            {   // do something calculation CAL1
                    T_previous=T_current
            }

also the code in main (outside this condition) is also very large.
So if I do that than the time between checking the condition twice is very large. So the change between these two checks will not be detected.

[[ what I am doing is, I am saving all the temperature values and then trying to predict the next approximate change so the more faster the check is the more better it is.
Obviously, we cant overcome the hardware constraints but we can make it more accurate by programming in such a way that it will check the condition as many times and also the other calculations will run.]]
 

Have you calculated the time taken to execute CAL1 and also the while(1) loop once ? If not, find it first.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top