ATMega328P Timer registers generate Build errors in Studio 7

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

I am trying to program an ATMega328P on a Pololu Baby Orangutan B-328 board with Pololu's AVR Programmer V2.1 on Atmel Studio 7.

I can turn the user LED on or off so I know the programming environment is OK. The problem is with including Timer/Counter1 to generate periodic interrupts. I'm using a closely related version of the program on a ATtiny104 Xplained Nano which works.

All the timer registers generate Build errors. Example: "out CLKPR, r16 - Operand 1 out of range: 0x61". So the assembler knows the offset for the register but still generates an error. Some other registers such as TCNT1H are not included in mdef328p.inc.

I've put in #include "mdef328p.inc" and made sure it is in the same directory as the main code main.asm and also in the directory that contains the project.
I'm concerned that this .inc file does not show under dependencies in the Solution Explorer. Why? Maybe it relates to the errors.

Skier

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

Some registers can only be accessed via ram addresses - thus you need to use STS rather than OUT. Atmel ran out of i/o addresses, so some registers got put in the ram area. I've not checked the datasheet to see if that applies to your case.

 

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

Skier wrote:
Some other registers such as TCNT1H are not included in mdef328p.inc.

???

; ***** I/O REGISTER DEFINITIONS *****************************************
; NOTE:
; Definitions marked "MEMORY MAPPED"are extended I/O ports
; and cannot be used with IN/OUT instructions
.equ	UDR0	= 0xc6	; MEMORY MAPPED
.equ	UBRR0L	= 0xc4	; MEMORY MAPPED
.equ	UBRR0H	= 0xc5	; MEMORY MAPPED
.equ	UCSR0C	= 0xc2	; MEMORY MAPPED
.equ	UCSR0B	= 0xc1	; MEMORY MAPPED
.equ	UCSR0A	= 0xc0	; MEMORY MAPPED
.equ	TWAMR	= 0xbd	; MEMORY MAPPED
.equ	TWCR	= 0xbc	; MEMORY MAPPED
.equ	TWDR	= 0xbb	; MEMORY MAPPED
.equ	TWAR	= 0xba	; MEMORY MAPPED
.equ	TWSR	= 0xb9	; MEMORY MAPPED
.equ	TWBR	= 0xb8	; MEMORY MAPPED
.equ	ASSR	= 0xb6	; MEMORY MAPPED
.equ	OCR2B	= 0xb4	; MEMORY MAPPED
.equ	OCR2A	= 0xb3	; MEMORY MAPPED
.equ	TCNT2	= 0xb2	; MEMORY MAPPED
.equ	TCCR2B	= 0xb1	; MEMORY MAPPED
.equ	TCCR2A	= 0xb0	; MEMORY MAPPED
.equ	OCR1BL	= 0x8a	; MEMORY MAPPED
.equ	OCR1BH	= 0x8b	; MEMORY MAPPED
.equ	OCR1AL	= 0x88	; MEMORY MAPPED
.equ	OCR1AH	= 0x89	; MEMORY MAPPED
.equ	ICR1L	= 0x86	; MEMORY MAPPED
.equ	ICR1H	= 0x87	; MEMORY MAPPED
.equ	TCNT1L	= 0x84	; MEMORY MAPPED
.equ	TCNT1H	= 0x85	; MEMORY MAPPED
.equ	TCCR1C	= 0x82	; MEMORY MAPPED
.equ	TCCR1B	= 0x81	; MEMORY MAPPED
.equ	TCCR1A	= 0x80	; MEMORY MAPPED
.equ	DIDR1	= 0x7f	; MEMORY MAPPED
.equ	DIDR0	= 0x7e	; MEMORY MAPPED
.equ	ADMUX	= 0x7c	; MEMORY MAPPED
.equ	ADCSRB	= 0x7b	; MEMORY MAPPED
.equ	ADCSRA	= 0x7a	; MEMORY MAPPED
.equ	ADCH	= 0x79	; MEMORY MAPPED
.equ	ADCL	= 0x78	; MEMORY MAPPED
.equ	TIMSK2	= 0x70	; MEMORY MAPPED
.equ	TIMSK1	= 0x6f	; MEMORY MAPPED
.equ	TIMSK0	= 0x6e	; MEMORY MAPPED
.equ	PCMSK1	= 0x6c	; MEMORY MAPPED
.equ	PCMSK2	= 0x6d	; MEMORY MAPPED
.equ	PCMSK0	= 0x6b	; MEMORY MAPPED
.equ	EICRA	= 0x69	; MEMORY MAPPED
.equ	PCICR	= 0x68	; MEMORY MAPPED
.equ	OSCCAL	= 0x66	; MEMORY MAPPED
.equ	PRR	= 0x64	; MEMORY MAPPED
.equ	CLKPR	= 0x61	; MEMORY MAPPED
.equ	WDTCSR	= 0x60	; MEMORY MAPPED
.equ	SREG	= 0x3f
.equ	SPL	= 0x3d
.equ	SPH	= 0x3e
.equ	SPMCSR	= 0x37
.equ	MCUCR	= 0x35
.equ	MCUSR	= 0x34
.equ	SMCR	= 0x33
...

 

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: Mon. Oct 21, 2019 - 12:43 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As for the CLKPR error, that's because you used OUT when it has to be STS. You can only use OUT on IO mapped registers (IO addresses 0x00..0x3F, RAM addresses 0x20..0x5F). CLKPR at 0x61 is not in that range so OUT cannot be used. To avoid this use the LOAD/STORE macros from AVR001

 

This... https://www.google.com/url?sa=t&...

Last Edited: Sun. Oct 20, 2019 - 03:17 PM