CorBee
Well-known member
Hi,
I have recently added a Lipo to a Teensy Batdetector (see https://forum.pjrc.com/threads/38988-Bat-detector). Next step was adding a simple routine that keeps track of the voltage coming from the Lipo to the teensy.
The USB-VIN is cut (I can however manually connect the USB-V still via a 1pin header.)
For this a voltage-divider was necessary, at the start I used a 100k/100k divider between VIN and GND and tried to read the analog voltage from A3 (pin 17).
Using a very simple routine
This read the voltage from the Lipo but it was very unstable, so I switched to reading the VIN when the USB is connected instead ... again unstable. So this forum was as always the next source to get better informed.
After reading https://forum.pjrc.com/threads/25111-Decreasing-noise-on-Teensy-ADC it seemed clear that the 100k/100k divider was not up to it so a new divider was set up using 15k/2.2k (had those hanging around).
The readouts for both the Lipo and the USB still look unstable, even after adding a small C (10n) over ADC-GND. Switching to 10bits resolution looked a bit better but the voltage at successive startups was very different.
I have also tried to use @pedvide's ADC library ... no difference. So I am stuck, and am looking for a good idea to solve this.
kind regards
Cor
I have recently added a Lipo to a Teensy Batdetector (see https://forum.pjrc.com/threads/38988-Bat-detector). Next step was adding a simple routine that keeps track of the voltage coming from the Lipo to the teensy.
The USB-VIN is cut (I can however manually connect the USB-V still via a 1pin header.)
For this a voltage-divider was necessary, at the start I used a 100k/100k divider between VIN and GND and tried to read the analog voltage from A3 (pin 17).
Using a very simple routine
Code:
analogReference(DEFAULT);
analogReadResolution(12);
analogReadAveraging(32);
VIN=analogRead(A3);
After reading https://forum.pjrc.com/threads/25111-Decreasing-noise-on-Teensy-ADC it seemed clear that the 100k/100k divider was not up to it so a new divider was set up using 15k/2.2k (had those hanging around).
The readouts for both the Lipo and the USB still look unstable, even after adding a small C (10n) over ADC-GND. Switching to 10bits resolution looked a bit better but the voltage at successive startups was very different.
I have also tried to use @pedvide's ADC library ... no difference. So I am stuck, and am looking for a good idea to solve this.
Code:
adc->setAveraging(32, ADC_0); // set number of averages
adc->setAveraging(32, ADC_1);
adc->setResolution(12,ADC_0); // set bits of resolution
adc->setResolution(12,ADC_1);
adc->setReference(ADC_REFERENCE::REF_1V2, ADC_1);
adc->setReference(ADC_REFERENCE::REF_1V2, ADC_0);
// it can be any of the ADC_CONVERSION_SPEED enum: VERY_LOW_SPEED, LOW_SPEED, MED_SPEED, HIGH_SPEED_16BITS, HIGH_SPEED or VERY_HIGH_SPEED
// see the documentation for more information
// additionally the conversion speed can also be ADACK_2_4, ADACK_4_0, ADACK_5_2 and ADACK_6_2,
// where the numbers are the frequency of the ADC clock in MHz and are independent on the bus speed.
pinMode(A3, INPUT);
adc->setConversionSpeed(ADC_CONVERSION_SPEED::LOW_SPEED,ADC_0); // change the conversion speed
adc->setConversionSpeed(ADC_CONVERSION_SPEED::LOW_SPEED,ADC_1);
// it can be any of the ADC_MED_SPEED enum: VERY_LOW_SPEED, LOW_SPEED, MED_SPEED, HIGH_SPEED or VERY_HIGH_SPEED
adc->setSamplingSpeed(ADC_SAMPLING_SPEED::LOW_SPEED,ADC_0); // change the sampling speed
adc->setSamplingSpeed(ADC_SAMPLING_SPEED::LOW_SPEED,ADC_1); // change the sampling speed
VIN= (adc->analogRead(A3))*2.671;///1024; //rough estimate of battery on VIN
kind regards
Cor