Searching \ for 'counter ???' 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/timers.htm?key=count
Search entire site for: 'counter ???'.

Truncated match.
PICList Thread
'counter ???'
1999\04\03@123349 by Glen

flavicon
face
hi & thanks for your time.
ii am using a 16f84 !
i'm new to ass & this is my first go.
i have written a program "which works" , surprised me too !
but i want to add a counter to count a preset no. of  cycles & then stop
the program when the count is reached! SEE NOTES BELOW

i have tried but been unsucessful!
i don't know what to do next !
any help for a beginner would be appreciated.
below is my attempt.
;***********************************************
;    Notes:     This program is to operate as follows ,        *
; after the zero crossing , start timer  times out then         *
; 2 outputs ( portb bits 4,5 ) toggle (turning off at the end of the  *
; each cycle ) after counting 30 cycles 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)

w       equ     0  ; destination designators
f       equ     1 ; destination designators
z equ 0 ; destination designators
count equ 30 ; counts the number of cycles
;**********************************************************************
;                   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)
loop      call chcycs    ;check for zero crossing
            call sttimer
            call  tog
            call  counter
            btfss status,Z
            goto    loop
           stop goto  stop
;=======================================================================

;                       delay sub-routine
;                       =================
;=============  check start cycle / check finish cycle =============
chcycs btfsc       portb,2           ;check AC input at port b pin 2 for
0
           goto      chcycs            ;check again if still high
lw         btfss     portb,2              ;check AC input at port b pin
2 for 1
            goto     lw              ;check again if still low
            return               ;found zero crossing - rising edge

;********************* delay sub-routines
*******************************
;
;       ============== start timer =============
sttimer  movlw   0x10             ;move 00 hex to register w
           movwf   souter             ;move register w to "outer"
souter  movlw   0x10             ;move 00 hex to register w
           movwf   sinner             ;move register w to "inner"
sinner  decfsz  sinner             ;decrement "inner" each scan, scan
for 0
           goto    sinner             ;loop "inner" until it = 0
           decfsz  souter             ;decrement "outer" each scan,
scan for 0
           goto    souter             ;loop "outer" until it = 0
return

;       ==============toggle outputs =============
tog     bsf     portb,4           ;set portb bit 4 high      }
        bsf     portb,5           ;set portb bit 5 high      }
        call    togs             ;calls 200mS sub-routine   } Toggle
4/5
       bcf     portb,4           ;set portb bit 4 low       }
       bcf     portb,5            ;set portb bit 5 low      }
       call        togf            ;call the delay sub-routine
       btfsc     portb,2      ;skip next if 0
        goto  tog
         return

;       ============== ontime delay =============
togs movlw   0x2              ;move 00 hex to register w
       movwf   outers             ;move register w to "outer"
outers  movlw   0x2             ;move 00 hex to register w
       movwf   inners             ;move register w to "inner"
inners  decfsz  inners             ;decrement "inner" each scan, scan
for 0
       goto    inners             ;loop "inner" until it = 0
       decfsz  outers             ;decrement "outer" each scan, scan
for 0
       goto    outers             ;loop "outer" until it = 0
       return

;       ============== offtime delay =============
togf movlw   0x1              ;move 00 hex to register w
       movwf   outerf             ;move register w to "outer"
outerf  movlw   0x1             ;move 00 hex to register w
       movwf   innerf             ;move register w to "inner"
innerf  decfsz  innerf             ;decrement "inner" each scan, scan
for 0
       goto    innerf             ;loop "inner" until it = 0
       decfsz  outerf             ;decrement "outer" each scan, scan
for 0
       goto    outerf             ;loop "outer" until it = 0
       return

counter decfsz count
;**********************************************************************
 END                     ; directive 'end of program'

THANKYOU VERY MUCH IN ADVANCE
glen

1999\04\06@043640 by Dr. Imre Bartfai

flavicon
face
Hi,

I found some unclarity in the routine "sttimer". It is a bad practice
(even forbidden) to use the same symbol both for a statement label and as
register. You did it at "souter" and "sinner". Such way maybe you enter
into and endless loop such case. The same is for the "ontime delay"
routine, where "inners" and "outers" are misused same way. A register as a
program variable and a statement label as a branch target are completely
different things. Think about it.

I hope this helps.
Imre


On Sun, 4 Apr 1999, Glen wrote:

{Quote hidden}

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