Searching \ for 'tmr0+counter?? wont work!' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: techref.massmind.org/techref/timers.htm?key=count
Search entire site for: 'tmr0+counter?? wont work!'.

Truncated match.
PICList Thread
'tmr0+counter?? wont work!'
1999\04\15@215102 by Glen

flavicon
face
thanks for taking the time & your help!

i'm new to this !
i cant get the tmr0 + counter to work in the 16f84.
i don't know why ?

i am trying to get the tmr0 to turn over every 10 ms
at each tmr0 turnover the counter decrements & when counter = 0 will
stop the program

can anyone help me as to where the problem is ?
columns have been checked & ok !
below is where i'm at:

;  **********************   *
; Notes:   This program is to operate as follows ,                    *
; after the zero crossing , start timer  times out then         *
; 2 outputs ( portb bits 4,5 ) toggle
; after each timeout the counter decrements until 0
;then the outputs stay off       *
;**********************************************************************
list      p=16F84             ; list directive to define processor
#include <p16F84.inc>         ; processor specific variable definitions

__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_OFF & _XT_OSC

;**********************************************************************
;   vars
porta        equ     0x05      ;CPU equates (program memory map)
portb        equ     0x06      ;CPU equates (program memory map)
souter       equ     0x0c     ;
sinner        equ     0x0d     ;
inners        equ     0x0e     ;
outers       equ     0x0f     ;
innerf        equ      0x10     ;
outerf        equ     0x11     ;
timfin         equ     0x12     ;
starttmr     equ     0x13     ; free reg ??
status         equ     0x03    ;CPU equates (program memory map)
w               equ     0          ; destination designators
f               equ         1         ; destination designators
z                 equ     0         ; destination designators

;**********************************************************************
;                   porta set-up
           org         0x000             ;address 000 program start
start      movlw    0xff              ;ff hex moved to w register
           tris           porta             ;porta set as inputs
;
;**********************************************************************
;                    portb set-up
       movlw   0x0c              ;00001100 hex moved to w register
       tris        portb             ;portb set outputs 0,1,4,5,6,7,
inputs 2,3
;
;**********************************************************************
;       ============== program start =============
       movlw     0x00              ;move 00 hex to register w
        movwf     portb             ;move register w to portb (clear
portb)

; set up timer and prescaler regs
        movlw     b'10010111' ; prescaler setup for 1:256
        option


           movlw      125
            movwf      starttmr          ; 125 * 10ms -> 250ms

initmr     movlw      -156
            movwf      TMR0           ; 156 * prescaler(256) * (4MHz)
=> 10ms approx

loop   call chcycs          ;check for zero crossing  SUB ROUTINE NOT
INCLUDED
        call sttimer          ;start first timer             SUB
ROUTINE NOT INCLUDED
        call  tog              ;toggle outputs             SUB ROUTINE
NOT INCLUDED

; check timer
        movf     TMR0,w      ;move timer value to w
        btfsc     status,z     ; if not 0, goto loop
        goto     loop

; timed out, so check for end
; get here every 10ms

            decfsz     starttmr,f             ;decrement starttmr value

            goto         initmr              ; go around for next delay

; done, drop thru to stop program

stop     goto stop

;subroutines not included

end

;thanks once again for your help !
glen

1999\04\15@225036 by Mike Henning

flavicon
face
{Quote hidden}

The above should only be 25 for 250 ms

>
>initmr     movlw      -156
>             movwf      TMR0           ; 156 * prescaler(256) * (4MHz)
>=> 10ms approx
>
You're calculating using a 4 Mhz clock
The TMR runs at clock/4 = 1 microsecond per TMR tick at 4 Mhz
The above should be coded as:
initmr    movlw    .215
           movwf    TMR0

This will cause the TMR to rollover to 0 aprox. every 10.2 ms.
40 x .000256 = 10.24 ms


{Quote hidden}

You may want to use the TMR interupt flag to check for rollover.
   btfss    TMR0IF    ;If TMR0 flag is set then TMR0 rolled to 0
   goto    loop
   bcf    TMR0IF    ;clear flag
{Quote hidden}

1999\04\20@130657 by electme

flavicon
face
Mike Henning wrote:

***************
thanks for your help mike
i appreciate it
glen

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