Problem with reference voltage on Arduino Mega

An area to discuss AVR and Arduino specific problems and examples

Moderator: Benj

Post Reply
Coensk
Posts: 10
Joined: Tue Mar 14, 2017 10:38 am
Contact:

Problem with reference voltage on Arduino Mega

Post 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
Attachments
Capture.PNG
(47.49 KiB) Downloaded 3763 times

User avatar
Benj
Matrix Staff
Posts: 15140
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Problem with reference voltage on Arduino Mega

Post 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.

Coensk
Posts: 10
Joined: Tue Mar 14, 2017 10:38 am
Contact:

Re: Problem with reference voltage on Arduino Mega

Post 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

Coensk
Posts: 10
Joined: Tue Mar 14, 2017 10:38 am
Contact:

Re: Problem with reference voltage on Arduino Mega

Post 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
Attachments
AVR_CAL_ADC_changed.c
(25.23 KiB) Downloaded 129 times

User avatar
Benj
Matrix Staff
Posts: 15140
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: Problem with reference voltage on Arduino Mega

Post 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);

Post Reply