OUT -vs- STS - problem

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

Odd thing I don't understand and haven't run into before:

Am using an ATMega328, and am setting the comparator to compare AIN1 to the 'bandgap voltage' of 1.1v

To select the BG-voltage for the comparator+, you have to set the ACBG bit in ACSR register. So I did this:

LDI r23, 1<<ACBG
STS ACSR,r23

This didn't work - I have verified that the comparator+ was still using AIN0, not the BG-voltage.... so ACBG-bit was still a 0.

Experimenting, I tried an "OUT" instead of "STS", and it works fine.

Confused.... I thought "OUT" was just a faster (1 cycle) way to address the low memory (registers), but "STS" works on the whole map, but takes 2 cycles.

Anybody understand this?

Mark
Elgin, IL (near Chicago)

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

Yes, you should check the actual address for ACSR.
STS will work on any address. The OUT instruction works on < 0x20.

From your data sheet:

Register Summary
  Address   Name Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 
$08 ($28)   ACSR   ACD  ACBG   ACO   ACI  ACIE  ACIC ACIS1 ACIS0

So you could use either:

    STS $28,r23 
    OUT $08,r23 

Note that Atmel have an app note (AVR001 I think) that gives a macro that checks the address first, and uses the best mode.

David.

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

Quote:
Note that Atmel have an app note (AVR001 I think) that gives a macro that checks the address first,
Correct.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

AVR001: Conditional Assembly and portability macros
http://www.atmel.com/Images/doc2...
http://www.atmel.com/Images/AVR0...

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

Snippet (AT90PWM3)

	ldi	temp, (1<<REFS0)		;Vref = AVcc (DAC same Vref as ADC)
	sts	ADMUX, temp

You forgot the brackets (?)

From the ATmega1284P datasheet.

When using the I/O specific commands IN and OUT, the I/O addresses $00 - $3F must be used. When addressing I/O registers as data space using LD and ST instructions, $20 must be added to these addresses. The ATmega1284P is a complex
microcontroller with more peripheral units than can be supported within the 64 location reserved in Opcode for the IN and
OUT instructions. For the Extended I/O space from $60 - $FF, only the ST/STS/STD and LD/LDS/LDD instructions can be
used.

RES

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

Quote:
You forgot the brackets (?)
Why do you think that you need brackets?

Regards,
Steve A.

The Board helps those that help themselves.

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

RES you are missing the point af what David and I are trying to say. Do you see ANY OUT or STS here? What is being used instead?

;USART1_INIT - Initialize USART1
USART1_INIT:
	ldi		temp,low(fosc/(16*baud_1)-1)
	ldi		temp1,high(fosc/(16*baud_1)-1)	;If used
SETBAUD_1:
	STORE	UBRR1H,temp1			;baud register high
	STORE	UBRR1L,temp			;baud register low	
	ldi		temp,(1<<RXEN1)|(1<<TXEN1)		
	STORE	UCSR1B,temp			;enable bits
	ret     

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly