Searching \ for '[PIC]: tmr0 as a counter in MPLAB (16F876)' 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=count
Search entire site for: 'tmr0 as a counter in MPLAB (16F876)'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: tmr0 as a counter in MPLAB (16F876)'
2002\06\30@211932 by Irek Rybark

flavicon
face
Hi all,
I ran into problems trying to simulate tmr0 as a counter in MPLAB.

I want to count pulses on RA4/T0CKI [low kHz].

The problem is that the counter register tmr0 is incremented every
instruction cycle when input signal (RA4) is high and is stopped when the
input is low.
I expect "counting input signal edges" rather than enabling internal fosc/4
as a pulse source.

The timer is configured as follows:
       banksel OPTION_REG
       movlw   b'11110000'     ; prescaler=1:1 assigned to timer0
       movwf   OPTION_REG      ; source: T0CKI/RA4, inc on hi->low

       banksel TMR0
       clrf    TMR0

To simulate the above I am using Pin Asynchronous Stimulus.
I defined the following two pin stimuli: the first RA4=high, the second
RA4=low

Simply: I don't get it!

Is there any known issue in MPLAB or I don't understand how tmr0 or pin
stimulus should work?

I appreciate any feedback

Ira

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


2002\06\30@221011 by Andrew Errington

flavicon
face
> I appreciate any feedback

Hi,

there are three things I think you should do.

1) Double check the assembler output to be sure your banksel macros are
working, and that the OPTION setup code is correct
2) Verify that a 1:2 ratio on TMR0 is okay (because that's what the data
sheet says you get with 000 in PS2..PS0, you only get 1:1 with a WDT
assignment).
3) Verify that the TRIS register for RA4 is correct, and that you can
see the pin state change in a watch window.

These are the obvious things to check, but I don't use the '87x series
so I've never tried them in MPLAB.  I haven't looked for errata for this
topic with MPLAB (too much to sort through...)

Hope this helps,

Andy

--
http://www.piclist.com hint: To leave the PICList
.....piclist-unsubscribe-requestKILLspamspam@spam@mitvma.mit.edu


2002\06\30@230521 by Irek Rybark

flavicon
face
Andrew:
Thanks for the hints.
I found the problem!
Your third point of the checklist focused my attention on PORTA!

FYI:
The following code doesn't work:

       Bank0
       clrf    PORTA
       Bank1_0
       movlw   0x06            ; configure all pins as
       movwf   ADCON1          ;   as digital inputs
       movlw   0xcf            ; configure all pins as
       movwf   TRISA           ;   as inputs

Where:
Bank0           MACRO                   ;macro to select data RAM bank 0
               bcf     STATUS,RP0
               bcf     STATUS,RP1
               ENDM
Bank1_0 MACRO                   ;macro to change data RAM from bank 0 to bank 1
               bsf     STATUS,RP0
               ENDM

The problem here is probably in line
       movlw   0xcf            ; configure all pins as
which is incorrect, because TRISA has only 6 significant bits.

I've changed it to:
       movlw   0x3f
and it works fine.

Kinda weird... It looks that this unexpected bit messed up MPLAB's brain.

Thanks a lot!

Ira (just a PIC-beginner)




> {Original Message removed}


'[PIC]: tmr0 as a counter in MPLAB (16F876)'
2002\07\01@043452 by Alan B. Pearce
face picon face
>3) Verify that the TRIS register for RA4 is correct,
>and that you can see the pin state change in a watch window.

or the Special Function Registers window, where you will also see the timer
register.

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\07\01@074916 by Olin Lathrop

face picon face
> The problem is that the counter register tmr0 is incremented every
> instruction cycle when input signal (RA4) is high and is stopped when the
> input is low.
> I expect "counting input signal edges" rather than enabling internal
fosc/4
> as a pulse source.
>
> The timer is configured as follows:
>         banksel OPTION_REG
>         movlw   b'11110000'     ; prescaler=1:1 assigned to timer0

If you're going to hard code the binary value, you should at least document
what each of the bits mean:

         movlw   b'11110000'
                 ; 1-------  port B pullups disabled
                 ; -1------  select rising edge for RB0 int
                 ; --1-----  timer 0 clock source is RA4
                 ; ---1----  select rising edge for RA4 clock
                 ; ----0---  assign prescaler to timer 0
                 ; -----000  set timer 0 prescaler to 2

Note that it is not possible to assign the prescaler to timer 0 and get a
divide value of 1.  If you want that (no prescaler), then you have to assign
it to the watchdog timer.

>         movwf   OPTION_REG      ; source: T0CKI/RA4, inc on hi->low
>
>         banksel TMR0
>         clrf    TMR0
>
> To simulate the above I am using Pin Asynchronous Stimulus.
> I defined the following two pin stimuli: the first RA4=high, the second
> RA4=low

First, check to make sure OPTION is still set the way you intended it.
Timer 0 shouldn't be able to increment more than once every 2 instructions
because you actually have the prescaler set to 2:1, so something else is
wrong in addition to a possible clock source problem.  Second, check how
fast MPLAB is supposed to be repeating your high-low sequence on RA4.  I use
this feature so infrequently that I don't remember how that works.


*****************************************************************
Embed Inc, embedded system specialists in Littleton Massachusetts
(978) 742-9014, http://www.embedinc.com

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2002\07\01@091524 by Irek Rybark

flavicon
face
Olin & Alan:

Thanks for the response.  Luckily I already found the problem.
It is described in my yesterday's post:
http://www.piclist.com/postbot.asp?id=piclist\2002\06\30\230521a

> {Original Message removed}

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