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
    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 11:30.

  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?

    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.

  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?

    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?

  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?

    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 12:53.
    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?

    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.

  6. #6
    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’s not the pauses, the loop never ends:
    Code:
    SOFTPWM:
    code
    GOTO SOFTPWM
    Only your main program can do that.
    This ISR doesn’t allow your main program to ever run once it’s called.

  7. #7
    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 get this going I’ll do the rest from there.
    The code to flash one led on/off per second is only needed
    to prove the include file is being included from the right directory and everything works.

    At the speeds you’re talking about you can have up to eight software PWM channels
    who’s rising and falling edges are synchronised to the clock cycle fairly easily.
    especially easy if the frequency of the outputs are the same.

    Code:
    DEFINE OSC xx
    ‘ tell PBP the clock frequency you’re using
    DEFINE NOCLRWDT
    ‘ this only means the program has it’s own clrwdt instruction
    ‘ you can still set the watchdog timer on at programming time
    
    include “Elapsed.bas”
    ‘ DT’s Elapsed Timer code from PBP forum
    ‘ drop the Elapsed.bas file in the PBP folder
    
    ‘don’t bother declaring SecondsChanged variable,
    ‘it should already be accessible because it’s declared in the include file
    
    ‘CMCON = 7
    ‘uncomment to set analogue ports digital if the device has analogue ports
    ‘and the led is connected to one of them
    
    trisb.1 = 0
    ‘ set led output whichever pin you have the led connected
    ledstate var bit
    
    gosub ResetTime		'reset time 00:00:00
    gosub StartTimer	'start timer
    '
    cycle:
    @ clrwdt
    ‘
    if SecondsChanged = 1 then
    SecondsChanged = 0
    ledstate = ledstate + 1
    portb.1 = ledstate
    ‘ use your led pin of course
    endif
    ‘
    goto cycle
    ‘

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