Go to Post So, volunteer Field Resetters are to meet in the school's weight room for training? :D - Roger [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Spotlight this post!  
Unread 29-01-2007, 08:10
DanDon's Avatar
DanDon DanDon is offline
ohhh MY god
AKA: Dan Hoizner
FRC #0375 (The Robotic Plague)
Team Role: Mentor
 
Join Date: Jan 2005
Rookie Year: 2004
Location: Staten Island, NY
Posts: 1,432
DanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond reputeDanDon has a reputation beyond repute
Send a message via ICQ to DanDon Send a message via AIM to DanDon Send a message via MSN to DanDon
Re: Reading battery voltage in software

Quote:
Originally Posted by bear24rw View Post
Wrote this over the summer when playing around with the edu rc. It prints out a float
Code:
current_voltage = rxdata.rc_main_batt;         // Store current voltage
    average_voltage += current_voltage;        // Add the current voltage to the average stack

    voltage_count++;                            // Increase the average stack count
    
    if (voltage_count == 39)                          // If the stack is 40
    {
        average_voltage = (average_voltage / 40) * 0.038 + 0.05;    // Get the average and apply formula
        i = (int)average_voltage;                            // Truncate decimals
        i2 = (int) ((average_voltage - i) * 1000);                // Subtract to get decimals only and then multiply by 1000
        printf("Average: %d.%d \n",i,i2);                        // Print the two together to make it look like a decimal

        average_voltage = 0;                                    // Reset the stack
        voltage_count = 0;                                    // Rest the counter
    }

The only problem that I see with that is, if your voltage is let's say 8.004, I believe that the way you are printing the variables would print 8.4.

If I recall correctly %03d forces three digits to be printed, which using the above example, would display 8.004.
__________________
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
battery voltage compensation Rickertsen2 Programming 5 17-10-2005 22:12
RC Circuits Melissa Nute Math and Science 3 25-01-2004 05:02
Battery Chargers Neal Probert Electrical 46 16-02-2003 22:31


All times are GMT -5. The time now is 04:59.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi