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
    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?

    CuriousOne, Here ia a small template for a program I just wrote that you can use as a starting point. It uses DT interrupts. I have them set for 1 millisecond and using 2 complete ports for the leds. Those ports are B & D. These interrupts are running in the background updating the led status from the 16 byte array. You can change the values in the array at any time in the main program. Enjoy. Let me know if it works for you.
    Attached Files Attached Files
    Dave Purola,
    N8NTA
    EN82fn

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


    Did you find this post helpful? Yes | No

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

    Thanks a lot, I don't have 18F46K22, but I have 18F45K22, will give it a try.

    I need some time to read and interpret "foreign" code for myself

  3. #3
    Join Date
    Feb 2013
    Posts
    1,153


    Did you find this post helpful? Yes | No

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

    Here's how I understand, how interrupt should work (for my case of course).

    There are two "independent" code blocks. The MCU works like this - 4 clock ticks (if I'm not mistaken, minimal amount needed to execute one command) are given to code block #1, next 4 ticks - to block #2, and so on. Since these "ticks" are going at high speed, from the user side, response is fluid and smooth.

    am I wrong?

  4. #4
    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?

    CuriousOne, It sounds as if you are interpreting interrupts to mean time multiplexing the operations of 2 different code segments at 50 %. This is NOT how it works. The MAIN code seqment is interrupted for a short period of time do execute some code then execution is returned to the main seqment. You should be in the interrupt routine as short of a time as possible.
    Dave Purola,
    N8NTA
    EN82fn

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


    Did you find this post helpful? Yes | No

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

    Yes, I might be wrong, since I approach interrupts as sort of multi-tasking. So, it might be possible to use it in they way I'd like it to be?

    Like this sequence:

    program starts, timer1 starts counting and after 4 ticks (or whatever value needed) it generates interrupt which jumps to another part of code. That another part of code, itself launches timer2, which again, after 4 ticks or whatever, generates interrupt, which jumps to 1st part of code.

    Is this possible?

    I guess, ASM will be needed.

  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?

    Wow, If that's all you want to do is jump between two different programs at a fixed interval then I would just start a timer interrupt at your favorite interval then TOGGLE a BIT called "PROG" each time the interrupt occures as well as set a flag bit called "Interrupt" to indicate the interrupt has occured. Then your main program would look like:
    MAIN:
    if Interrupt = 1 then
    Interrupt = 0
    if PROG = 0 then
    gosub program 1
    else
    gosub program 2
    endif
    endif
    goto main
    Dave Purola,
    N8NTA
    EN82fn

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


    Did you find this post helpful? Yes | No

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

    Yes, but program should not be terminated, it should be "paused" while another part is executing. Let me illustrate by this simple "CODE"

    Conventional BASIC:

    DO:
    FOR A=1 TO 10
    PRINT "A=";A
    NEXT A

    FOR B=1 TO 10
    PRINT "B=";B
    NEXT B

    LOOP

    The above program will print value of A first, and then it will print value of B.

    But I need a output like this:

    A=1
    B=1
    A=2
    B=2
    A=3
    B=3

    and so on.

    I need to somehow "multiplex" two different parts of code in a such way, that they would run in "parallel" If you have heard about Parallax "propeller" chip, which has 8 "cores" but they being executed sequentally, at high speed, so user gets feeling of multi-core system. So I want basically to emulate something like that.

Similar Threads

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