Generate a non-blocking pulse with an Interrupt Service Routine
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    204

    Default Generate a non-blocking pulse with an Interrupt Service Routine

    Saw a similar thread (http://www.picbasic.co.uk/forum/showthread.php?t=24119) and it was a very timely question. A project I'm working on has a somewhat similar pulse requirement and I have been asking myself how to accomplish it with out tying myself up with PAUSE commands in the ISR.

    In my case, I need to trigger a couple of 500uS pulses on different pins at different intervals.
    I'm using DT INTs and have two 8 bit timers free (TMR0 and TMR2 on a 12F683).

    Currently have a line in the ISR: "pulsout Drive, 50" for a 500uS pulse, but I'm concerned that it's an unnecessary delay.

    Daryl's Blinky example (http://dt.picbasic.co.uk/INT16/BlinkyLED) is close, but with the TOGGLE scheme, when I entered the ISR, it would toggle the pin on and load the ON time, then I would have to toggle it back off somehow. I'm trying to understand how you would do that. The only ways I can think of require that you stay in the ISR ( with the attendant delay) or maybe enter the ISR twice and change the timer preload for ON and OFF times.

    The pulse times are constant, it's just how often I fire them that changes.

    Any suggestions?
    thanks
    bo

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,228

    Default Re: Generate a non-blocking pulse with an Interrupt Service Routine

    One possible way:
    If 500us is enough granularity for the timing BETWEEN pulses then make your interrupt fire every 500us. In the ISR first clear all outputs - always. Then increment counter(s) for the various outputs and check if it's time to generate a pulse, if so set that output.

    At 2kHz interrupt rate with BYTE sized counter variables the time between pulses can be ~128ms and with WORD sized counter variables as much as 32 seconds.

  3. #3

    Default Re: Generate a non-blocking pulse with an Interrupt Service Routine

    How about, set a flag and set the timer for the delay between pulses. In the ISR, if flag set, set port hi, clear the flag and set the timer to the pulse duration or if flag clear, set port low, set the flag and set the timer to the delay between pulses.
    Last edited by towlerg; - 16th April 2019 at 12:05.
    George

  4. #4
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    204

    Default Re: Generate a non-blocking pulse with an Interrupt Service Routine

    Thank you for the ideas. Ill give it a go and see what I come up with.
    bo

  5. #5
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    866

    Default Re: Generate a non-blocking pulse with an Interrupt Service Routine

    If the 8 bit timer suffices for your max pulse timing, you can consider setting the output, firing the timer and on the timer overflow interrupt, turn off the output. This way you can get enough granularity/variability for pulse width.

  6. #6
    Join Date
    Feb 2008
    Location
    Michigan, USA
    Posts
    204

    Default Re: Generate a non-blocking pulse with an Interrupt Service Routine

    Jerson,
    That's what I'd like to do. I have been trying to figure out how to do just that. I'm not sure how to end it with an interrupt. Time to study up on timer overflow and see how that will work...
    bo

Similar Threads

  1. Programmatically generate a (false) interrupt?
    By circuitpro in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th January 2011, 23:48
  2. Replies: 23
    Last Post: - 23rd September 2008, 18:20
  3. DT interrupt/pulse generator
    By Adrian in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 20th August 2008, 21:13
  4. TMR1 100Hz Exactly Interrupt Routine
    By manumenzella in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 15th February 2007, 05:51
  5. Blocking problem with 18F252
    By muskut in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 12th October 2005, 21:53

Members who have read this thread : 15

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