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, The Parallax Propeller is truly a multicore processor. You would need multiple Pic's to do the same.
    I don't see the difference in your code next to what I am suggesting? The way your's is written it will not produce the output you require.And what do you mean terminated? How about this for an interrupt example:
    a = 1
    MAIN:
    if Interrupt = 1 then
    Interrupt = 0
    if PROG = 0 then
    gosub program 1
    else
    gosub program 2
    endif
    endif
    a = a + 1
    if a > 10 then a = 0
    goto main

    Program1:
    PRINT "A=";A
    return

    Program2:
    PRINT "B=";B
    return

    This will produce the output you require.

    Or without interrupts, Your way..
    A=1
    B=1
    DO:
    PRINT "A=";A
    PRINT "B=";B
    A=A+1
    B=B+1
    IF A > 10 THEN A = 1
    IF B > 10 THEN B = 1
    LOOP

    This will produce the same output you require.
    Last edited by Dave; - 7th April 2015 at 22:23.
    Dave Purola,
    N8NTA
    EN82fn

  2. #2
    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 you’re going that way it would make more sense to do the PWM in your main code and handle button pushes in the interrupt.
    So you’d interrupt on port change and change some variables in the ISR and don’t have to run a loop polling buttons.

    Either way unless the PWM is timer driven, it’s still not “emulating something like that”. Even though you might get the job done.

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


    Did you find this post helpful? Yes | No

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

    Simply saying, windows is multi tasking OS, and can do multi-tasking even on single core CPU. How to do it similar way on PIC ?

  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?

    With a hardware timer. ie. Time slice, time splitting.
    The same way other platforms and threading languages (C) do it.

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


    Did you find this post helpful? Yes | No

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

    Quote Originally Posted by Dave View Post
    CuriousOne, The Parallax Propeller is truly a multicore processor. You would need multiple Pic's to do the same.
    I don't see the difference in your code next to what I am suggesting? The way your's is written it will not produce the output you require.And what do you mean terminated? How about this for an interrupt example:
    a = 1
    MAIN:
    if Interrupt = 1 then
    Interrupt = 0
    if PROG = 0 then
    gosub program 1
    else
    gosub program 2
    endif
    endif
    a = a + 1
    if a > 10 then a = 0
    goto main

    Program1:
    PRINT "A=";A
    return

    Program2:
    PRINT "B=";B
    return

    This will produce the output you require.

    Or without interrupts, Your way..
    A=1
    B=1
    DO:
    PRINT "A=";A
    PRINT "B=";B
    A=A+1
    B=B+1
    IF A > 10 THEN A = 1
    IF B > 10 THEN B = 1
    LOOP

    This will produce the same output you require.
    The main difference is that I need it to work like this:

    advance code 1
    advance code 2
    loop

    The "PRINT" was just an example, of course if I want to print two variables at same time, I know how to do this

    And doing it in both way means that I have to prematurely exit from FOR/NEXT loop, and I can't return to inside it.

    Let me explain once again what I need.

    In above example, I have two for/next loops, each with 10 steps. Is there a way to execute them like one step from code a, one step from code b and so on. Execute by not modifying code as you did (because it works for this certain case, but in real life it might be totally impossible to do like you did), but just distributing processor time between two codes ?

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