SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By nanobot
#67109
I have been building various simple robots over the years and this forum is great - but this is only a hobby as my background training is not in programming or electronics and I have been learning as I go. Let me first say I searched for this topic on the forum before I posted and while I found various articles, I am hoping for a comprehensive answer.

The basic questions I have are:

1. What resistor values should I use for the voltage divider and exactly how do I wire this with respect to the battery and the Vref - is it the midpoint of the divider that gets connected?

2. Need a code using the internal 1.1v reference. I have read the data sheet, but if someone has code from an existing project with the declarations - that would be ideal!

Background: I am building a small tracked bot using geared pager motors and the BabyOrangutan controller board that is a Mega168. I am using a single 3.7V LiPo battery which is under the recommended 5v, but I have adjusted the board to use the internal 8MHz setting rather than the external 20MHz based on other recommendations and have done this before. I am also using a solar powered charging circuit to top off the battery when there is sufficient light, but it is not currently integrated into this design.

In a nutshell, I have never written a C-program from scratch and while that is bad and I know I need to try, I am seeking a complete code of how to read the battery voltage and use the internal 1.1vref to determine the battery state. The board has a few LEDs that I can blink if it reaches a certain level, but I can add that later. I have read various posts about ADC on this forum and have looked at the mega168 datasheet, but what I am hoping for is that someone has some actual code that is not pseudo-code, that I could test with this chip/board using the internal reference point preferably if it is standalone as a modular approach seems to work best. I know that is a lot to ask, but any and all help is appreciated.
By nanobot
#67584
That is perfect. I even searched that forum and never found that information - thanks again for the tip