XMEGA ADC , measuring VCC

Go To Last Post
5 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

 

 

(Possum Lodge oath) Quando omni flunkus, moritati.

"I thought growing old would take longer"

 

  • 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!