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.

need help about saving and retrieving the W reg during interrupt handling in assembly

Status
Not open for further replies.

Noman Yousaf

Full Member level 4
Joined
Nov 19, 2003
Messages
210
Helped
3
Reputation
6
Reaction score
2
Trophy points
1,298
Location
Lahore Pakistan
Activity points
1,774
urgent help is needed please

i am facing the problem that in my software (in assembly language).
i am using timer interrupt in 16f72. there is some calculation which is done by w reg.
during calculation, when timer interrupt occurs, the value of w reg is disturbed.
when w reg goes to work for interrupt, then comes back after ISR, value has been changed.
actually problem is, when interrupt occurs, on very next step when i have to save the the w reg in any file reg, value of w reg is changed before even go to ISR (interrupt service routine).
so wrong value of w reg is saved.
please tell the appropriate solution to save then retrieve the value of w reg.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
19,475
Helped
4,306
Reputation
8,617
Reaction score
4,262
Trophy points
1,393
Activity points
129,131
Hi,

When entering isr w reg is unchanged --> before you use it in isr push it on stack
Before leaving isr pop w reg from stack.

Klaus
 

betwixt

Super Moderator
Staff member
Joined
Jul 4, 2009
Messages
14,871
Helped
4,860
Reputation
9,738
Reaction score
4,643
Trophy points
1,393
Location
Aberdyfi, West Wales, UK
Activity points
126,579
You have not stated which assembler you are using. Assuming it is MPLAB or MPLABX, look in the templates for the best way to do it. You should also save the STATUS register because it holds the bank select bits, if you change those the ISR will return to the wrong address. As a general rule, always copy the template file then build the rest of your code around it.

This is an extract of Microchip's template for the 16F72:
Code:
;***** VARIABLE DEFINITIONS
w_temp		EQU	0x20		; variable used for context saving
w_temp1		EQU	0xA0		; reserve bank1 equivalent of w_temp 
status_temp	EQU	0x21		; variable used for context saving

;**********************************************************************
	ORG     0x000             ; processor reset vector

  	goto    main              ; go to beginning of program


	ORG     0x004             ; interrupt vector location

	movwf   w_temp            ; save off current W register contents
	movf	STATUS,w          ; move status register into W register
	bcf     STATUS,RP0        ; ensure file register bank set to 0
	movwf	status_temp       ; save off contents of STATUS register


; isr code can go here or be located as a call subroutine elsewhere


	bcf     STATUS,RP0        ; ensure file register bank set to 0
	movf    status_temp,w     ; retrieve copy of STATUS register
	movwf	STATUS            ; restore pre-isr STATUS register contents
	swapf   w_temp,f
	swapf   w_temp,w          ; restore pre-isr W register contents
	retfie                    ; return from interrupt

Brian.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top