Searching \ for '[PIC]: 16F870 TimerX Problems' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/time.htm?key=time
Search entire site for: '16F870 TimerX Problems'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: 16F870 TimerX Problems'
2001\08\28@221406 by Nick Veys

flavicon
face
Been trying to get a timer to fire off on my 16F870 for a while now...

I tried TMR0 since I had experience setting it on from my 16F84a.  Here
are the steps I take:

Set up TMR0 configuration stuff, prescalar, etc. (watchdog disabled of
course)
Enable T0 interrupt
Enable Global Interrupts

wait for the magic to happen.  nothing.  is there something I'm missing
on the 16F870 to get a timer to go off?  My code worked fine on my 16F84
so I just changed it to fit a 870...

So I nuked that code, and tried to use TMR1 since it was 16 bit and
would be a bit slower to work with.  Here's my setup (I saved the code
this time! :)

*snip*

 movlw 0x24                                    ; W <- 0010 0100
 movwf T1CON                                   ; set T1CON (PS=4,
Internal OSC)
 clrf TMR1H                                    ; clear timer
 clrf TMR1L                                    ; clear timer
 BANK1                                         ; bank1 macro
 bsf PIE1,TMR1IE                               ; enable TIMER1
interrupt
 BANK0
 bsf INTCON,GIE                                ; enable global
interrupts

*snip*

org 4

ISR
 movwf W_TEMP                                  ; Copy W to TEMP
register
 swapf STATUS,w                                ; Swap status to be
saved into W
 clrf STATUS                                   ; bank 0, regardless of
current bank, Clears IRP,RP1,RP0
 movwf STATUS_TEMP                             ; Save status to bank
zero STATUS_TEMP register
 movf PCLATH,w                                 ; Only required if using
pages 1, 2 and/or 3
 movwf PCLATH_TEMP                             ; Save PCLATH into W
 clrf PCLATH                                   ; Page zero, regardless
of current page

 incf EIGHTTEEN,f                              ; counter++
 movlw 18
 subwf EIGHTTEEN,w
 btfss STATUS,C                                ; if EIGHTTEEN < 18
   goto ISR_DONE                               ; do nothing
 incf MINUTES                                  ; otherwise do this

ISR_DONE
 movf PCLATH_TEMP,w                            ; Restore PCLATH
 movwf PCLATH                                  ; Move W into PCLATH
 swapf STATUS_TEMP,w                           ; Swap STATUS_TEMP
register into W
 movwf STATUS                                  ; Move W into STATUS
register
 swapf W_TEMP,f                                ; Swap W_TEMP
 swapf W_TEMP,w                                ; Swap W_TEMP into W
 bcf PIR1,TMR1IF                               ; handle TMR1 flag
 retfie

*snip*

and nothing happens, MINUTES never gets incremented, nor does TMR1H/L as
I've outputted them as well...

Any thoughts?  This is confusing me as this should be totally simple!

All hail PICLIST :)

Thanks... -- Nick Veys

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email spam_OUTlistservTakeThisOuTspammitvma.mit.edu with SET PICList DIGEST in the body


2001\08\28@224339 by Tony Nixon

flavicon
picon face
Nick Veys wrote:
>
> Been trying to get a timer to fire off on my 16F870 for a while now...
>
> I tried TMR0 since I had experience setting it on from my 16F84a.  Here
> are the steps I take:
>
> Set up TMR0 configuration stuff, prescalar, etc. (watchdog disabled of
> course)
> Enable T0 interrupt
> Enable Global Interrupts

This should work...

       org 0h              ; startup vector = 0000

       goto Start

       org 4h

       ; save registers etc.
       bcf INTCON,T0IF
       ; do something
       ; restore registers
       retfie

;
; ----------
; CODE START
; ----------
;
Start   ; port setups etc.


       bsf STATUS,RP0
       movlw b'10000000'
       movwf OPTION_REG   ; prescale = 1:2 = TMR0 = INT
       bcf STATUS,RP0     ; ram page 0
       clrf PCLATH


       clrf TMR0
       clrf INTCON
       bsf INTCON,T0IE
       bsf INTCON,GIE
here    nop                ; jumps to IRQ on TMR0 overflow
       goto here





--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
.....salesKILLspamspam@spam@bubblesoftonline.com

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email listservspamKILLspammitvma.mit.edu with SET PICList DIGEST in the body


2001\08\28@233418 by Dan Michaels

flavicon
face
Nick Veys wrote:
>Been trying to get a timer to fire off on my 16F870 for a while now...
>
>I tried TMR0 since I had experience setting it on from my 16F84a.  Here
>are the steps I take:
>
>Set up TMR0 configuration stuff, prescalar, etc. (watchdog disabled of
>course)
>Enable T0 interrupt
>Enable Global Interrupts
>
>wait for the magic to happen.  nothing.  is there something I'm missing
>on the 16F870 to get a timer to go off?  My code worked fine on my 16F84
>so I just changed it to fit a 870...
.........>


Nick, I did not parse your code, but here is a suggestion for
the next time you're beating your head against the wall over
something like this. Simplify it to 1 step at a time. Do the
timer stuff, and get it working correctly via polling the IF
flag without doing the interrupts. Once that is good, then add
in the interrupt stuff.

- dan

--
http://www.piclist.com#nomail Going offline? Don't AutoReply us!
email .....listservKILLspamspam.....mitvma.mit.edu with SET PICList DIGEST in the body


2001\08\29@011441 by Nick Veys

flavicon
face
Still no go :(

Here's what I have verbatim:

***************************************************************

org 0

 goto MAIN

org 4

ISR
 MOVWF W_TEMP ;Copy W to TEMP register
 SWAPF STATUS,W ;Swap status to be saved into W
 CLRF STATUS ;bank 0, regardless of current bank, Clears IRP,RP1,RP0
 MOVWF STATUS_TEMP ;Save status to bank zero STATUS_TEMP register
 MOVF PCLATH, W ;Only required if using pages 1, 2 and/or 3
 MOVWF PCLATH_TEMP ;Save PCLATH into W
 CLRF PCLATH ;Page zero, regardless of current page

 bcf INTCON,T0IF

 MOVF PCLATH_TEMP, W ;Restore PCLATH
 MOVWF PCLATH ;Move W into PCLATH
 SWAPF STATUS_TEMP,W ;Swap STATUS_TEMP register into W
 ;(sets bank to original state)
 MOVWF STATUS ;Move W into STATUS register
 SWAPF W_TEMP,F ;Swap W_TEMP
 SWAPF W_TEMP,W ;Swap W_TEMP into W
 retfie

;-----------------------------------------------------------------------
-----------------
; Mainline
;-----------------------------------------------------------------------
-----------------

MAIN
 BANK1                                         ; set up registers
 movlw 0x85                                    ; W <- 1000 0101
 movlw OPTION_REG ^ 0x80                       ; set OPTION_REG
(prescalar=64, no _RBPU)
 BANK0

 clrf TMR0
 clrf INTCON
 bsf INTCON,T0IE
 bsf INTCON,GIE

; VARIOUS VARIABLE INITIALIZATION

 LCD_INITIALIZATION                            ; setup the LCD for
us...
 LCD_CLEAR                                     ; clear it out

TESTLOOP
 DELAY_MILLI 100
 movf TMR0,w
 call LCD_OUT_DATA
 LCD_PRINT 'A'
;  LCD_CLEAR
 goto TESTLOOP

***************************************************

Cut and dry, once everything is set up, I output the TMR0 value (comes
out in HEX) to my LCD, along w/a test character to make sure it's alive.
The HEX changes with every startup, but never changes during my looping,
I always get some random HEX value, and an 'A' printed...

I've also tried adding a variable, having the ISR increment that
variable, and outputting THAT instead on TMR0, in which case that
variable always outputs 0x00 since I initialize it in the beginning...

:( I don't get it, it should be super simple!

> {Original Message removed}

2001\08\29@014546 by Tony Nixon
flavicon
picon face
Nick Veys wrote:
>
> Still no go :(
>
> Here's what I have verbatim:

As was pointed out earlier, try deleting the LCD stuff and just test a
TMR0 interrupt.

Test in in MPLAB first.

If that works, start adding the LCD stuff again and test in a real chip.


--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
EraseMEsalesspam_OUTspamTakeThisOuTbubblesoftonline.com

--
http://www.piclist.com hint: To leave the PICList
piclist-unsubscribe-requestspamspam_OUTmitvma.mit.edu


2001\08\29@020847 by Tony Nixon

flavicon
picon face
Nick Veys wrote:
>
> Still no go :(
>
> Here's what I have verbatim:

> MAIN
>   BANK1                                         ; set up registers
>   movlw 0x85                                    ; W <- 1000 0101
>   movlw OPTION_REG ^ 0x80                       ; set OPTION_REG
   ^^^^^

Should be

   movwf OPTION_REG



--
Best regards

Tony

mICros
http://www.bubblesoftonline.com
@spam@salesKILLspamspambubblesoftonline.com

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestKILLspamspammitvma.mit.edu


More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...