Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
eX-Robot. New Ideas and Solutions for Self Balancing Robot
06-12-2015, 12:30 PM
Post: #3
RE: eX-Robot. New Ideas and Solutions for Self Balancing Robot
Hi!
Under our future ideas need free memory and time for their execution.
Now we will unleash 16 bytes of memory and a 100 microsecond time.
So, we will upgrade the original procedure for measuring the battery voltage. The modernization will improve measurement accuracy and free up 16 bytes of memory and a 100 microsecond time.
The original code (not the library version of the code):
Code:
#define BATT_VOLT_FACTOR 8

boolean first_time = true;

int readBattery()
{
  if (first_time)
    battery = analogRead(5)/BATT_VOLT_FACTOR;
  else
    battery = (battery*9 + (analogRead(5)/BATT_VOLT_FACTOR))/10;
  return battery;
}

Replace a new code:
Code:
uint16_t   tbattery = 0;

int readBattery() // c
{
  battery = (battery*9 + (tbattery/BATT_VOLT_FACTOR))/10; //
  ADMUX = (1<<REFS0) | (1<<REFS1);                       // Vref = 2.56В, for A5 (ADC0) all MUX5..0=0
  ADCSRA |= (1<<ADSC) | (1<<ADIE);                       // start ADC & enable interrupt
  return battery;
}

ISR(ADC_vect)                    // ready data
{
  tbattery = ADCL;
  tbattery |= ADCH<<8;
}

NOTE: In the original code BATT_VOLT_FACTOR = 8 selected for maximum battery voltage (Vin) equal to 12.5 volts and a voltage reference source Vref = 5 volt. Using a resistive divider R3(33K) end R5(22K).
The new code uses a built-in stabilized power supply with Vref = 2.56V. This limits the voltage at pin A5 and require different resistors R3, R5 and constant BATT_VOLT_FACTOR.

Question developers:
How to solve the problem of monitoring the battery on the board Pro Micro? In it there is no pin A5!
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: eX-Robot. New Ideas and Solutions for Self Balancing Robot - KomX - 06-12-2015 12:30 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)