mega16 timer0 compare interrupt problem - Assembler

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am using an ATmega16 on an STK500 and programming in assembler with Studio7 and including the m16def.inc.  My problem is trying to use the timer0 compare interrupt.  When ever I try to build my file I always get an error message "Undefined symbol:tim0_comp" pointing to the entry in the list of interrupt vectors in the CSEG listing of all the interrupts.  The list is straight out of the ATmega16 data sheet PDF so why won't it recognize the label I've used.  I'm beginning to think that there might be an error in the list of interrupts in the PDF file.  I have tried starting again from scratch using the mega16a and m16Adef.inc with the same result.  One way around the problem would be to use timer2 but that would just get around my problem and not fix it.

 

Thanking any replies in advance,    Allan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tim0_comp is not defined in the .inc file.  It is something that YOU define and you can call it anything as long as you have the correct address in the ISR vector and a corresponding ISR.

 

I have these define for the Mega 16, some people prefer having the .org for each vector but I have never had any problems doing it this way.

If you want the .org for each vector just un-comment the line and add .org to it

;Reset and Interrupt vectors mega16
;
.cseg

;$000 
	jmp		RESET 			; Reset Handler
;$002 
	jmp 	ISR_EXT_INT0 	; IRQ0 Handler
;$004 
	jmp 	ISR_EXT_INT1 	; IRQ1 Handler
;$006 
	jmp 	ISR_TIM2_COMP 	; Timer2 Compare Handler
;$008 
	jmp 	ISR_TIM2_OVF 	; Timer2 Overflow Handler
;$00A 
	jmp 	ISR_TIM1_CAPT 	; Timer1 Capture Handler
;$00C 
	jmp 	ISR_TIM1_COMPA 	; Timer1 CompareA Handler
;$00E 
	jmp 	ISR_TIM1_COMPB 	; Timer1 CompareB Handler
;$010 
	jmp 	ISR_TIM1_OVF 	; Timer1 Overflow Handler
;$012 
	jmp 	ISR_TIM0_OVF 	; Timer0 Overflow Handler
;$014 	
	jmp 	ISR_SPI_STC 	; SPI Transfer Complete Handler
;$016 
	jmp 	ISR_USART_RXC 	; USART RX Complete Handler
;$018 
	jmp 	ISR_USART_UDRE 	; UDR Empty Handler
;$01A 
	jmp 	ISR_USART_TXC 	; USART TX Complete Handler
;$01C 
	jmp 	ISR_ADC 		; ADC Conversion Complete Handler
;$01E 
	jmp 	ISR_EE_RDY 		; EEPROM Ready Handler
;$020 
	jmp 	ISR_ANA_COMP 	; Analog Comparator Handler
;$022 
	jmp 	ISR_TWSI 		; Two-wire Serial Interface Handler
;$024 
	jmp 	ISR_EXT_INT2 	; IRQ2 Handler
;$026 
	jmp 	ISR_TIM0_COMP 	; Timer0 Compare Handler
;$028 
	jmp 	ISR_SPM_RDY 	; Store Program Memory Ready Handler

 

then for the ISRs

 

.cseg

;REMEMBER to save any registers you may want to use here!
;Int. flags are automatically cleared.
;
ISR_EXT_INT0:
	in		save_sreg,SREG		;Save Status register
;Do something here	
	out		SREG,save_sreg		;Restore Status register
	reti
;
ISR_EXT_INT1:
	in		save_sreg,SREG		;Save Status register
;Do something here		
	out		SREG,save_sreg		;Restore Status register
	reti
;
ISR_TIM2_COMP:
	in		save_sreg,SREG				;Save Status register
;Do something here
	out		SREG,save_sreg				;Restore Status register
	reti
;
ISR_TIM2_OVF:
	in		save_sreg,sreg				;Save Status register
;Do something here	
	out		sreg,save_sreg				;Restore Status register
	reti
;
ISR_TIM1_CAPT:
	in		save_sreg,SREG				;Save Status register
;Do something here	
	out		SREG,save_sreg				;Restore Status register
	reti
;
ISR_TIM1_COMPA:
	in		save_sreg,sreg				;Save Status register
;Do something here	
	out		sreg,save_sreg				;Restore Status register
	reti
;	
ISR_TIM1_COMPB:
	in		save_sreg,sreg				;Save Status register
;Do something here	
	out		sreg,save_sreg				;Restore Status register		
	reti
;
ISR_TIM1_OVF:
	in		save_sreg,SREG				;Save Status register
;Do something here
	out		SREG,save_sreg				;Restore Status register
	reti
;
ISR_TIM0_OVF:
	in		save_sreg,SREG				;Save Status register
;Do something here
	out		SREG,save_sreg				;Restore Status register
	reti
;
ISR_SPI_STC:
	in		save_sreg,SREG				;Save Status register
;Do something here	
	out		SREG,save_sreg				;Restore Status register
	reti
;
ISR_USART_RXC:
;X register only used in this routine
	in		save_sreg,SREG				;Save Status register
;Do something here	
	out		SREG,save_sreg				;Restore Status register
	reti
;			
ISR_USART_UDRE:
	in		save_sreg,SREG		;Save Status register
;Do something here
	out		SREG,save_sreg		;Restore Status register
	reti
;
ISR_USART_TXC:
	in		save_sreg,SREG		;Save Status register
;Do something here	
	out		SREG,save_sreg		;Restore Status register
	reti
;
ISR_ADC:
	in		save_sreg,SREG		;Save Status register
;Do something here	
	out		SREG,save_sreg		;Restore Status register
	reti
;
ISR_EE_RDY:	
	in		save_sreg,SREG		;Save Status register
;Do something here	
	out		SREG,save_sreg		;Restore Status register
	reti
;		
ISR_ANA_COMP:
	in		save_sreg,SREG		;Save Status register
;Do something here	
	out		SREG,save_sreg		;Restore Status register
	reti
;
ISR_TWSI:
	in		save_sreg,sreg		;Save Status register
;Do something here	
	out		sreg,save_sreg		;Restore Status register
	reti
;
ISR_EXT_INT2:
	in		save_sreg,SREG				;Save Status register
;Do something here
	out		SREG,save_sreg				;Restore Status register
	reti
;
ISR_TIM0_COMP:
	in		save_sreg,SREG				;Save Status register
;Do something here
	out		SREG,save_sreg				;Restore Status register
	reti
;
ISR_SPM_RDY:		
	in		save_sreg,sreg		;Save Status register
;Do something here	
	out		sreg,save_sreg		;Restore Status register
	reti

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Allan_Dent wrote:
The list is straight out of the ATmega16 data sheet PDF so why won't it recognize the label I've used.

Because that is a document; your assembler doesn't process documents -- it processes files.

 

Indeed perhaps a typo.  Or perhaps over the years different versions used different wordings.  Anyway, armed with that page of the datasheet peek inside the .INC file and find the corresponding entry.

 

Oh, I changed my mind -- I have to go with js on this one -- in ASM you make whatever label you care to.  I was thinking of the .ORG addresses, e.g.

 

.equ	INT0addr=$002	;External Interrupt0 Vector Address
.equ	INT1addr=$004	;External Interrupt1 Vector Address
.equ	OC2addr =$006	;Output Compare2 Interrupt Vector Address
.equ	OVF2addr=$008	;Overflow2 Interrupt Vector Address
.equ	ICP1addr=$00A	;Input Capture1 Interrupt Vector Address
.equ	OC1Aaddr=$00C	;Output Compare1A Interrupt Vector Address
.equ	OC1Baddr=$00E	;Output Compare1B Interrupt Vector Address
.equ	OVF1addr=$010	;Overflow1 Interrupt Vector Address
.equ	OVF0addr=$012	;Overflow0 Interrupt Vector Address
.equ	SPIaddr =$014	;SPI Interrupt Vector Address
.equ	URXCaddr=$016	;UART Receive Complete Interrupt Vector Address
.equ	UDREaddr=$018	;UART Data Register Empty Interrupt Vector Address
.equ	UTXCaddr=$01A	;UART Transmit Complete Interrupt Vector Address
.equ	ADCCaddr=$01C	;ADC Interrupt Vector Address
.equ	ERDYaddr=$01E	;EEPROM Interrupt Vector Address
.equ	ACIaddr =$020	;Analog Comparator Interrupt Vector Address
.equ    TWIaddr =$022   ;Irq. vector address for Two-Wire Interface
.equ	INT2addr=$024   ;External Interrupt2 Vector Address
.equ	OC0addr =$026   ;Output Compare0 Interrupt Vector Address
.equ	SPMRaddr=$028   ;Store Program Memory Ready Interrupt Vector Address

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Fri. Mar 2, 2018 - 09:19 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for those helpful hints, I'll have a go and see how I get on.

 

Allan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks Guys,

I defined my own interrupts & Studio 7 is no longer rejecting my code

 

Cheers,   Allan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd like to thank both contributors to my posted problem.  On studying your replies, I re-read a couple of Assembly Tutorials on interrupts and along with your posts, for the first time, I think I fully understand how the AVR responds to interrupts.  Before this, I had just used skeleton programs provided to me by a friend many years ago which already had the list of interrupts in a cseg listing and a further list of interrupt labels with their associated jump instructions at the end of the program listing.  From there I just added my own code and accepted that interrupts would just happen when enabled and triggered and not bothering to understand how the AVR went about responding to it's interrupt.  I now understand that each AVR interrupt sends the processor to it's own unique interrupt address vector and those vectors follow the layout of the interrupt listings in the PDF file for that particular processor. 

Thanks again for not only helping me to fix my problem but also in educating me to be a better AVR programmer.

Cheers,   Allan

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Glad to help a fellow Aussie, particularly one who uses assembler. wink

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly