Instant Interrupts - Revisited


Closed Thread
Results 1 to 40 of 773

Hybrid View

  1. #1
    Join Date
    Jan 2014
    Posts
    84


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    ...or , how I can make SPWM without intrerupts...?

  2. #2


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Quote Originally Posted by midali View Post
    ...or , how I can make SPWM without intrerupts...?
    Darrel came up with a terrific piece of code for my project - have a look at this thread:

    http://www.picbasic.co.uk/forum/showthread.php?t=17299

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


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Hi,
    I guess you COULD use ADCIN but it kind of defeats the purpose of the interrupt since it is a self timed command.

    When using ADC interrupts you basically set the GO/DONE bit to start the converstion and the interrupt fires when the ADC conversion is done. If you then use ADCIN in the interrupt handler it would perform another, self-timed, conversion which, again, kind of defeats the use of interrupts in the first place.

    The idea is to start the conversion and then either go to sleep or go do something important while the ADC does its job. The interrupt fires when the conversion is complete and you go grab the result by reading ADRESH/ADRESL register pair.

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Thanks Henrik. I've never done A/D conversion before other than through ADCIN but I guessed it wouldn't make sense to use in an interrupt. I'll have to do a search on 'ADRESH' to see how to read the result when I turn the trim pot dial.

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    I've set up and ADC interrupt using DT_INST-14 with the following handler code:

    Code:
    ' ***************************************************************
    ' [A/D - interrupt handler]
    ' ***************************************************************
    ADC_change:
      PAUSEUS 50              ' Wait for A/D channel acquisition time
      ADCON0.1 = 1           ' Start conversion
      WHILE ADCON0.1       ' Wait for it to complete
      WEND
      ADCInVal = ADRESH
    
    @ INT_RETURN
    Is that right? I just need 8-bit ADC resolution (0-255)

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


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Hi,
    Well, that too defeats the purpose of using the interrupt in the first place since you trig the conversion and sit around waiting for it to complete while IN the interrupt handler. You could just as well have used ADCIN in the ISR.

    One thing we need to get squared away just so we're clear. Your ISR is called ADC_Change and from that I get the feeling that you might think the ADC interrupt fires when the voltage at the input changes - that's not the case. If that was already obvious to you then I appologise, I just wanted to clarify that.

    You start the conversion from within your main code or possibly from another ISR, whatever. Then, instead of sitting around waiting for the duration of the conversion you go do something else or go to sleep to provide a quiet environment for the ADC. The interrupt then fires when the conversion is complete and all you need to do in the ISR is grab the result by reading ADRESH, just like you're doing now.

    As you probably know using, when using DT-ints, PBP needs to do a whole lot of context saving/restoring when entering/exiting the ISR and this takes time. So it might not even be worth it using interrupts as the time taken to enter and exit the ISR could very well be longer than the ADC conversion time. I don't know for sure, and it depends, just saying..... If reading the result is all you're going to do in the ISR then you can probably get away with an ASM type handler still written in PBP which will be much quicker to get in and out of - but that's always "risky" so lets not go there untill you have something that works and does what you need.

    /Henrik.

  7. #7


    Did you find this post helpful? Yes | No

    Default Re: Instant Interrupts - Revisited

    Thanks for your detailed reply, Henrik. In the past, I've just used a GOSUB in the main loop and in the subroutine call ADCIN and compare the current value to a previous value; if it's different, I use that 8-bit value to set a PWM duty cycle to brighten/dim an LED. For this project, I thought it might be more efficient to set up an AD_INT interrupt which I thought would be triggered whenever I turn the dial on the trim pot and hence slightly more efficient. I think I see now that I'm wrong in what I thought would trigger this interrupt and that I guess I have to go back to the GOSUB approach.

Similar Threads

  1. Clock using Instant Interrupts
    By PICpocket in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 16th February 2009, 21:43
  2. DT instant interrupts with mister_e keypad
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 26th November 2008, 20:02
  3. DT's Instant Interrupts trouble
    By Tomexx in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th November 2008, 20:48
  4. Keypad and DT's Instant Interrupts
    By Homerclese in forum General
    Replies: 11
    Last Post: - 27th April 2007, 06:32
  5. Replies: 1
    Last Post: - 1st November 2006, 03:11

Members who have read this thread : 8

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

Tags for this Thread

Posting Permissions

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