Page 1 of 1

Problem with reference voltage on Arduino Mega

Posted: Fri May 05, 2017 9:43 am
by Coensk
Hello,

While finetuning my program I stumbled upon a problem with the internal reference voltage (ARef) of my Arduino Mega. I set the internal reference voltage to 2.56V just like LeighM explained me in one of my previous questions (viewtopic.php?f=63&t=18701).

The problem is, whenever I try to read an analog signal (I read the analog signal the way it's explained in the Flowcode wiki) the internal ARef voltage changes from 2.56V to AVCC (4.68V in my case).
--(It's the GetByte component macro in the attachment which causes the problem)

Does anyone have any solution to this? Maybe the C-code of the GetByte command which reads the analog signal interferes with the register that sets the internal ARef voltage (ADMUX).

Thanks, Coensk

Re: Problem with reference voltage on Arduino Mega

Posted: Fri May 05, 2017 10:37 am
by Benj
Hello,

The Arduino Mega uses ADC type 10 so if you look in the "Flowcode 7\CAL\AVR\AVR_CAL_ADC.c" file using a text editor then ADC type 10 starts at around line 673.

Save the CAL C file to your desktop and add your voltage reference modification to the ADC_Enable routine.

Copy the file back to it's original location using Windows explorer. Be sure to make a backup of the original file so you can easily go back if you need to.

Let us know how you get on.

Re: Problem with reference voltage on Arduino Mega

Posted: Fri May 05, 2017 5:34 pm
by Coensk
Hello,

Thanks for your reply Benj, is the line I should change under the 'ADC type 10 Supported Devices'? (Arduino Mega) I changed the value there but now the voltage over the ARef pin just measures 0V..

Later I changed the value in every type of "Supported Devices", still the same outcome..

Thanks Coensk

Re: Problem with reference voltage on Arduino Mega

Posted: Tue May 09, 2017 12:02 pm
by Coensk
I have changed it in the AVR CAL ADC file but still the same problem persists, whenever an analog signal is read by the Arduino Mega, the reference voltage present at the ARef pin changes.

When done with a C-code component in the flowchart it changes from 2.56V to UVcc => 5V.
When changed in the AVR CAL ADC file it changes from 2.56V to 0V.

You can find the edited file under attachments in this response

Does anyone have an idea on how to solve this?

Thanks, Coensk

Re: Problem with reference voltage on Arduino Mega

Posted: Tue May 09, 2017 3:03 pm
by Benj
Hello Coensk,

Is the problem that the ADC peripheral is being switched off after an ADC sample?

See this line in the ADC_Disable function for ADC type 10.

Code: Select all

ADCSRA &= ~(1 << ADEN);
You could try commenting out the line to see if this makes any difference.

Code: Select all

//ADCSRA &= ~(1 << ADEN);