![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| I am using timer1 of a pic 16f886 to make a clock. However, the interrupt code only runs once. I think I have to clear the interrupt flag to get it to run again? Do I also have to reset the timer, or does it rollover itself? Also, do i need to disable the timer to clear the interrupt flag? And can i get the timer running again while im still in the interrupt code (don't want to lose any time)? Thanks, Scott | |
| |
| | (permalink) | ||||
| Quote:
EDIT: Incorrect. See rest of thread. Quote:
Quote:
Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 18th August 2008 at 03:55 PM. | |||||
| |
| | (permalink) |
| You have to clear the interrupt flag (PIR1,TMR1IF - NOT PIE1,TMR1IE) in the interrupt. The timer will just keep running and interrupt whenever it rolls over. If you want it to interrupt after a certain count then have a read about the CCP module, especially the special event trigger. Mike. | |
| |
| | (permalink) |
| | |
| |
| | (permalink) |
| You're correct Mike (Pommie). Clear the flag to prevent another immediate interrupt after the return from interrupt. Mike | |
| |
| | (permalink) |
| Hmm, bcf PIR1,TMR1IF doesn't seem to do the trick. Is this right? | |
| |
| | (permalink) | |
| Quote:
EDIT: Two against one! Sounds like I'm wrong. Oh well. I always cleared the flag anyway, so it never mattered...
__________________ ========================= Futz's Microcontrollers & Robotics ========================= Last edited by futz; 18th August 2008 at 05:21 AM. | ||
| |
| | (permalink) |
| No, that's not correct. Remember the little PWM-32 project bug where I forgot the "pir1.TMR2IF = 0;" instruction? Your code in Main wasn't running because the program was spending all its time in the ISR... | |
| |
| | (permalink) | |
| Quote:
__________________ ========================= Futz's Microcontrollers & Robotics ========================= | ||
| |
| | (permalink) |
| Ok thanks, got it working (for now at least). | |
| |
| | (permalink) |
| As a side note, what is the best way to test if something is zero? I'm doing clrw iorwf Second,0 btfsc STATUS,Z Is there an easier way than that? Last edited by laxmidd50; 18th August 2008 at 05:29 AM. | |
| |
| | (permalink) |
| Yes. As soon as the 'retfie' instruction is executed interrupts are re-enabled and the processor sees what it thinks is a pending interrupt flag which needs to be processed. Last edited by Mike, K8LH; 18th August 2008 at 05:39 AM. | |
| |
| | (permalink) | |
| Quote:
Your code is fine. You could also use movf Second,F and btfsc STATUS,Z instructions if you need to preserve the W register. If the value you want to test is in W then you can use andlw b'11111111' and then test the Z flag. This becomes necessary when you need to test for a zero value from a table lookup because the retlw instruction does not modify the Z flag. Mike Last edited by Mike, K8LH; 18th August 2008 at 05:39 AM. | ||
| |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
| |
| | ||||
| Title | Starter | Forum | Replies | Latest |
| 16F886/16F887 Serial Boot Loader | Mike, K8LH | Micro Controllers | 10 | 29th November 2008 01:16 PM |
| Resetting Timer1 in a PIC | richacm | Micro Controllers | 11 | 14th July 2008 12:37 PM |
| Next kit (maybe) Dragonfly Seven segment & 16F886 | blueroomelectronics | Micro Controllers | 29 | 12th July 2007 09:38 AM |
| Timer1 | richb | Micro Controllers | 5 | 27th November 2006 11:44 PM |
| Interrupts or not interrupts ? That is the question ! | ZERS | Micro Controllers | 9 | 1st March 2005 08:26 PM |