Searching \ for 'counter won't count above 1F' 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 won't count above 1F'.

Truncated match.
PICList Thread
'counter won't count above 1F'
2000\06\01@023752 by markwillcox56

picon face
part 0 220 bytes content-type:application/octet-stream; name="secount.asm"</x-flowed>
Content-Type: application/octet-stream; name="secount.asm"
Content-Disposition: attachment; filename="secount.asm"

Attachment converted: creation:secount.asm (????/----) (00015FCE)

2000\06\01@025508 by Tony Nixon

flavicon
picon face
Mark Willcox wrote:
>
> Hi all
>   I'm trying to understand TMR0. The attached code won't count above 1F.
> When it reaches 1F the counter resets and counts up to 1F again. I thought
> it would count to FF and then reset. Whats wrong with the code?
>   I copied the code from Introduction to PICS.. The original code used RTCC
> instead of TMR0. Could this be the problem?
> Thanks in advance, Mark
> ________________________________________________________________________
> Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com
>
>   ------------------------------------------------------------------------
>                   Name: secount.asm
>    secount.asm    Type: ASM File (application/x-unknown-content-type-asm_auto_file)
>               Encoding: base64

You have used the "p16f84.inc" file, so you don't need to define
these...

PORTB   equ     06
STATUS  equ     03
Z       equ     02
TMR0    equ     01


This defines 'cntr' at the location for the PCLATH register.

cntr    equ     0A

Use the first general purpose RAM location at 0x0C instead.

cntr    equ 0Ch


For your timing loop, try this, by using the T0IF flag.
This is set = 1 when TMR0 overflows from FF - 00.

loop    btfss INTCON,T0IF    ; wait for TMR0 overflow
       goto loop

       bcf INTCON,T0IF      ; clear flag

       incf    cntr,1       ;increment counter file
       movf    cntr,0       ;mov counter file to W
       movwf   PORTB        ;output counter value to PORTB
       goto    loop


Depending on your XTAL (RC) speed, you may only see a blur on PORTB.

To slow things down a little, try this.

TimeL equ 0Dh      ; RAM register 0Dh

       clrf TimeL

loop    btfss INTCON,T0IF    ; wait for TMR0 overflow
       goto loop

       bcf INTCON,T0IF      ; clear flag

       decfsz TimeL
       goto loop

       incf    cntr,1       ;increment counter file
       movf    cntr,0       ;mov counter file to W
       movwf   PORTB        ;output counter value to PORTB
       goto    loop

If it is still too fast, you may need to add a TimeH register in the
loop as well.


--
Best regards

Tony

http://www.picnpoke.com
spam_OUTsalesTakeThisOuTspampicnpoke.com

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