ATmega4809 ADC question

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

I've got the ADC working on the ATmega4809 using VDD as reference.

 

	/* Disable digital input buffer */
	PORTE.PIN0CTRL |= PORT_ISC_INPUT_DISABLE_gc;

	ADC0.CTRLC = ADC_PRESC_DIV16_gc
	| ADC_SAMPCAP_bm
	| ADC_REFSEL_VDDREF_gc;

	ADC0.CTRLB = ADC_SAMPNUM_ACC4_gc;

	/* Select ADC channel */
	ADC0.MUXPOS  = ADC_MUXPOS_AIN8_gc;

	ADC0.CTRLA |= ADC_ENABLE_bm;          /* ADC Enable: enabled */

 

and to trigger the ADC

 

	/* Start ADC conversion */
	ADC0.COMMAND = ADC_STCONV_bm;

	/* Wait until ADC conversion done */
	while ( !(ADC0.INTFLAGS & ADC_RESRDY_bm) )
	{
		;
	}

	/* Clear the interrupt flag by writing 1: */
	ADC0.INTFLAGS = ADC_RESRDY_bm;

	return ADC0.RES >> 2;

but my question is;  The reference voltage is 4.3 instead of the 5V I have powering the device.

 

Is this expected behavior?  if so does anyone have an explanation as to why?

This topic has a solution.

Happy Trails,

Mike

JaxCoder.com

Last Edited: Fri. Jan 14, 2022 - 07:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm just a bit mangler but 0.7V sounds suspiciously like a diode voltage drop ;-)

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

Is the actual chip AVcc really 5.0V with respect to the chip analog ground?

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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

Guess I should have included my board schematic.

 

I've checked voltages at both VDDs and they are 5V.  I've tried applying 5V to AVCC but as expected it did nothing.

 

Cliff

clawson wrote:
I'm just a bit mangler but 0.7V sounds suspiciously like a diode voltage drop ;-)

 

You're right it does look like a diode drop, but don't know where it would be coming from.

 

Yes 5V in respect to AVCC ground

 

 

Attachment(s): 

Happy Trails,

Mike

JaxCoder.com

Last Edited: Fri. Jan 14, 2022 - 07:26 PM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

At the very least, you need to connect AVdd and AGnd when using the ADC. Without that, all bets are off. It might not be The Solution but I don't think that you will get a solution without it.

 

Note this from the spec sheet. There appears to be something "magic" about 4.3V.

 

29.3.2.4.2 ADC Voltage Reference

The reference voltage for the ADC (VREF) controls the conversion range of the ADC. Input voltages that exceed the selected VREF will be converted to the maximum result value of the ADC. For an ideal 10-bit ADC, this value is 0x3FF.

VREF can be selected by writing the Reference Selection (REFSEL) bits in the Control C (ADCn.CTRLC) register as either VDD, external reference VREFA, or an internal reference from the VREF peripheral. VDD is connected to the ADC through a passive switch.

When using the external reference voltage VREFA, configure ADCnREFSEL[0:2] in the corresponding VREF.CTRLn register to the value that is closest, but above the applied reference voltage. For external references higher than 4.3V, use ADCnREFSEL[0:2] = 0x3.

The internal reference is generated from an internal band gap reference through an internal amplifier, controlled by the Voltage Reference (VREF) peripheral.

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Fri. Jan 14, 2022 - 07:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

I read that 5 times, 2 yesterday and 3 times in your post and just now caught;

 

For external references higher than 4.3V, use ADCnREFSEL[0:2] = 0x3.

 

Turns out that 0x3 did not work but connecting AVCC to 5V and AGND to GND did.  Thanks Jim

Happy Trails,

Mike

JaxCoder.com

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

In addition to not having the power pins conected (as Jim reminded you), you also lack adequate power supply filtering. Add about 100nF decoupling capacitor between every VDD-GND pin pair. Consider separate VDD and AVDD by ferrite bead.
https://ww1.microchip.com/downlo... page 4.

A datasheet paragraph quoted by jim looks weird. If i select external reference through analog mux in ADC (REFSEL[1:0]) why the hell i should select adequate internal VREF value ? What more, if I understand it literally then even in case that internal reference is turned off (ADC0REFEN=0) i have to select its proper value... smells like some "bug correction".... or i am missing something.

Michal

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

Michal,

 

Thanks for the input.  Although, not shown on the schematic I actually did put .1uF caps between all VDDs and GNDs.

I'll add to next version of board.  I'm a software guy with just enough knowledge of electronics to be dangerous.  :)

 

I tried the suggestion given in the paragraph that Jim mentioned but in the datasheet 0x3 is shown as Reserved.  At any rate it didn't work!

Happy Trails,

Mike

JaxCoder.com