Changeset - ec5ca12568cd
[Not reviewed]
default
0 4 0
mkroening@CL-ENS241-07.cedarville.edu - 12 years ago 2013-02-01 16:40:59
mkroening@CL-ENS241-07.cedarville.edu
Began mod for ADC
4 files changed with 23 insertions and 13 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -22,6 +22,12 @@ int8_t	moduleID;	// Slave Module ID from
 
	DDRC &= ~(1 << DDC3);		// Set PC3 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip    //TEMPORARY//
 
	
 
	DDRA &= ~(1 << DDA7);		// Set PA7 to input for battery voltage divider
 
	
 
	ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);
 
	ADMUX |= (1 << REFS0); 
 
	
 
 }
 
 
 
 
slave/slave/lib/sensors.c
Show inline comments
 
@@ -44,7 +44,7 @@ int32_t b5;
 
int32_t b6;
 
uint32_t b7;
 
int32_t trueTemp;
 
int32_t truePres;
 
int32_t pressure;
 
 
 
 
@@ -166,18 +166,18 @@ void sensors_readPressure()
 
	
 
	if (b7 < 0x80000000)
 
	{
 
		truePres = (b7 << 1) / b4;
 
		pressure = (b7 << 1) / b4;
 
	}
 
	
 
	else
 
	{
 
		truePres = (b7 / b4) << 1;
 
		pressure = (b7 / b4) << 1;
 
	}
 
	
 
	x1 = (truePres >> 8) * (truePres >> 8);
 
	x1 = (pressure >> 8) * (pressure >> 8);
 
	x1 = (x1 * 3038) >> 16;
 
	x2 = (-7357 * truePres) >> 16;
 
	truePres += (x1 + x2 + 3791) >> 4;				//This is the final value for our pressure
 
	x2 = (-7357 * pressure) >> 16;
 
	pressure += (x1 + x2 + 3791) >> 4;				//This is the final value for our pressure
 
}
 

	
 
void sensors_readHumid()
 
@@ -190,17 +190,18 @@ void sensors_readHumid()
 

	
 
void sensors_readLight()
 
{
 
	// FOR FIRST BYTE:
 
	light = i2c_read(LIGHT_ADDR, 0x03);
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 8xM7 + 4xM6 + 2xM5 + M4
 
	// light = 2^(exponent)*mantissa*0.72
 

	
 
	// FOR BOTH BYTES:
 
	// light = light << 4;
 
	// light = light | (0x0F & i2c_read(LIGHT_ADDR, 0x04));  //  This can be used to read in the 4 LSBs from the second register
 
	// FOR FIRST BYTE:
 
	// Lux = 2^(exponent)*mantissa*0.72
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 8xM7 + 4xM6 + 2xM5 + M4
 
	// FOR BOTH BYTES:
 
	// Lux = 2^(exponent)*mantissa*0.045
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 128xM7 + 64xM6 + 32xM5 + 16xM4 + 8xM3 + 4xM2 + 2xM1 + M0
 
	// light = 2^(exponent)*mantissa*0.045
 
}
 

	
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
@@ -215,7 +216,7 @@ int8_t sensors_getBoardTemp(void)	// Get
 
 
int32_t sensors_getPressure(void)	// Gets pressure from variable
 
{
 
	return truePres;
 
	return pressure;
 
}
 
 
int sensors_getHumid(void)			// Gets relative humidity from variable
slave/slave/lib/sensors.h
Show inline comments
 
@@ -16,11 +16,13 @@ void sensors_readBoardTemp(void);	// Rea
 
void sensors_readPressure(void);	// Reads pressure
 
void sensors_readHumid(void);		// Reads humidity
 
void sensors_readLight(void);		// Reads lux
 
//void sensors_readBatt(void);
 
 
int16_t sensors_getSpiTemp(void);	// Gets spi temperature from variable
 
int8_t sensors_getBoardTemp(void);	// Gets board temperature from variable
 
int32_t sensors_getPressure(void);	// Gets pressure from variable
 
uint16_t sensors_getHumid(void);	// Gets humidity from variable
 
uint8_t sensors_getLight(void);		// Gets lux from variable
 
//int_t sensors_getBatt(void);
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -126,6 +126,7 @@
 
	sensors_readPressure();			//Data Read
 
	sensors_readHumid();			//Data Read
 
	sensors_readLight();			//Data Read
 
	//sensors_readBatt();
 
	 
 
 }
 
  
0 comments (0 inline, 0 general)