Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Can increment TMR0 in 16f84a using MPLAB

Status
Not open for further replies.

daniel2004

Newbie level 1
Joined
Dec 24, 2004
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
25
tmr0 in 16f84a

Hi I have a dumb question, i think I am missing something very basic here.

I cant seem to get TMR0 to increment in MPLAB, and i don't think it is working in the PIC either. First I setup the Option_Reg, and set T0CS, in order to turn the timer off. When I want the timer to count I clear T0CS so the timer will increment off the internal clock. This dosnt happen. By my reading of the data sheet the Timer should increment in this mode no matter what. I have checked in MPLAB that all bits are been set and cleared as they should be, still no luck. I hope someone here could shed some light on this.

Thanks
Daniel

#define Processor 16F84A

LIST P=16F84A;, F=INHX8M
#include <P16F84A.inc>

__config _CP_OFF & _PWRTE_OFF & _WDT_OFF & _HS_OSC


;************************************************************
; MEMORY EQUATES
;************************************************************

W_Temp EQU 0x20
STATUS_Temp EQU 0x21
Delay EQU 0x22

;************************************************************
; Reset and Interrupt Vectors

ORG 0x0000 ;Reset Vector
GOTO Start

ORG 0x0004 ;Interrupt vector
GOTO IntVector

;************************************************************
; Program begins here

ORG 0x005
Start
BSF STATUS, RP0
MOVLW h'FF'
MOVWF TRISA
CLRF TRISB
BSF TRISB, 7
BSF TRISB, 6

BSF OPTION_REG, T0CS ;Timer0 not running
BSF OPTION_REG, T0SE ;Rising edge
BCF OPTION_REG, PSA ;Use tmr0 for prescaler
BSF OPTION_REG, PS2 ;Maximum prescaler
BSF OPTION_REG, PS1
BSF OPTION_REG, PS0
CLRF INTCON ;Start fresh
BCF INTCON, T0IE ;Enable TMR0 Interupt
BCF INTCON, T0IF ;Clear TMR0 Flag
BCF STATUS, RP0 ;Bank0
CLRF TMR0
BSF INTCON, GIE
GOTO Main

Main
; BTFSS PORTA, 1
; GOTO Main
CLRF PORTB
BSF PORTB, 0
BSF STATUS, RP0
BCF OPTION_REG, T0CS ;Start TMR0
BCF STATUS, RP0
a MOVF Delay, W
SUBLW d'76'
BTFSS STATUS, Z
GOTO a
BSF STATUS, RP0
BSF OPTION_REG, T0CS ;Stop TMR0
BCF STATUS, RP0
CLRF TMR0
BSF PORTB, 1
; GOTO Main

Main_a
GOTO Main_a

IntVector
BSF PORTB, 3
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

INCF Delay
CLRF TMR0
BCF INTCON, T0IF

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

end
 

stop tmr0

Hi,

I haven't gone through your code as it is almost 4 AM where I am,
but there is a note in the 16F84A datasheet that says:

"Writing to TMR0 when the prescaler is
assigned to Timer0 will clear the prescaler
count, but will not change the prescaler
assignment." (page 19)

Could it be that you are resetting your count all the time?

Good night...
/Rambo
 

Re: tmr0 in 16f84a

Hai
Also check weather timer0 counts internal clock or external pulse from it's input pin. that is the probabile thing.
Picstudent
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top