This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Interrupts using variable values???



Hello All,

I am using LM4F120 Stellaris Launchpad.

Though this question is not related strictly to this only controller, I want to ask to solve my query which has been born while using this controller!

I am programming my logic and I need a strategy to active a software interrupt when the value of the particular variable is get exceeded by predefined threshold value.

Is it possible?? And when the value is get lower down to that threshold value the interrupt should be disable.

For ex. Variable name is flag

Threshold value Th = 200;

Whenever Flag is more than 200 the interrupt should be active (for ex a timer interrupt have a load value of 1 ms)

& whenever Flag gets lesser then 200 the interrupt should be disable.

Please guide me to develop such logic.

Thanks a lot for  your help.

  • Do you know how to do logic in a program?

    This is very basic.

    if (Th > THRESHOLD) {

       IntEnable(DESIRED_INTERRUPT);

    }

    if (Th < THRESHOLD) {

       IntDisable(DESIRED_INTERRUPT);

    }

  • slandrum said:

    Do you know how to do logic in a program?

    This is very basic.

    if (Th > THRESHOLD) {

       IntEnable(DESIRED_INTERRUPT);

    }

    if (Th < THRESHOLD) {

       IntDisable(DESIRED_INTERRUPT);

    }

    That what I know sir.

    But I am asking to trigger it without checking the variable value...

    This is what a beginner can answer and so I. But my question was whenever the value goes higher than threshold it should be trigger the interrupt I don't want to check it all the time... So what you've suggest me as an answer is my question.

  • It's going to be your code that causes your variable to change, so just check it whenever you change it.

  • Jigar4Electronics said:
    exceed threshold ... trigger the interrupt... I don't want to check it all the time

    This reporter would have responded exactly as poster "slandrum" did - almost word for word.  So perhaps issue is your question's presentation.

    Software - for most any system - checks/tests a variable at an interval which meets overall system requirements.  This check can be "automated" - by having the "check/test" be triggered by an MCU Timer - as one example.  Hundreds of systems employ this method.

    Should your variable of interest exist in hardware (i.e. it is a signal voltage) that signal may be fed into the MCU's analog comparator (new M4's have this) or into certain MCU  ADC Channels - which feature a digital comparator.  Once set-up/configured - either method meets your requirement of, "not checking all the time..."  (i.e. checking is performed mechanically - by the hardware)

    As Stellaris in specific - and ARM in general - are loaded w/Timers - and software is vastly more flexible and dynamically adaptable - the normal/customary method of meeting your requirement is as slandrum suggested...  (perhaps w/the addition of a Timer "trigger" - to better automate the process.)

  • I'm with cb1_mobile and slandrum. I suspect you haven't really given us enough information to offer useful advice here. What's the high level problem you are trying to solve? With a bit more information on the big picture, we may be provide more useful advice.

  • This reporter respectfully submits that both his & slandrum's posts qualify as "useful advice."  

    Inadequacy of request does not degrade quality - and speed of response - of posts listed...

  • True enough. I should have said "more useful". I had no intention of downplaying the quality of the advice, honestly!

  • Thank you all... Thanks for your guidance. I'll implement all suggestions. Actually in code I want to make a very quick responsive method for the stability of the device using IMU (Inertial Measurement Unit) and my task is not to waste even a 1 micro second while gaining that stability... I need to create a strict lines for the variables which are irregular with respect to time... I think Class or Structures can be the option (using the public and private section properly)... Or if any other option which can make the device quick will be better to follow.

  • Dave Wilson said:
    What's the high level problem you are trying to solve?

    Or, in other words, what is the goal that you're trying to achieve?

    http://www.catb.org/~esr/faqs/smart-questions.html#goal

    Jigar4Electronics said:
    when the value of the particular variable is get exceeded by predefined threshold value

    Jigar4Electronics said:
    I don't want to check it all the time

    As the others have noted, your variables do not just magically change value of their own accord - they only change when you explicitly write to them.

    Therefore, you don't need to check all the time;  you just need to check whenever you do an update - perhaps by having a function which combines both the update and the check (and, maybe, also the action)?

     

  • Jigar4Electronics said:
    my task is not to waste even a 1 micro second

    Or not!   Shouldn't your first task be to, "satisfy the requirement?"  

    KISS and "Proceed by Refinement" usually produce faster and more lasting solutions.  Obsessing on one aspect of a problem often leads to inadequate consideration and/or analysis of the "big picture" - often results in delay, frustration and unnecessary "catch-up."

    Suggest you focus upon the central task - and reserve tweaks/optimizations for, "down the road."  (i.e. later - often only you will fully/properly value such focus... thus the effort may be mis-spent...while diverting you from the true mission...)

  •  

    "Premature optimisation is a root of all kinds of evils..."

  • Andy Neil said:

    "Premature optimisation is a root of all kinds of evils..."

    And - too often masks dreaded "avoidance" of more frightening/complex issues.

    In OP's case - likely extends time w/in, "Never Leave it until you did it," advisory logo/loop...

  • Thanks again to all to provide advices/ guidance.

    By the way my central task is to make a faster system... As I've already mentioned that I don't want to waste even a single microsecond is my central main task to fulfill using 10 - 20 variables with 10-20 different angles. And if in case I am not able to do it with 20 variables then 10 will also be ok for me... In short, My Focus/Main goal/ target/ central task is to develop quicker IMU system. I know that I can check the value of variable whenever I update (obviously without doing any magic) but I just wanna know that is their any other method available to do that with more quicker way?? And so I make a post here... But I think you all had take it purely negative....

    TI ratings for me is "Prodigy" it doesn't mean I've started doing programming yesterday! So Am I attempting to be premature or not could not be concluded by anyone.

  • Hi,

    No one wants bad for you - but you must realize the problem presented is incomplete so this is why all tried to change your thinking - of coarse you shouldn't disclose your full requirements, but at least the essential one needed for your help/benefit. What you don't want (still) to take into consideration is the behavior of a real system - noise for instance could trouble you more than anything else. While you like to process fast, some parasitic noise will force you to start a process, but the next microsecond it is gone so you started it for what? it is a real threshold or not? usually some form of analog/digital filtering is used if the variable is analog, or some counting if it is digital- but these must be correlated with your system... so you must start from the top down, coding phase should be the last one.

    Petrei