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.

External Interrupt query

Status
Not open for further replies.

swapan

Full Member level 4
Joined
Feb 20, 2009
Messages
199
Helped
27
Reputation
54
Reaction score
24
Trophy points
1,298
Location
Kolkata
Activity points
2,806
Is it possible to execute ADC within ISR and later use the ADC result in the main program like this ?



regards.

Code:
RESET_VECTOR      CODE    0x0000      ; processor reset vector
    goto    start                     ; go to beginning of program


INT_VECTOR        CODE    0x0004      ; interrupt vector location

goto		int_serv

int_serv:
	
	
    movwf  w_temp          ; save off current W register contents
    bcf    STATUS,RP0      ; select bank0
    movf   STATUS,w        ; move status register into W register
    movwf  status_temp     ; save off contents of STATUS register

clrf		temp_adc
movlw		b'01011001'
movwf		ADCON0
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
bsf			ADCON0,GO
btfsc		ADCON0,GO
goto		$-1
movf		ADRES,0
movwf		temp_adc	
bcf		INTCON,INTE		;  Clear Ext. Interrupt flag.

    bcf    STATUS,RP0      ; select bank0
    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




MAIN_PROG         CODE
 

Hi,

which is the microcontroller?? if it is a PIC18F the interrupt vectors are located in 0x08 and 0x18 if i remember.
i advice you to program the stuff in C language. it is easier!!
joseMiguel
 

Hi joseMiguel,

The microcontroller is PIC16F72 whose interrupt vector is at 0004h. I have little knowledge on C. Hence I wrote in assembly.


regards.
 

Is it possible to execute ADC within ISR and later use the ADC result in the main program like this?

The ADC module can be configured to trigger an interrupt (ADIF) when the conversion has completed. If the ADIF is enable (ADIE) you can handle the storage of the ADC value within the ISR.

Reference PIC16F72 Datasheet, pg 54, 10.0 ANALOG-TO-DIGITAL CONVERTER (A/D) MODULE

The following steps should be followed for doing an
A/D conversion:

1. Configure the A/D module:
• Configure analog pins/voltage reference and
digital I/O (ADCON1)
• Select A/D input channel (ADCON0)
• Select A/D conversion clock (ADCON0)
• Turn on A/D module (ADCON0)

2. Configure A/D interrupt (if desired):
• Clear ADIF bit
• Set ADIE bit
• Set GIE bit

3. Wait the required acquisition time.

4. Start conversion:
• Set GO/DONE bit (ADCON0)

5. Wait for A/D conversion to complete, by either:
• Polling for the GO/DONE bit to be cleared
OR
Waiting for the A/D interrupt

6. Read A/D Result register (ADRES), clear bit
ADIF if required.

7. For next conversion, go to step 1 or step 2 as
required. The A/D conversion time per bit is
defined as TAD. A minimum wait of 2 TAD is
required before the next acquisition starts.

BigDog
 

Hi BigDog

What I actually intend to do is taking sample for ADC at a specific position each time i.e. immediately after crossing zero of AC mains. That's why my query 'Is it possible to initiate AD conversion on detecting external interrupt i.e. zero cross pulse'. Please see my code and post your valued comment.

regards

swapan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top