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.

Elementary Offset problem. Please help!

Status
Not open for further replies.

PotatoPeeler

Newbie level 2
Joined
Apr 16, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,300
Hello I am a student that are a complete novice.

I have written a code in Assembler that works, except for one thing.

The offset value that I have entered for TMR0 never appears in TMR0 if I simulate! So I am doing it wrong.

I am using P16F84A (Use MPLAB and PIC Simulator to write code.).
I am using TMR0 is timer and not the WDT.

If have never noticed before that my offset values are not entered in TMR0; because I have only had to work with very small offset values, so I didn't notice errors. I can not find anything on the net to explain how to enter offset correctly.

Here is part of my code with an example of how I entered all my offset values:

START BSF STATUS,RP0
CLRF TRISA ;Make all outputs
CLRF TRISB ;Redandant part.

MOVLW B'00010110' ;INPUTS RB1, RB2 AND RB4!
MOVWF TRISB

MOVLW B'10000001'
MOVWF OPTION_REG ; Redundant part

MOVLW B'10101000'
MOVWF INTCON ;Interupt Setup

BCF STATUS,RP0
CLRF PORTA
CLRF PORTB ;PORT A & B start at 0

BSF STATUS,RP0
MOVLW B'10000001'
MOVWF OPTION_REG ;PRESCALER=4
BCF STATUS,RP0
MOVLW B'00001000' ;******This part doesnt work!
MOVWF TMR0 ;******OFFSET=8

MAIN GOTO MAIN


END
 

I have simulated the code and it works just fine?????

MOVLW B'00001000' ;******This part does work!
MOVWF TMR0 ;******OFFSET=8
 

I have simulated the code and it works just fine?????

MOVLW B'00001000' ;******This part does work!
MOVWF TMR0 ;******OFFSET=8

Thanks.

Got the problem. It was in when I entered the offset is the interrupt service routine.

I still do not understand how offset works though.

If I enter offset just before I return from interrupt it works just fine, If I enter it early in my ISR it does not8O.
 

The timer does not stop incrementing while you are in the interrupt.
If you pre-load the timer at the beginning of the interrupt, depending on the pre-scale value, it may have incremented by the end of it.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top