use of Timer1 and portA interrupts together


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: use of Timer1 and portA interrupts together

    I just realized that having both LEDs on means that they trigger too fast. Is it possible that activating Interrupt on Change on PORTA I affect my TIMER1 prescaler somehow?

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: use of Timer1 and portA interrupts together

    You have enabled Interrupt On Change (INTCON.3), External interrupt (INTCON.4) and Timer1 Ints (PIE1.0).
    But the ISR only clears the flag for Timer1. So it will be continuously interrupting when the other interrupts get triggered.

    It needs to differentiate between the different interrupts, run separate code depending on which one fired, and clear the appropriate flags before resuming.

    Remember that with Int On Change you have to read the port to clear the mismatch condition before you can clear the flag.
    DT

  3. #3
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: use of Timer1 and portA interrupts together

    Hello Darrel,

    Strange why my interrupts on change affect the timer if I do not press buttons, but yes, clearing those flags makes the timer interrupts work better with regular intervals. Also I added IF PIR!.0 condition in the interrupt handler, but it seems not working well. if interrupt on change flags are not cleared I still have irregular time interwals - probably because of skipping timer handler when other interrupts trigger I do not know what is the reason.

    if this something to do with oscillator mode? I use internal osc at 4 MHz, PORTA uses inputs on A.2 and A.5 and A.4 is analog
    PORTC is used bor DEBUGIN on C.! and others are outputs

    I noticed it works better with HS setting for oscillatio for timer interrupt and Int on change seems need INTOSCIO which mode is correct?

    Thanks again,
    Alexey

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: use of Timer1 and portA interrupts together

    Did you add IF tests for all the interrupts you are using? (IOC and INT)
    Are you sure you want to use INT? The INT pin is also an IOC pin.

    For a 4Mhz crystal, you would use the XT oscillator mode.
    The oscillator mode has no effect on IOC interrupts.
    And whether it's internal or external, as long as the OSC is 4mhz, it has no effect on the Timer interrupts either.
    DT

  5. #5
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: use of Timer1 and portA interrupts together

    Hello Darrel,

    Yes, I already learnt that interrupts require a great attention and careful programming Sometimes I could not understand why I am getting different results with (on my opinion) same approach but probably just one little thing outside of my attention makes all difference. I just noticed that simple use of SLEEP in a branch that is not executed when my TIMER1 is used does not allow timer to work Simple commenting SLEEP in that branch restores work of the TIMER1. Not sure why. Maybe if I use sleep, PICBASIC reserves the timer1 for it, although I thought it uses TIMER0 (will look how WDT affects this - maybe I had it disabled - will check)
    I use interrupt on change on PORTA.5 and RA2/INT on PORTA.2 which helps to filter when A.2 button pressed and when I have signal on A.5 Yes, I do use IFs to handle interrupts

    Oh... how many things I need to learn...

    Thank you for help!
    Last edited by Alexey; - 10th June 2011 at 05:53.

  6. #6
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default Re: use of Timer1 and portA interrupts together

    When a PIC goes to sleep, the primary oscillator is shut down.
    Since Timer1 gets it's clock from the primaray oscillator, it stops too.

    Timer1 can run on an external 32768hz crystal while the PIC is asleep.
    DT

  7. #7
    Join Date
    Dec 2009
    Location
    Canada
    Posts
    68


    Did you find this post helpful? Yes | No

    Default Re: use of Timer1 and portA interrupts together

    Thanks Darrel,

    I am getting crazy with these things... Now I have interrupts from timer working until I call a subroutine. Tried to remove everything from the subroutinemaking it like this:

    gosub test

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