Hi there,

I need to measure the Vcc voltage using the intrnal Bandgap voltage. It's my first time I am doing this, so please correct me if I am saying something wrong, because I am not experienced in this mechanism.

Some info. about my circuit:

uC: AT90USB647-16AU

AREF pin: externally connected to an 100nF only.

AVCC pin: externally connected to an 100nF and also to VCC via a 10uH.

CPU clock: external crystal 8MHz

The Vcc varies from 4.0V up to 5.5V and I need to know this, that's why I am using this mechanism. Also I need to tell you that there is no need of high resolution.

My test code is:

adc_init(ADC_CHANNEL_BANDGAP, ADC_BITS_8, ADC_AVCC, NO_ADC_PIN, CPU_CLOCK_8MHz); while(1){ unsigned char index = 0; unsigned char array[16]; array= adc_8bit(ADC_CHANNEL_BANDGAP); if (++index > 16){ index = 0; } }

The function adc_init set the peripheral registers as:

ADMUX = 0x7E (Single Ended Input: Band Gap 1.1V, 8bit results, Reference: AVcc with external Cap on AREF pin)

ADCSRA = 0x86 (Input clock F: 125KHz, ADC Enable)

ADCSRB = 0x00

DIDR0 = 0x00

and also makes a dummy measurement on the sellected channel.

The results of my code are:

for Vcc = 4V: array[0] = 85 array[1] = 77 array[2] = 73 array[3] = 72 array[4] = 72 array[5] = 72 array[6] = 72 array[7] = 72 array[8] = 72 array[9] = 72 array[10] = 72 array[11] = 72 array[12] = 72 array[13] = 72 array[14] = 72 array[15] = 72

for Vcc = 4.5V: array[0] = 78 array[1] = 69 array[2] = 65 array[3] = 64 array[4] = 63 array[5] = 63 array[6] = 63 array[7] = 63 array[8] = 63 array[9] = 63 array[10] = 63 array[11] = 63 array[12] = 63 array[13] = 63 array[14] = 63 array[15] = 63

for Vcc = 5V: array[0] = 74 array[1] = 63 array[2] = 58 array[3] = 57 array[4] = 57 array[5] = 56 array[6] = 56 array[7] = 56 array[8] = 56 array[9] = 56 array[10] = 57 array[11] = 56 array[12] = 56 array[13] = 56 array[14] = 56 array[15] = 56

for Vcc = 5.5V: array[0] = 71 array[1] = 59 array[2] = 54 array[3] = 52 array[4] = 52 array[5] = 52 array[6] = 52 array[7] = 52 array[8] = 52 array[9] = 52 array[10] = 52 array[11] = 52 array[12] = 52 array[13] = 52 array[14] = 56 array[15] = 56

I have almost red this popular thread:

https://www.avrfreaks.net/index.p...

But I still have some questions:

1. How is it possible for the measurements to decreased as the Vcc increases. Is this Ok or I am doing wrong?

2. The measurement span is too small. For Vcc = 4V the ADC counts are 72 and for 5.5V they are 56. This means that there is only 1 count decrement for 100mV incement. Is this Ok? Is there any way of using all the 8bit result span (255 counts)?

Looking forward to hearing your suggestions.

Thank you.