PIC18F4550, A/D Interrupts, Assembly Language

In summary, the conversation discusses an attempt to make a PIC18F4550 use A/D interrupts to blink an LED at RA1. The frequency of the blinking LED is determined by a potentiometer linked to RA0. However, after 30 cycles, only the Main LED blinks and the Interrupt LED stops responding to potentiometer changes. The code seems to stop interrupting at a certain point and the cause is unknown. The circuit and hardware have been tested and work fine, and resetting the AD Interrupt flag and ADC enable bits has no effect. The code uses an internal oscillator, sets conversion voltage references, and has methods for blinking and delaying. The main code has an infinite loop and enables interrupts globally.
  • #1
El Moriana
33
0
1. What I am trying to do
I am attempting to make a PIC18F4550 use A/D interrupts to blink an LED at RA1. [Interrupt LED]
The frequency of the blinking LED is determined by a potentiometer linked to RA0.
To gauge when the loop is outside of the interrupt routine, I have added an LED at RA2 that is set to blink when the program loops in the main code. [Main LED]

2. The Problem
The Interrupt LED blinks properly, responding to potentiometer changes for 30 or so cycles, after which, only the Main LED blinks, unresponsive to potentiometer changes.
It seems clear that the code no longer interrupts after a point and the main code loops thereafter.
However, I am at a loss at what causes the code to stop interrupting.

The circuit/hardware works fine; I have managed to use the pot to make the LED blink without interrupts (i.e. using a loop waiting for conversion to finish).
I have tried resetting the AD Interrupt flag and ADC enable bits, no effect.

3. Code

Code:
;=========PROGRAM INFORMATION=========
;Designed to sense voltage from pot, convert to digital and use result to set delay time of a blinking LED.
;Run off internal oscillator - 1MHz mode (default int osc)
;Conversion voltage references set to VDD and VSS
;Analog input in RA0
;Blinking LED positioned RA1
;Main loop test-LED positioned RA2 (visual cue of looping main code)

;=========PIC SPECIFIC IMPORTS=========
#include<P18F4550.INC>

;=========CONFIGURATION BITS=========
	CONFIG WDT = OFF 	; watchdog timer off
	CONFIG MCLRE = OFF 	; MCLR pin off, no debugging, no need to set pin hi
	CONFIG DEBUG = OFF	; debug mode off
	CONFIG FOSC = INTOSCIO_EC	; internal oscillator
	CONFIG XINST = OFF	; disable extended instruction set
	CONFIG CP0 = OFF	; disable code protection
	CONFIG LVP = OFF	; disable low voltage programming

;=========VARIABLE DECLARATION=========
Delay1 res 2	;delay loop variables
DelTmr res 2	;delay loop multiplier, will be influenced by result of A/D conversion

;=========VECTORS=========
		;RESET
RESET_VECTOR	CODE	0x0000
		goto	init	; go to initialisation

		;INTERRUPT
INT_VECTOR		CODE	0x0008
		;Blink + Delay
		btg		LATA, LATA1 ; blink RA1
		call 	delay
		
		;Reset interrupt
		;bcf		PIR1, ADIF	; clear A/D interrupt flag [no effect]
		;bsf		PIE1, ADIE	; enable A/D interrupt [no effect]
		bsf		INTCON, GIE	; enable interrupts

		goto	main	; return to main loop

;=========METHODS=========
;DELAY
delay:	movff ADRESH, DelTmr ;move 8bit A/D result to DelTmr
		
		infsnz 	DelTmr, F	; make sure no overflows occur
		decf 	DelTmr, F	;

dloop:	decfsz	Delay1
		goto 	dloop
		decfsz	DelTmr
		goto	dloop

		return

;=========INITIALIZATION=========
		;Pins
init:	clrf	PORTA	; clear porta
		clrf 	TRISA	; porta > outputs
		clrf	LATA	; clear porta latch
		bsf		TRISA, TRISA0	; RA0 > input
		
		;No Internal Osc selection, will keep osc at 1MHz

		;A/D Module
		movlw 	b'00001110'	; AN0 set to analog input + VSS,VDD ref. 
		movwf 	ADCON1		;
		clrf 	ADCON0 		; select AN0 (channel 0) as A/D channel
		movlw 	b'00001000'	; results are left-justified, Tac = 2*Tosc
		movwf 	ADCON2		;
		
		bsf 	ADCON0,ADON ; enable A/D Conversion Module
		
		;Interrupts
		bcf		RCON, IPEN	; disable interrupt priority
		bsf		INTCON, PEIE	; enable peripheral interrupts
		bcf		PIR1, ADIF	; clear A/D interrupt flag
		bsf		PIE1, ADIE	; enable A/D interrupt
		bsf		INTCON, GIE	; enable interrupts globally
		
;=========MAIN CODE=========
main:	bsf 	ADCON0, GO_DONE ; start A/D Conversion

inf:		
		btg		LATA, LATA2 ; blink RA2
		call 	delay		;

		goto 	inf	; infinite loop

		END
;=========END OF CODE=========
 
Physics news on Phys.org
  • #2
I might be able to help you. can you show me the circuit you drew?
 
  • #3
NP
 

Related to PIC18F4550, A/D Interrupts, Assembly Language

1. What is the PIC18F4550 microcontroller?

The PIC18F4550 is a popular microcontroller from Microchip, commonly used in embedded systems and electronic devices. It has a 8-bit RISC architecture and offers a wide range of features such as USB communication, analog-to-digital conversion, and multiple I/O ports.

2. What is an A/D interrupt and how does it work?

An A/D interrupt is a type of interrupt used in microcontrollers to handle analog-to-digital conversion. It is triggered when the A/D converter finishes converting an analog signal into a digital value, and it can be used to pause the main program and handle the converted data. This allows for more efficient use of the microcontroller's resources.

3. What is assembly language and why is it used in PIC18F4550 programming?

Assembly language is a low-level programming language that uses mnemonic codes to represent machine instructions. It is specific to a particular type of processor, in this case the PIC18F4550. Assembly language is used in PIC18F4550 programming because it allows for direct control over the hardware and can result in more efficient and faster code execution.

4. How can I enable A/D interrupts on the PIC18F4550?

To enable A/D interrupts on the PIC18F4550, you first need to configure the A/D converter and the interrupt settings in the microcontroller's registers. This involves setting the appropriate bits in the ADCON0 and ADCON1 registers, as well as the interrupt enable bit in the INTCON register. You will also need to define the interrupt service routine (ISR) to handle the interrupt.

5. Can A/D interrupts be used in conjunction with other interrupts on the PIC18F4550?

Yes, A/D interrupts can be used simultaneously with other interrupts on the PIC18F4550. However, it is important to prioritize interrupts and handle them appropriately in the ISR. For example, if a higher priority interrupt occurs while the A/D interrupt is being handled, the A/D interrupt should be paused and the higher priority interrupt should be handled first.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Programming and Computer Science
Replies
3
Views
1K
  • Electrical Engineering
Replies
2
Views
2K
  • Electrical Engineering
Replies
9
Views
2K
  • Electrical Engineering
Replies
10
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
7K
  • Electrical Engineering
Replies
2
Views
966
  • Programming and Computer Science
Replies
4
Views
2K
Back
Top