Does variable value change being transferred to code running in interrupt loop?


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Does variable value change being transferred to code running in interrupt loop?

    Hi,
    In PBP all variables are global, meaning they are always "in scope" and can be accessed by anything/everything at any time/all the time so the answer to your question is yes.

    Pay special attention to what Art said, the total execution time of the interrupt code can not be allowed to be MORE than the time between interrupts. If you have a timer tripping an interrupt at 100Hz then the total execution time of the code in the interrupt service routine can not be more than 10ms. If it is then your main code will not run.

    You'll see comments about never doing any "real work" in the interrupt code, quick in, quick out, set flags etc or you'll set the world on fire. These are generally good advice but there's absolutely no problems with spending 90% of your time in the ISR and 10% in the main code as long as you understand what that does to your code. A PAUSE 100 in the main code will pretty much turn into a PAUSE 900 due to the interrupt service routine "absorbing" 90% of the CPU power without the rest of the system knowing about it. The same goes for all the software times commands like SERIN, COUNT, PWM, DEBUG etc etc - as long you understand that and you're OK with it then no problem.

    /Henrik.

  2. #2
    Join Date
    Feb 2013
    Posts
    1,132


    Did you find this post helpful? Yes | No

    Default Re: Does variable value change being transferred to code running in interrupt loop?

    Well, that PAUSE 100 was provided just as filler - at such rate, leds going to blink rapidly. I believe, PAUSEUS 100 would be much better, but PBP PAUSEUS accuracy is far from desired.

  3. #3
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Does variable value change being transferred to code running in interrupt loop?

    If that code is in your interrupt, the interrupt can never exit and you might as well have put this in your main program.
    You can’t run a continuous loop. The ISR is always a call i.e.. GOSUB, and you always have to return from interrupt or your main code will never run.
    What is currently triggering the interrupt?

    Also, it looks like you want PWM at 50% duty cycle, but if more than one condition is true, it will break all of them.

    There is a thread a little below about frequency counters. Darrel didn’t want to shove his own timer code down someone’s throat,
    but it was really the answer to the problem. To his merit, he gave advice about a less efficient manner the OP was already working on.
    Similarly DT’s code is the answer to your problem.
    Last edited by Art; - 7th April 2015 at 10:30.

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Does variable value change being transferred to code running in interrupt loop?

    It looks to me you want three software PWM channels, all 50% duty cycle 100ms ON/100ms OFF,
    that you switch on & off based on the values in variables A,B & C.

    Even though this code won’t do that, I don’t understand why you check X=1, X>1, X>2, all for the same result.
    Could you have just:
    Code:
    IF A != 0 THEN
    HIGH LED1
    PAUSE 100
    LOW LED1
    PAUSE 100
    ENDIF
    and then the same for B & C?

    Just want to be sure of what you want to do.

  5. #5
    Join Date
    Feb 2013
    Posts
    1,132


    Did you find this post helpful? Yes | No

    Default Re: Does variable value change being transferred to code running in interrupt loop?

    Just checked, sorry, I've pasted ENDIF at wrong place. It should look like this

    Code:
    SOFTPWM:
    IF A=1 THEN
    HIGH LED1
    ENDIF
    PAUSE 100
    LOW LED1
    PAUSE 100
    GOTO SOFTPWM
    and so on, for all LEDS and cases.

    I want to run this code in background of main task, so this is why I wanted to use interrupt. Seems like it is impossible?

  6. #6
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Does variable value change being transferred to code running in interrupt loop?

    You mean you want to run the above lines of code as an interrupt? I don't think so.... The pauses will kill you.... What is your anticipated interrupt period?
    By the way, What processor are you using and at what frequency?
    Last edited by Dave; - 7th April 2015 at 11:53.
    Dave Purola,
    N8NTA
    EN82fn

  7. #7
    Join Date
    Feb 2013
    Posts
    1,132


    Did you find this post helpful? Yes | No

    Default Re: Does variable value change being transferred to code running in interrupt loop?

    I want to run this task in a way, that main task won't interfere with it, nor it execution will affect main task.

    Processor can be any of 16F family at any possible frequency.

Similar Threads

  1. Can not change variable while using DT_INT?
    By hvguy0 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th March 2013, 23:05
  2. Altering a variable in a loop.
    By jmgelba in forum mel PIC BASIC Pro
    Replies: 26
    Last Post: - 18th September 2012, 06:24
  3. Change a variable to the opposite?
    By Hylan in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 21st June 2012, 07:00
  4. Change variable allocation to save code space
    By aberco in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 5th September 2011, 01:28
  5. 16f84a running interrupt PICBASIC code
    By divaker in forum mel PIC BASIC Pro
    Replies: 18
    Last Post: - 31st July 2008, 15:49

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts