Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

cannot find the errors???

Status
Not open for further replies.

falleafd

New Member
Code:
;---------------------------------------------------------------------
TMR0_ISR
;
; NEXT STEP FOR STEPPING AS TMR0 OVERFLOAT
;---------------------------------------------------------------------

				BTFSS	MOTOR_TURN
				RETURN
				BTFSS	MOTOR_DIR
				GOTO	TURNLEFT
				NOP
TURNRIGHT		MOVLW	D'3'
				SUBWF	MTR_INDEX,	W
				MOVLW	D'255'
				BTFSC	STATUS,		C
				MOVWF	MTR_INDEX			; MTR_INDEX = 255
				INCF	MTR_INDEX,	F		; NEXT STEP
				GOTO	END_TMR0_ISR
TURNLEFT		MOVF	MTR_INDEX,	W
				SUBLW	D'0'
				MOVLW	D'4'
				BTFSC	STATUS,		C
				MOVWF	MTR_INDEX			; MTR_INDEX = 4
				DECF	MTR_INDEX,	F		; NEXT STEP
				GOTO	END_TMR0_ISR

END_TMR0_ISR	MOVF	MTR_INDEX,	W
				CALL	STEP_TAB
				BANKSEL	PORTB
				MOVWF	PORTB				; OUTPORT AND LET THE MOTOR TURN
				RETURN
				

;---------------------------------------------------------------------
STEP_TAB
;
; STEP TABLE FOR STEPPING
;---------------------------------------------------------------------
				ADDWF	PCL,		F
				RETLW	B'10000000'
				RETLW	B'01000000'
				RETLW	B'00100000'
				RETLW	B'00010000'

Please help to find the errors and show meeh? The debug run correctly until ADDWF PCL, F?????
 
Oh, don't care bout saving special registers. I saved it. TMR0_ISR is only a routine and I call it from my ISR after check if it's TMR0 overfloat interrupt.

As I debug the program. It's right until WREG is loaded with MTR_INDEX. But as I call the STEP_TAB. I add MTR_INDEX to PCL, but PCL changed unexpectedly. And it jump to itself address until PCL return to 0000 and get back the RESET routine.
 
Can you post the entire project? as a zip file perhaps...
It's easyer to help you if we can see all the code and compile it so we can see how it ends up in memory (this will show things like a table crossing a page limit)
 
1. First, all the entries should be be within the same page.
2. Second, make sure the value of PCLATH register is on the same page as where the "ADDWF PC,F" is.
3. Thirdly, make sure MTR_INDEX value is 0<=MTR_INDEX<=3.

1) Yes, of course, it's in the same page. Because this test is so short. And Page0 is accessed from 0005 to 07ff (I used 16F876A). And I begin the program at 0x050

2) I only work on page0.

3) As you see in the TMR0_ISR, MTR_INDEX is maintained from 0 to 3. And I said the program run oki in debugger until it meets ADDWF PCL, F instruction.

I wrote this type of service for many times, I get no problems, but I don't know why this time?

And it jumped to STEP_TAB routine, but it cannot do ADDWF instruction!!!!

I write this program and note in Vietnamese, so, perhaps you may be confused with my notes. If there are only 3 problems as you say with this types of table. I checked it many times and find it oki. It should be something wrong somewhere else. I'll check my program again.

Thanks for your help.
 
And Page0 is accessed from 0005 to 07ff (I used 16F876A).

FYI, a page for "addwf PC,F" instructions is only 256bytes long. Page0 is from 0 to 0FFh. See section 2.3.1 COMPUTED GOTO of the datasheet.
 
Status
Not open for further replies.

Latest threads

Back
Top