Another final project....sounds like more money wasted....or another crappy instructor....
At any rate...
You've got voltage is a word.....
Somewhere in that coding mess you've got:
voltage = voltage * 300 ' Removes decimal
Now what happens when voltage = 219?
Also, you sample the voltage once and go with that number and only that number. Do you have any kind of filter on the line coming from the battery or is it straight from the battery thru a divider? Probably no filters or anything. Easiest thing to do here is to read the ADC a bunch of times and divide the result by the number of times you read it, average out the reading. Or what I do when I have to read a 'slowly' changing analog input....Say my last result was '100'. I read the ADC again, this time it's 110, I add 1 to my last results making it 101. I read the ADC, this time it's 130, I add another 1 to my last, making 102. I read again, this time it's 80, I subtract one. I would hope you get the picture. If the result I just read is within 1 of my last result, I don't change the number at all unless I get 2 successive reads that are both one off.
JDG




Bookmarks