Closed charlespax closed 8 years ago
@samchoy88 this has been implemented, correct?
The ATmega32U4 datasheet specifies that the internal reference is typically 2.56V but can vary between 2.4V and 2.8V. See page 385: http://www.atmel.com/images/doc7766.pdf
If you need a more precise reference value, for battery measurement and other purposes, you may have to measure and calibrate each individual unit by storing the measured reference voltage (as measured on the AREF pin) in the internal EEPROM, and use the stored value for calculations.
If you do this, it would be nice to allow users to re-calibrate their unit by entering a new value, using a menu item, that they measured themselves. Instead, or in addition to, having a menu item, you could allow setting it from a command via the USB port.
The other option is to use a more precise external reference connected to the AREF pin.
@samchoy88 how should we address this?
I don't have Eagle installed, so I can't look at your latest schematic. If you're still using a Micrel MIC5219 to provide 3.3V then note that its output is specified to be within 1% (or 2% over the full temperature range). If this tolerance is sufficient for your purposes, you could set the ADC to use AVcc as the reference.
If you need to be more precise, then as I've said, you could add a better external reference or allow for software calibration.
If it's just the battery voltage that you need to measure accurately (not other things relative to the reference) then another option is to add a potentiometer in the resistor divider that provides VBAT_SENSE, to allow hardware calibration. However, if you decide to calibrate each unit, I think software calibration would be preferred.
If you decide to use AVcc internally, or a higher external reference voltage, then you should also consider changing the values of the VBAT_SENSE resistor divider to take advantage of the larger range. With a 3.3V reference, using 18.7K on the high side and 34K on the low side will give a nice 5mV per step from the ADC.
A problem with using AVcc as the reference is that once the battery falls below the dropout voltage of the 3.3V regulator the reference starts to drop and then will no longer allow a correct battery voltage reading. I've discussed addressing this problem in the Arduboy forum here: http://community.arduboy.com/t/arduboy-kickstarter-version-design-discussion/220/31
The battery voltage below 3.6V could be consider as low battery.
We can consider the battery level is always higher than 3.3V.
I will apply MLXXXp suggestion and use AVCC (regulated 3.3V) as ADC reference and using 18.7K on the high side and 34K on the low side will give a nice 5mV per step from the ADC.
Besides, a capacitor also added between ADC input and ground as noise filter.
See below update circuit:
A couple of notes:
Testing this, might want something a little higher than .1uF since there seems to be some noise spikes on the signal.
For the resistors, we are using 1% value in general. Only the thermocouple part using 0.1% resistors. (please see issue: Does the thermocouple filtration circuit affect the ADC readings? #53)
For the capacitor at VBAT_SENSE, I put 1uF as current design. Please turn on MOSFET with longer duration before taking ADC value.
Schematic changed.
18.7K and 34K resistors can be replace by value 11K and 20K resistors to achieve 50mV per ADC step with 3.3V ADC reference.
11K and 20K gives exactly the same divide ratio as 18.7K and 34K, so either pair will work pretty much identically.
11K and 20K will draw more current but settle faster.
We now use the ATmega32U4 internal reference voltage (https://github.com/PaxInstruments/t400-firmware/issues/21), but @samchoy88 may have found a problem.
Comment from @samchoy88 in https://github.com/PaxInstruments/t400-electronics/issues/43: As the Reference voltage is critical for calculating the VBAT voltage value. I expect using internal 2.56V voltage reference. and calculate the VBAT level by ADC x 2.56V / 1023. However, I found the VBAT value does not match with measuring point. After checking the circuit and ARef pin, the internal voltage reference only supply 2.508V and causing incorrect result in calculation.