XMEGA ADC , measuring VCC

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi All

 

This is in relational to a Previous Post i did in regards the battery voltage dropping below 2.8V and then causing the charger to preform in trickle charge mode, but as my circuit was consuming much of the power therefore the battery was not recovering.

 

What i intend to do is measure the VCC, and if its is below 3.2V, not enable any my modules or circuit.  If i am able to read 3.2V  this would indicate to the battery has progressed from the trickle charge phase to the stage where adequate current is being outputted from the charger to enable circuit.

 

 

When VCC is 3.3V i get 672 and when VCC is 2.5V i am getting 515.

 

But i was expecting 3.3/10=0.33

0.33*4095=1351. when 3.3V

 

and

 

i was expecting 2.5/10=0.25

0.25*4095=1023. when 2.5V

 

The ADC is 12-bit

 

Is my code or my calculation incorrect?

 

 

void adc_init(void)
{
ADCB_CTRLB|=ADC_CURRLIMIT1_bm|ADC_CONMODE_bm;
ADCB_REFCTRL|=ADC_BANDGAP_bm;
ADCB_EVCTRL=0x00;        
ADCB_PRESCALER|=ADC_PRESCALER2_bm; 
ADCB_INTFLAGS=ADC_CH0IF_bm; 
ADCB_CH0_MUXCTRL|=ADC_CH_MUXPOS1_bm;
ADCB_CTRLA=ADC_ENABLE_bm; //enable ADC
}

int adc_result(void)
{

ADCB_CTRLA|=ADC_CH0START_bm; //start ADC conversion
while(!(ADCB_INTFLAGS & ADC_CH0IF_bm));
ADCB_INTFLAGS=ADC_CH0IF_bm; 
int result=ADCB_CH0_RES;
return result;
}

 

 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

djoshi wrote:

But i was expecting 3.3/10=0.33

0.33*4095=1351. when 3.3V

 

and

 

i was expecting 2.5/10=0.25

0.25*4095=1023. when 2.5V

 

Where did the 10 come from in this equation?

 

Given the results (3.3v = 672, and 2.5 = 515) it appears your vref is 5.0v and your ADC resolution is 10 bit or 1023! 

I'm not familiar with xmega, are those setting possible?  

 

Jim

 

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The full scale is 2047 because you chose signed.
Therefore, the conversion result is not strange.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kabasan wrote:

The full scale is 2047 because you chose signed.
Therefore, the conversion result is not strange.

 

That does make sense as it would be 11-bits

 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Be sure to add some hysteresis, to avoid stutter.

 

For example, below  500 turn on the water pump, above 520 turn it off.   If you did both at 500 it would sit there & chatter as the water sloshed around or settled.

 

Batt off circuits do the same....voltage too low turn off the load, but then that makes the voltage rise & system thinks "turn on".... load coming on causes drop, now turn off...off/on/off /on ...hysteresis  gets rid of that.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi.

 

I had some new PCBs made recently, which is causing a little issue. 

 

But my firmware is the same. I am trying to reference the 1.1V bandpass reference to the 3.3V VCC.

 

(1.1/3.3)*2047(12bit with sign)=682

 

Previously till the ADC reaches 650, I do not progress further in my code or circuit. All previous PCB produced ADC results above 660. 

 

With some new PCB, I am getting results of 640, which cause the firmware not to progress.

 

Am I correct in saying ADC has a 10% tolerance, and therefore I should wait for the ADC to reach at least 614 instead?

 

I am using XMEGA, does a batch of XMEGA have slightly different values? I have not calibrated the ADC, as I never needed to.

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Which xmega are you using? In the AU family, the reference voltage available to the ADC is 1.0V derived from a 1.1V bandgap.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 I have not calibrated the ADC, as I never needed to.

 

If you are making decisions based upon a specific ADC value the clearly you need to read the data sheet and determine if the ADC will be within spec, out of the box, to meet your needs, without end user calibration.

 

Additionally, too little info.

 

What is the power supply, is it well regulated and clean, and the same for both boards?

 

What is the temperature range the device is operated over?

 

What is the source impedance of the signal driving the ADC?

 

Are you taking multiple ADC readings and averaging them?

 

There are many factors that can impact the ADC readings, and you need to control for them for reliable, consistent data.

 

JC 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

balisong42 wrote:

Which xmega are you using? In the AU family, the reference voltage available to the ADC is 1.0V derived from a 1.1V bandgap.

 

I am using the ATxmega256a3bu

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

DocJC wrote:

 I have not calibrated the ADC, as I never needed to.

 

If you are making decisions based upon a specific ADC value the clearly you need to read the data sheet and determine if the ADC will be within spec, out of the box, to meet your needs, without end user calibration.

 

Additionally, too little info.

 

What is the power supply, is it well regulated and clean, and the same for both boards?

 

What is the temperature range the device is operated over?

 

What is the source impedance of the signal driving the ADC?

 

Are you taking multiple ADC readings and averaging them?

 

There are many factors that can impact the ADC readings, and you need to control for them for reliable, consistent data.

 

JC 

 

 

 

The power supply will be a Li-Poly battery.

Temp range can be between 20-40 degrees.

Yes, I am talking about 10 samples.

 

I am taking the ADC reading of the internal 1.1V against a 3.3V ref.

 

 

The reason why I need to do this exercise is to make sure the battery has enough charge to power the LDO to create a good 3.3V. This ensures the battery is in a good state to be used. 

 

 

 

Thanks

Regards

DJ

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The 1.0V reference varies with temperature and voltage.