ADC (noise reduction) mega8 fail

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

I'm trying to implement ADC reading with an ARmega8 using noise reduction option witout results.
can anybody take a look to this ASM simple pgm .

Any error or missing instr. ?

Thanks

;ATmega8 - Test of ADC .

; Just reads ADC5 and put result on ports B and D
;The ADC has a separate analog supply voltage pin, AVCC. AVCC must not differ more than ± 0.3V ;from VCC . Connect Aref and AVCC to VCC

; I/O Register Definitions
.equ SREG =$3F
.equ SPH =$3e ;stack pointer H
.equ SPL =$3d ;stack pointer L
.equ GIMSK =$3B
.equ GIFR =$3A
.equ TIMSK =$39 ; ok
.equ TIFR =$38
.equ MCUCR =$35 ; ok
.equ TCCR0 =$33 ; ok
.equ TCNT0 =$32
.equ TCCR1 =$30
.equ TCNT1 =$2F
.equ OCR1A =$2E
.equ OCR1B =$2D
.equ PORTB =$18
.equ DDRB =$17
.equ ACSR =$08
.equ ADMUX =$07 ; 0k
.equ ADCSR =$06 ; ok
.equ ADCH =$05 ; ok
.equ ADCL =$04 ; ok
.equ PORTC =$15 ; ok
.equ DDRC =$14 ; ok
.equ PINC =$13 ; ok
.equ PORTD =$12
.equ DDRD =$11
.equ PIND =$10
.equ ADIF =4 ;

; Variable Declarations

.def temp = r16
.def isrsreg = r18
.def isrtemp1 = r19
.def isrtemp2 = r20
.def cseg = r21
.def seg0 = r22
.def seg1 = r23
.def seg2 = r24
.def seg3 = r25

.cseg ; CODE segment.

;Interrupt Vectors
.org 0
rjmp init ;Reset
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;
reti ;

;Initialization
init:

ldi r16,$03 ; Stack pointer 3F xxxx 4
out SPH,r16 ;
ldi r16,$0F ;
out SPL,r16 ;

ldi r16,$1F ; 5 bits are outputs
out DDRC,r16 ;

ldi r16,$FF ; all bits are outputs
out DDRB,r16
ldi r16,$FF ; all bits are outputs
out DDRD,r16

sei ; Enable Interrupts

ldi r16,$8E ; Enable, ADIE, Prescale = 1/64 1000 1110 xxxxx;
out ADCSR,r16

ldi r16,$05 ; 5 - Select ADC5 as input, VCC as VREF ligado externo xxxx
out ADMUX,r16 ; xxxx 000x0101 5

loop:

ldi r16,$90 ; Sleep enable, ADC low noise mode
out MCUCR,r16
sleep ; Wait for ADC to convert

in r0,ADCL ; Read the converted value
in r1,ADCH

out PortB,r1 ; Out result to ports B , D
out PortD,r0

rjmp loop ; Go again

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

Not too sure how to solve your problem (never done that before) but I'm giving a couple of suggestions on improving your code if you don't mind.

; I/O Register Definitions 
.equ SREG =$3F 

You don't need this, just include the definition file .include "m8def.inc" as one of your fist line.

ldi r16,$03 ; Stack pointer 3F xxxx 4 
out SPH,r16 ; 
ldi r16,$0F ; 
out SPL,r16 ; 

Do it as the data sheet shows (page 43)

ldi r16,high(RAMEND) ; Main program start
out SPH,r16 ; Set stack pointer to top of RAM
ldi r16,low(RAMEND)
out SPL,r16

Look at page 196 on how to wire up AVcc if not already done so. Also about AREF from the data sheet

Quote:
If the user has a fixed voltage source connected to the AREF pin, the user may not use
the other reference voltage options in the application, as they will be shorted to the
external voltage. If no external voltage is applied to the AREF pin, the user may switch
between AVCC and 2.56V as reference selection. The first ADC conversion result after
switching reference voltage source may be inaccurate, and the user is advised to discard
this result.
Usually I just have a 100nF cap to AREF and not conneted.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Hi js

I changed the ASm with your Sug. but no results .

I also have tried all Vref options , software ( changing REFS1 and REFS0 ) and of course the

hardware (to match software option).

Note:

The single conversion works fine.
Free run also works fine.

Only ADC noise redution do not work.
As you know it stop normal micro run and should reduce noise and improve ADC results.

I also have tried this options on a ATtiny15 an all work fine .
I just can´t run it on ATmega8.

AnY Suggestions ?
Can anybody try it ?

Thanks a lot.

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

What is the problem exactly? Doesn't the M8 wake up from sleep? Ot is it something else?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

Is it my imagination, or have we seen three different threads in the past week on ADC noise-reduction mode? And I cannot remember any before that.

Lee

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.

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

In single conversion mode you need to set ADSC bit in ADCSRA to one to start a new conversion. So you need to add

sbi  adcsra,adsc  ;start a new conversion

at the end of your loop to have continous single conversions. In free running mode you only need to set ADSC to "1" to start first conversion.

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

Quote:

In single conversion mode you need to set ADSC bit in ADCSRA to one to start a new conversion. ...

But OP wants to use the noise reduction, where a conversion is started when the AVR goes to sleep and wakes up when finished.

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.

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

theusch wrote:
Quote:

In single conversion mode you need to set ADSC bit in ADCSRA to one to start a new conversion. ...

But OP wants to use the noise reduction, where a conversion is started when the AVR goes to sleep and wakes up when finished.

Thanks to all

The problem is that results in r0 and r1 registers are allways 0 and so ports B and D are also 0 for any value on ADC5 pin.
Yes M8 wake up from sleep .

As I said before in "single conversion" and "free run" mode it works fine.

It seems I´m doing any mistake or some missing/wrong instrution.But it seems to be as per datasheet .

Thanks

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

Quote:
VCC as VREF ligado externo xxxx
So AREF is tied up to AVCC (or VCC I guess) and you are putting some voltage to the A/D pin, all VCC, AVCC and ground pins are connected (if not PDIP package then there is more than 1 VCC and ground)......it's silly questions time....also anything in the errata to see if there have been problems along these lines?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

js wrote:
Quote:
VCC as VREF ligado externo xxxx
So AREF is tied up to AVCC (or VCC I guess) and you are putting some voltage to the A/D pin, all VCC, AVCC and ground pins are connected (if not PDIP package then there is more than 1 VCC and ground)......it's silly questions time....also anything in the errata to see if there have been problems along these lines?

Thanks js , all questions/comments are wellcome .

Yes Aref conected to AVCC . (I also tried all other possible Vref config , no result )
Ground pins connected .
Voltage (0 to 5v ) conected to ADC5 pin .Result allways 0 .

I tried to find errata on Atmel site but could not find it .
Do you know if it exists ?

Until now i could not find the problem .

I will get a new Mega8 and verify if this one have any problem.

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

I tried a new ATmega8 and the ADC works fine with all configurations.

Thanks to all for your helps and comments.