EEVblog Electronics Community Forum

Electronics => Microcontrollers => Topic started by: Deni on January 09, 2018, 08:05:13 pm

Title: ATMega324PB AREF issue
Post by: Deni on January 09, 2018, 08:05:13 pm
Just got a few samples of ATMega324PB. I would like to use it instead of ATMega324P(A) in our current project. ATMega324PB should be backwards compatible with older flavors of ATMega324 but I got stucked with external AREF for ADC. To cut the long story short - I can't get it to work as supposed. When I select external AREF, ADC always reads 0x3FF on any channel I select - like AREF is not routed to the pin. On ATMega324PB it is shared with (new) PortE, but according to Microchip, if ADC is enabled and AREF set to external, pin should be automatically re-routed as an AREF input. On the other hand, if any other reference source is selected, it works as expected....

Can anybody try it out and verify my findings, or point me in the right direction if I'm doing something wrong...?
Title: Re: ATMega324PB AREF issue
Post by: sleemanj on January 09, 2018, 08:59:37 pm
Well... silly question certainly, but sometimes people miss an obvious error so it bears asking, what voltage are you supplying to ARef and what input are you supplying to the selected mux - in other words, are you sure that 0x3ff is not actually the correct conversion for your inputs.
Title: Re: ATMega324PB AREF issue
Post by: Deni on January 10, 2018, 07:02:59 am
OK, to clarify things further - I just soldered ATMega324PB on the same board we are currently producing with ATMega324P. So, yes - all signals are correct with correct levels, as well as AREF (5V - same as analog&digital supply voltage). After soldering old ATMega324P back  (running the same firmware, same HEX file flashed) - everything works as supposed.
And one more thing - I've opened a ticket on Microchip's site, got some initial response from their support staff and then complete silence.
Title: Re: ATMega324PB AREF issue
Post by: sleemanj on January 10, 2018, 07:54:23 am
Quote
running the same firmware, same HEX file flashed

If it was me I would recompile targetted specifically to the PB (you'll have to have an up to date avr-gcc to get the appropriate definitions, assuming you are using avr-gcc), I know the PB is supposed to be able to run P compiled code, but...

Then I would try another PB in case I had been unlucky and was trying a faulty one.

And after all that, I would go over to avrfreaks and ask there, a more targetted audience
Title: Re: ATMega324PB AREF issue
Post by: Deni on January 10, 2018, 11:06:48 am
Your last advice is a good one, I'll try there...
Title: Re: ATMega324PB AREF issue
Post by: Deni on January 11, 2018, 12:59:40 pm
- UPDATE -

Mistery solved - ATMega324PB has an error in datasheet regarding ADC. There's control bit in ADCSRB bit 7, that controls function of AREF pin.
If it is set (and after reset it is by default), AREF pin is routed to GPIO port E pin4. If it is cleared, AREF pin functions as an ADC ref. pin (either
as an input for external AREF voltage or bypass cap. output).