Top Banner

of 21

Team Revolver

Apr 07, 2018

Download

Documents

Ian Bryan
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
  • 8/3/2019 Team Revolver

    1/21

    Team Revolver

    EP 391 Microprocessors

  • 8/3/2019 Team Revolver

    2/21

    Introduction

    The primary intention of the design was to track a light source and to send the recorded data

    received from various sensors to be displayed. Furthermore, temperature and pressure readings were

    taken. The sensors used were three voltage sensors, two LEDs, a pressure sensor, and a thermistor. The

    voltage sensors monitored the supply, the negative voltage of the battery, and the positive voltage ofthe battery. The LEDs were used to find the light and track it as it moved, telling the system which

    direction to move in. The actually moving section the system was a brush and plate mechanism that

    allowed the free spinning of the lights without the worry of wires getting tangled. The system

    emphasized hardware to deal with many of the problems we would run into, rather than solving it in the

    software.

    The System

    The Code

    The code was created and calibrated to include all the devices. Each device was given a function

    to convert the counts to a realistic value. They were then passed into a function that would send all the

    data in a packet of information including the team name. The code contained a multiplexer that was

    later removed, its code still remains integrated in the analog to digital conversion function should we

    have wanted to use it later.

    Motor and Light Tracker

    The primary physical components of the light tracking system were 2 LEDs, used as photo LEDs

    to detect the light source, and a stepper motor to mechanically align the sensors. The basic algorithm

    for light tracking was developed by considering the geometries of a triangle. As a photo LEDs output is

    based on light intensity, which is strongly related to the lights distance from the LED in our testing

    environment, we can easily infer that the LED which produces a stronger signal is closer to the light.

    Based on this, we have defined the following geometric diagram:

    Figure 1: General geometric implication of light tracking design.

    A fixed distance between the LEDs allowed us to calibrate center point at which both LEDs have

    very similar light intensity, representing equal distance from each LED to the light. When this condition

    is met, the stepper motor is commanded to halt. However, if the LEDs have largely different outputs as

  • 8/3/2019 Team Revolver

    3/21

    demonstrated in the figure above, the motor will be ordered to rotate towards the LED which produces

    the stronger signal, thus working to re-center the light.

    In order to initially locate the light, the motor spins counter-clockwise, until a minimum

    specified intensity is reached in each LED output. At the time this threshold is met, the sensors have

    identified the existence of a light source, and the primary algorithm (previous described) engages to

    track the light.

    Once the light has been centered for the first time, a counter is set such that the code will start

    recording angular displacement, using that initial center location as a zero degree reference. On

    average, the motor turns 1.8 degrees per step.

    It is important to note that when used as a photo LED, the output of an LED is a current, so

    transimpedance op-amps were used to convert this signal into a scaled voltage before analog to digital

    conversion within the microcontroller. Below is a table of count readings as they pertain to the various

    command sequences described above.

    Condition Environment Objective Command

    LEDLeft and LEDRight

    are both less than 35

    counts.

    No detected light

    source.

    Seek a light source. Rotate CW one step.

    LEDLeft is more than 30

    counts greater than

    LEDRight .

    The light is located to

    the left of centered

    alignment.

    Adjust alignment to

    achieve correct

    pointing.

    Rotate CCW one step.

    LEDRight is more than

    30 counts greater than

    LEDLeft .

    The light is located to

    the right of centered

    alignment.

    Adjust alignment to

    achieve correct

    pointing.

    Rotate CW one step.

    LEDLeft and LEDRight

    are within 30 counts of

    eachother.

    The light is within an

    acceptable centered

    pointing.

    Do not move. Do nothing. If this is the

    first time this condition

    is met, set conditional bit

    for angular tracking.

    Table 1: Overview of command logic based upon the count inputs of each LED. It should be noted that the choice of

    a +/- 30 count threshold between the LED readouts largely affects the accuracy of the tracker. If the number weresmaller, the system could potentially have a smaller angular error, but risks engaging in a jumping affect, where

    it oscillates between numerous, quick turns to the right and left while seeking a more perfect center. This is due to

    numerous electronic imperfections (largely from the LEDs) which cause physically unrepresentative undulations in

    the sensor output. Conversely, a larger number decreases the likelihood of jumping, but also decreases the pointing

    accuracy.

    Perhaps the most unique feature of the tracking tower design lies in its brush electrical

    connection system. Where most rival teams simply used lengthy conductive wire, we designed and

    implemented a brush motor system, preventing the need for any software corrections should the light

    source rotate 360 or more degrees around the tracking tower; it will simply continue to follow

    unimpeded. The rather lengthy design and troubleshooting process is described shortly. For pictures

    concerning the construction of the tower, reference appendix 5.

    Voltage Sensors

    In this project one of the requirements was to develop a system that can read the voltages from

    the batteries. To do this, two circuits were set up which would independently read in the voltages and

    pass them to the ADC. The reading of the positive voltage was very straight forward. The ADC can only

    read voltages between 0 to 5 volts, and the battery starts at 9 volts. To fix this problem we used a

    voltage divider to make sure the maximum voltage would never exceed 4.5 volts. After the divider the

  • 8/3/2019 Team Revolver

    4/21

    signal was sent to the ADC. It was at this time the voltage divider was replaced with a potentiometer.

    The value of the potentiometer was adjusted and counts read by the ADC were recorded. A plot of

    voltage v.s. counts was generated and a function was created and input into the ADC such that it could

    display proper voltage corresponding to the counts, as seen in figure 1. The calibration equation was

    found to be y = 0.0041x+0.0018 where y is the voltage and x is the counts to the microcontroller. As it

    can be seen in figure 1 the voltage sensor is linear.

    Figure 2 shows the calibration of the positive voltage count

    The negative signal went through a similar process, but it had to first pass through two

    additional op-amps. The first op-amp was a follower; this was added to make sure the next op-amp

    would not depend on the resistances before the follower. The second op-amp was an inverter with no

    gain. Since the negative battery was providing a negative signal the inverter was needed to ensure the

    signal entering the ADC was positive. We chose to do it in the hardware, but it can be noted that should

    we have wanted to we could have solved the issue in the code by changing our reference value in the

    microcontroller when initializing the ADC to a negative 5 volts. To calibrate we removed the voltage

    divider and replaced with a potentiometer to develop a relationship between counts and voltage, this

    can be seen in figure 2. After the relation for counts to volts was found, the voltage dividers were put

    back in place of the potentiometers. The calibration equation was found to be similar to that of the

    positive but with a different y intercept y = 0.0041x 0.0191

    y = 0.0041x + 0.0018

    0

    0.5

    1

    1.5

    2

    2.5

    3

    3.5

    4

    4.5

    200 400 600 800 1000

    Volts

    Counts

    +V

  • 8/3/2019 Team Revolver

    5/21

    Figure 3 shows calibration of the negative voltage monitor.

    A third voltage sensor was set up much the same way as the previous two but was monitoring

    the regulated voltage. The results from this sensor should stay the same throughout the usage of the

    system. If this starts decreasing that means the batteries are most likely dead or close to it. If this does

    drop it will cause everything else in the circuit to drop below their operating power, including the

    microcontroller which will cause data to be wrong.

    Thermistor

    The thermistor circuit seemed easy enough on paper but proved to be far more perplexing to

    physically construct and troubleshoot then anticipated. Developing the circuit required specific

    calculations and several op-amps, the details of which are described below.

    The circuit consisted of four op-amps used for a variety of reasons thermistors changeresistance depending on the temperature around the thermistor. For the thermistor in this circuit the

    outputs were in the milivolt range, but the ADC can read from 0 to 5 volts. To make our small range

    map to the larger range of the ADC we utilize op-amps. The four op-amps used were two voltage

    followers, a weighted summer, and an inverting amplifier. One of the two followers was placed after

    the thermistor and the other after the negative voltage source. These positive and negative voltages

    were fed into the summing amplifier which gave a new range of voltages. This new voltage was to be

    amplified and inverted by the inverting amplifier. The process above was necessary to ensure that the

    voltage readings coming from the thermistor were using the full range of the ADC.

    To have the thermistor give readings of voltage, we submitted the thermistor to a range of

    temperatures from 0 to 300C. These temperature readings were measured by a thermometer and

    recorded along with the corresponding counts to make a usable equation. This time the calibration was

    not linear but best fit was a cubic function. The temperature calibration equation was found to

    be .

    y = 0.0041x - 0.0191

    0

    0.5

    1

    1.5

    2

    2.5

    3

    3.5

    4

    4.5

    200 400 600 800 1000

    Volts

    Counts

    Volts -

  • 8/3/2019 Team Revolver

    6/21

    Figure 1 shows the calibration of the thermister.

    Pressure

    The pressure sensor was an easy device to sensor was an easy device to set up. The only thing

    that had to be done was the signal would be saturated at atmospheric pressure so a voltage divider was

    used to cut it in half and feed it to the microcontroller. After this it was given the wireless sensor so that

    It could be placed within the pressure chamber. Once a calibration test was run the data was graphed

    and a function was found. The data was found to be a linear relationship and the equation was found to

    be y = 0.2119x 13.196.

    y = -8E-09x3 + 1E-05x2 - 0.0364x + 33.885

    0

    5

    10

    15

    20

    25

    30

    35

    0 200 400 600 800 1000 1200

    Temperature

    Counts

    temp

    y = 0.2119x - 13.196

    0

    20

    40

    60

    80

    100

    120

    0 200 400 600

    Pressure (kPa)

    counts

    Pressure

    pres

    Linear (pres)

  • 8/3/2019 Team Revolver

    7/21

    Troubleshooting

    General Problems

    Throughout our project, we would develop the board and have multiple items working, but then

    they would suddenly stop. One problem we ran into was that our voltage from the battery would vary

    quickly and uncontrollably over a range of tens of milivolts. For the longest time, we could not figure outthe problem. As one early solution, we moved all of our electrical systems onto a new breadboard,

    believing that the initial breadboard had failed. Initially, the problem appeared to be solved.

    Unfortunately, after a short time, it reappeared. After many more hours of troubleshooting, we deduced

    that the Aerocom device was causing this error. The reason it jumped was because the device drew so

    much power whenever it needed to transmit, and during the other times it would be on standby using

    virtually no power.

    Thermistor

    While constructing the thermistor circuit, complications arose which lead to some design

    changes and lessons learned. The first problem that was discovered is an op-amp can and will not

    amplify an input voltage to the exact value of the voltage it uses as a supply. In our case the SDC wouldread zero to five Volts and the rail which supplied the op-amp was also set to five Volts. No matter what

    was done the output would not go above 4.5 V. To ensure an output of 5V from any op-amp used in our

    circuit, we should have given the power supply a voltage of 5.5V or greater. This will allow for losses in

    the circuit and the op-amp output signal to come closer if not match the goal of 5V.

    The second major issue was in the determination of the resistor value which was attached to the

    thermistor and made the voltage divider. The methods presented in Lab 15 were initially used to

    provide two possible values of 4.3 and 168.3k. (See appendix.) But upon implementing the 4.3

    resistor we saw the entire voltage across the thermistor, which would not change much with

    temperature. Then the 168.3k resistor was assembled and tested. Now the majority of the voltage was

    across the resistor resulting in only mV across the thermistor. The signal was detectable but the lower

    voltage which had to be subtracted by the summer could not be produced by our potentiometer setup.

    The desired voltage was too precise to get with the potentiometer.

    It was at this time a group member went to ask Dr. Butka for some advice. He suggested that a

    resistor which served as a half voltage divider be used with the thermistor. Heeding this advice we used

    a 1k resistor which divided the 5V source to approximately 2.5V. We then could heat and cool the

    thermistor, see the voltage change, and watch the counts in the ADC change accordingly.

    Brush System Design and Troubleshooting

    A basic and common design used by most of the teams for light tracker involved following the

    light around until a specific number of rotations were made. Once that number of rotations were done,

    the system would have to rotate back to its initial state to avoid winding of the LED feedback wires.

    We came up with an idea to eliminate the necessity of unwinding. The system was designed

    considering the limited parts and tools that were available for the team use. The first design consisted ofsix conductive rings (steel washers) equally spaced by small LEGO tires and stacked on top of each other

    to create an electrical tower. The plan was to have LEDs wires come down from the main frame and

    touch the rings to create a complete electrical path.

    This first challenge the team faced was building a stable ring tower that would conserve its

    structure while transferring electrical input from a breadboard, without obscuring any other part of the

    system. The solution brought to table was using hot glue to keep things in place. In addition to its easy

  • 8/3/2019 Team Revolver

    8/21

    application, hot glue can easily come off the system if something went wrong. This proved itself to be

    very useful all throughout the production of the stepper motor brush system.

    The second challenge was faced when the team realized that running wires through the holes in

    the rings would obscure the rod that held the main frame for LEDs. To overcome this challenge, it was

    decided to drill additional holes into inner circle of the rings to run wires through. The first ring (the one

    above all) was given three holes. One for running the wire through and two for wrapping the wire

    around since soldering to the steel washers was not an effective mean of joining the ring and the wire.

    Every ring going from the top to bottom had one extra hole than the one above. This ensured wires

    reach to upper rings.

    The next challenge was the biggest. It was critical that he leads that came down from the LEDs

    had firm, constant contact with the rings at each level. Initially, the system was designed for three LEDs,

    each LED with two terminal rings. However, after many connection and mounting complications, we

    decided to use two LEDs with a common ground, requiring only 3 rings, thus making the design much

    simpler. Conductive metal brushes were used first; however, due to high torques applied to the system

    with this design, the brush idea had to be abandoned. A rigid straw running down on the outer side of

    rings was screwed on to the frame to serve as a wire path. The straw was later replaced by a wooden

    stick to increase rigidity of the transmission pole. Connective forks were then attached to the tips of the

    wires to serve as brush system. This outfitting was able to demonstrate that it could follow the light forone or more full rotations. Nonetheless, the conductive forks also had drawbacks, both with impeding

    motor movement and having somewhat unreliable connectivity. These problems could cause the system

    to fail entirely.

    Largely, these errors were built into our project with the limited amount of available tools and

    resources. Most often, failures were caused when the system would mechanically get stuck. To prevent

    this, ring surfaces were cleaned, removing the impurities that brushes would run into. Furthermore, to

    an electrically conductive lubricant was liberally applied across the rings. At this stage, the stepper

    motor and the brush system were much more functional.

    Future designs could be improved with the usage of better constructions materials, such as rigid

    spacers, implementation of a neater production process and better machining tools.

    The One Hour Test

    The test was performed in the pressure chamber with all devices integrated onto one system,

    drawing power from the same battery sources. The test was done over one hour with information being

    sent out every 9 seconds. The system was able to survive the whole one hour test without any

    problems and still maintained power to everything. The battery voltage levels were recorded and put

    into a graph to find the drain of it over time. It was found that by the end of the test the voltage on the

    positive battery drained about 1 volt and the negative voltage did not drain at all. The real reason for

    this is because not much of the negative voltage is used besides powering the amplifiers. The regulated

    voltage stayed constant as it was expected. The pressure sensor worked well and shows a gradualincrease in pressure with time. The temperature decreased with the decrease of pressure as can be seen

    in Appendix 3. The temperature did a large drop when the pressure was at 5 kPa but shot back up in a

    few seconds when the pressure leaked a bit 15 kPa. This could be because the thermistor does not

    operate well at that low of pressure and was unable to give a useful reading.

  • 8/3/2019 Team Revolver

    9/21

    Appendix

    Appendix 1:

    0

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    0.

    15

    2.

    85

    5.

    55

    8.

    25

    10

    .95

    13

    .65

    16

    .35

    19

    .05

    21

    .75

    24

    .45

    27

    .15

    29

    .85

    32

    .55

    35

    .25

    37

    .95

    40

    .65

    43

    .35

    46

    .05

    48

    .75

    51

    .45

    54

    .15

    56

    .85

    59

    .55

    62

    .25

    Voltage (V)

    Time (min)

    Voltages

    supply

    positive

    negative

  • 8/3/2019 Team Revolver

    10/21

    Appendix 2:

    0

    20

    40

    60

    80

    100

    120

    0.

    15

    2.

    4

    4.

    65

    6.

    9

    9.

    15

    11

    .4

    13

    .65

    15

    .9

    18

    .15

    20

    .4

    22

    .65

    24

    .9

    27

    .15

    29

    .4

    31

    .65

    33

    .9

    36

    .15

    38

    .4

    40

    .65

    42

    .9

    45

    .15

    47

    .4

    49

    .65

    51

    .9

    54

    .15

    56

    .4

    58

    .65

    60

    .9

    Pressure kPa

    Time (min)

    Pressure

  • 8/3/2019 Team Revolver

    11/21

    Appendix 3:

    0

    5

    10

    15

    20

    25

    0.

    15 3

    5.

    85

    8.

    7

    11

    .55

    14

    .4

    17

    .25

    20

    .1

    22

    .95

    25

    .8

    28

    .65

    31

    .5

    34

    .35

    37

    .2

    40

    .05

    42

    .9

    45

    .75

    48

    .6

    51

    .45

    54

    .3

    57

    .15

    60

    Temperature (0C)

    Time (min)

    Temperature

    Series1

  • 8/3/2019 Team Revolver

    12/21

    Appendix 4:

  • 8/3/2019 Team Revolver

    13/21

    Appendix 5:

  • 8/3/2019 Team Revolver

    14/21

    Appendix 6: Code

    /*----------------------------------------------------------------------------

    //

    //

    //

    // TEAM MEMBERS: Ian Bryan// Marcus Jackson

    // Murat Tunca Aygun

    // Ted Dabrowski

    // Nathalie Vasquez

    //

    // PROJECT: Proto-CubeSat

    //

    // DEADLINE: May 4th, 2011

    //

    // NOTES: Code is current set for 1 hour trial. Commented blocks of

    // code are seen in typical use.*//---------------------------------------------------------------------------

    #include

    #include

    #include

    #include

    //CPU Frequency

    #define F_CPU 1000000UL

    #define UART_BAUD 4800

    //Define Baud Rate as described in AVR manual

    //***used for usb transmission also ***

    //***comment out line in uart_init()***

    //#define UART_UBBR_VALUE (((F_CPU / (UART_BAUD * 16UL))) - 1)

    //***used for wireless transmission ***

    #define UART_UBBR_VALUE (12)

    //-----------------------------------------------------------------------------

    // Following are some function prototyes

    //-----------------------------------------------------------------------------

    //Display functionvoid display(float volsup, float volpos, float volneg, float pres, float temp, float angle);

    //measument functions

    void vol_display(float *volsup, float *volpos, float *volneg);

    float pressure(float pres);

    float temperature(float temp);

  • 8/3/2019 Team Revolver

    15/21

    //UART

    void uart_init(); // This function initializes the AVR UART

    void write_uart(char c[]); //This function writes a string to the uart

    //ADC conversion

    void adc_init();

    //x selects mux and y selects the analog

    int analog(int x, int y);

    //------------------------------------------------------------------------------

    //Start Main

    //------------------------------------------------------------------------------

    int main(){

    /*Define Variables*/

    float volpos;

    float volneg;float volsup;

    float pres;

    float temp;

    int16_t LEDLeft;

    int16_t LEDRight;

    int16_t LEDdiff;

    float angle = 0; //degrees

    int i;int C = 0; //define a "check" variable

    float offset = 1.8; //Hardcoded value = number of degress in one step

    /*Stepper Motor Initilization Stuff*/

    DDRB |= 0x0F; // Set Register B PINS 0-3 High, i.e. configure as output

    int step[4]={0x0c, 0x06, 0x03, 0x09}; // CW Full step.Set the stepping sequence of the stepper motor

    int cstep[4]={0x0c, 0x09, 0x03, 0x06}; // cCW Full step.Set the stepping sequence of the stepper motor

    /*Light Indication System Initialization*/

    DDRC |= (0xFF); //Set all of Port C as outputs

    // This function will initialize and properly setup the AVR UART

    uart_init();

    // This function will initialize the adc conversion

    adc_init();

    //Delcare Switch selection ports as "outputs"

    DDRC |= (0x03);

  • 8/3/2019 Team Revolver

    16/21

    while(1){ // repeat forever

    volsup = analog(0,0);

    //Get voltage reedings using a voltage divider with two 1k ohm resistors

    //Selectively take MUX data based on which ADC port it outputs to

    volpos = analog(0,1);

    volneg = analog(0,2);

    vol_display(&volsup, &volpos, &volneg);

    //insert current sensor

    //Get pressure sensor information

    pres = pressure(analog(0,3));

    //Get the temperature

    temp = temperature(analog(0,4));

    /*Get PhotoLED readings and rotate accordingly*/

    /*LED Reading stuff*/

    LEDLeft = analog (0,5); //Gets the counts value of each LED

    LEDRight = analog (0,6);

    LEDdiff = fabs(LEDLeft-LEDRight);

    PORTC &= (0xF8); //Clear any previous LED information.

    if (LEDRight < 35 && LEDLeft < 35)

    {

    /*Auto Rotate till light is apparent*/

    /*Take a step clockwise*/PORTB &= 0xF0; //Clear ports that are currently driving stepper motor to allow

    for new input

    _delay_ms(5);

    PORTB |= step[i]; // Cause the stepper motor to make a step

    _delay_ms(5);

    i=(i+1)%4;//change 4 to 8 for half step; // Setting the modulus so the stepping sequence

    repeats forever

    /*Assign physical value to the change in offset*/

    if (C == 1)

    angle = (angle - offset);

    }

    else if ((LEDRight > LEDLeft)&&(LEDdiff > 30))

    {

    PORTC |= (0x02); //Indicate that the motor needs to move RIGHT (CW) by

    activating an LED

    /*Take a step clockwise*/

  • 8/3/2019 Team Revolver

    17/21

    PORTB &= 0xF0; //Clear ports that are currently driving stepper motor to allow

    for new input

    _delay_ms(5);

    PORTB |= step[i]; // Cause the stepper motor to make a step

    _delay_ms(5);

    i=(i+1)%4;//change 4 to 8 for half step; // Setting the modulus so the stepping sequence

    repeats forever

    /*Assign physical value to the change in offset*/

    if (C == 1)

    angle = (angle - offset);

    }

    else if ((LEDLeft > LEDRight)&&(LEDdiff > 30))

    {

    PORTC |= (0x04); //Indicate that the motor needs to move LEFT (cCW) by

    activating an LED

    /*Take a step counter-clockwise*/

    PORTB &= 0xF0; //Clear ports that are currently driving stepper motor to allow

    for new input

    _delay_ms(5);

    PORTB |= cstep[i]; // Cause the stepper motor to make a step

    _delay_ms(5);

    i=(i+1)%4;//change 4 to 8 for half step; // Setting the modulus so the stepping sequence

    repeats forever

    /*Assign physical value to the change in offset*/

    if (C == 1)

    angle = (angle + offset);}

    else

    {

    PORTC |= (0x01); //Indicate that the motor has found its CENTER by activating

    an LED

    /*Check to see if this is the initial find of the light*/

    if (C == 0);

    C = 1; //let the code know it has found its origin

    }

    /*Angular saturation correction*/

    if (angle > 360)

    angle = (angle - 360);

    if (angle < 0);

    angle = (angle + 360);

  • 8/3/2019 Team Revolver

    18/21

    //displaying the recieved values to the serial port

    display(volsup, volpos, volneg, pres, temp, angle);

    }//end while

    } //end main function

    //------------------------------------------------------------------------------

    //display function

    //------------------------------------------------------------------------------

    void display(float volsup, float volpos, float volneg, float pres, float temp, float angle)

    {

    char buffer[100];

    /*//displaying the recieved values to the serial port

    sprintf(buffer, "\n\r**** Team Kickass ****\n\r");

    write_uart(buffer);

    sprintf(buffer, "\n\r**** Voltage Readings ****\n\r");

    write_uart(buffer);

    sprintf(buffer, "The Regulated Voltage is %f\n\r", volsup);

    write_uart(buffer);

    sprintf(buffer, "The Positive Voltage is %f\n\r", volpos);

    write_uart(buffer);

    sprintf(buffer, "The Negative Voltage is -%f\n\r", volneg);

    write_uart(buffer);sprintf(buffer, "\n\r **** Pressure ****\n\r");

    write_uart(buffer);

    sprintf(buffer, "The Pressure is %f kPa\n\r", pres);

    write_uart(buffer);

    sprintf(buffer, "\n\r **** Temperature **** \n\r");

    write_uart(buffer);

    sprintf(buffer, "The Temperature is %f degrees Celsius\n\r", temp);

    write_uart(buffer);

    sprintf(buffer, "\n\r **** Angle **** \n\r");

    write_uart(buffer);

    sprintf(buffer,"Angle = %d\n\r", angle); //Convert and save values as a string for data packet

    write_uart(buffer);

    //_delay_ms(2000);

    */

    //used for ground station matlab code

    sprintf(buffer, "sup %f pos %f neg %f pres %f temp %f angle %f \n\r",volsup, volpos, volneg,

    pres, temp, angle);

    write_uart(buffer);

    _delay_ms(60000);

  • 8/3/2019 Team Revolver

    19/21

    }

    //------------------------------------------------------------------------------

    //Temperature Function

    //------------------------------------------------------------------------------

    float temperature(float temp)

    {

    temp = -8 * pow(10,-9) * pow(temp,3) + pow(10,-5) * pow(temp,2) - 0.0364 * temp + 33.885;

    return(temp);

    }

    //------------------------------------------------------------------------------

    //voltage function

    //------------------------------------------------------------------------------

    void vol_display(float *volsup, float *volpos, float *volneg){

    int sup = *volsup;

    int pos = *volpos;

    int neg = *volneg;

    ;

    //equation to convert the counts to voltage values

    *volsup = (0.005 * sup - 0.439)*2;

    *volpos = (0.0041 * pos +0.0618)*3;

    *volneg = (0.0041 * neg + 0.4919)*2;

    }//end vol_display function

    //------------------------------------------------------------------------------

    //Pressure Function

    //------------------------------------------------------------------------------

    float pressure(float pres)

    {

    //Conversion for pressure sensor

    pres = 0.2119* pres - 13.616;

    return(pres);

    }//end pressure function

    //------------------------------------------------------------------------------

    //UART Functions

    //------------------------------------------------------------------------------

  • 8/3/2019 Team Revolver

    20/21

    void uart_init()

    {

    /*Set Baud rate*/

    UBRR0H = UART_UBBR_VALUE >> 8;

    UBRR0L = UART_UBBR_VALUE;

    /*Frame format: 8 data bits, no parity, 1 stop bit*/

    UCSR0C = (1

  • 8/3/2019 Team Revolver

    21/21

    PORTC &= (0xFC); // Clear previos selections

    PORTC |= (x); // Select multiplexer pin (First MUX out pair 0)

    */

    //return the ADC target to default (ADC0) by clearing ADMUX

    ADMUX &= (0xE0);

    // Set the correct ADC port to take data from

    //(based on the input of the requesting sensor)

    ADMUX |= (y);

    ADCSRA |= (1