0% found this document useful (0 votes)
85 views

Team Revolver: EP 391 Microprocessors

The document summarizes a student project to design a light tracking system using various sensors. The system uses LEDs to detect and track a light source, and a stepper motor to align the sensors. Voltage, temperature, and pressure sensors send data to be displayed. The code was calibrated to read sensor values and send data packets. A brush mechanism allows the light to rotate freely without tangled wires affecting tracking.

Uploaded by

Ian Bryan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views

Team Revolver: EP 391 Microprocessors

The document summarizes a student project to design a light tracking system using various sensors. The system uses LEDs to detect and track a light source, and a stepper motor to align the sensors. Voltage, temperature, and pressure sensors send data to be displayed. The code was calibrated to read sensor values and send data packets. A brush mechanism allows the light to rotate freely without tangled wires affecting tracking.

Uploaded by

Ian Bryan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Team Revolver

EP 391 Microprocessors

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 of the 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

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 No detected light Seek a light source. Rotate CW one step. are both less than 35 source. counts. LEDLeft is more than 30 The light is located to Adjust alignment to Rotate CCW one step. counts greater than the left of centered achieve correct LEDRight . alignment. pointing. LEDRight is more than The light is located to Adjust alignment to Rotate CW one step. 30 counts greater than the right of centered achieve correct LEDLeft . alignment. pointing. LEDLeft and LEDRight The light is within an Do not move. Do nothing. If this is the are within 30 counts of acceptable centered first time this condition eachother. pointing. 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 were smaller, 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

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.

+V
4.5 4 3.5 3 2.5 Volts 2 1.5 1 0.5 0 200 400 Counts
Figure 2 shows the calibration of the positive voltage count

y = 0.0041x + 0.0018 600 800 1000

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

Volts 4.5 4 3.5 3 2.5 Volts 2 1.5 1 0.5 0 200 400 600 Counts
Figure 3 shows calibration of the negative voltage monitor.

y = 0.0041x - 0.0191 800 1000

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 change resistance 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 .

temp
35 30 25 Temperature 20 15 10 5 0 0 200 400 600 Counts
Figure 1 shows the calibration of the thermister.

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

800

1000

1200

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.

Pressure
120 100 80 Pressure (kPa) 60 40 20 0 0 200 counts 400 600 pres Linear (pres) y = 0.2119x - 13.196

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 out the 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 would read 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 of six 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

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 for one 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 gradual increase 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.

Appendix 1:

Appendix

10

Voltage (V) 5

Voltages

Time (min) negative

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

supply

positive

Appendix 2:

Pressure kPa 60

20

40

80

100

120

Pressure

Time (min)

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

Appendix 3:

Temperature (0C) 10 15 20 25

Temperature

Time (min)

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

Series1

Appendix 4:

Appendix 5:

Appendix 6: Code /*---------------------------------------------------------------------------// <<TEAM REVOLVER>> // // // 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 <avr/io.h> #include <util/delay.h> #include <stdio.h> #include <math.h> //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 function void 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);

//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);

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*/

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);

//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 /* //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); buffer[100];

} //-----------------------------------------------------------------------------//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 //------------------------------------------------------------------------------

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<<UCSZ01)|(1<<UCSZ00); /*Enable Transmit and Receive*/ UCSR0B = (1<< RXEN0)|(1<<TXEN0); //used to set the double clock for wireless transmission comment out for usb UCSR0A = (1<< U2X0); //set double clock speed } //--------------------------------------------------------------------------------void write_uart(char c[]) { do { while((UCSR0A&(1<<UDRE0)) == 0); // Wait for Transmit Buffer to Empty UDR0 = *c; // Transmit the character c++; // Increment the pointer to point to the next character }while(*c != '\0'); } //-------------------------------------------------------------------------------//ADC functions //-------------------------------------------------------------------------------void adc_init () { ADCSRA |= (1<<ADPS1) | (1<<ADPS0); // Set ADC prescalar to 8 (125khz) ADMUX |= (1<<REFS0); // This sets ADC reference to AVCC ADMUX |= (0<<ADLAR); // set for full ten bits ADCSRA |= (1<<ADEN); // Enable ADC } //-------------------------------------------------------------------------------int analog (int x, int y) //Generic ADC function. Operates on bit specified by // function input { //Declare a 16 bit register for data storage uint16_t ir; /*Old MUX Code*/ /* -- Was funtional, dicontinued use of MUX --//multiplexer selection pin x, y for micro controller

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 << ADSC); // Start ADC Conversions of the sensor while ((1 << ADSC) & ADCSRA) {} // Wait until conversion is complete ir = (ADCL|(ADCH<<8)); //Store data of conversions from high and low registers return (ir); //send ADC value back to requesting code }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy