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
 
@@ -19,12 +19,18 @@ int8_t	moduleID;	// Slave Module ID from
 
	DDRB |= (1 << DDB4);		// Set PB4 to Output for Heater (also allows SCK to operate)
 
	
 
	DDRC &= ~(1 << DDC2);		// Set PC2 to input for rotary dip    //TEMPORARY//
 
	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
 
@@ -41,13 +41,13 @@ int32_t x3;
 
int32_t b3;
 
uint32_t b4;
 
int32_t b5;
 
int32_t b6;
 
uint32_t b7;
 
int32_t trueTemp;
 
int32_t truePres;
 
int32_t pressure;
 
 
 
 
void sensors_setupPressure()
 
{
 
	//This function reads in the calibration values from the BMP085.  This is done only once.
 
@@ -163,47 +163,48 @@ void sensors_readPressure()
 
	b4 = (ac4 * (x3 + 32768)) >> 15;
 
	
 
	b7 = (up - b3) * 50000;
 
	
 
	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()
 
{
 
	humid = i2c_read16(HUMID_ADDR);
 
	
 
	//calculations to relative humidity: humid = (humid/((2^14) - 1))*100%       >> is divide by power, << is multiply by power, 2^14-1 = 16383
 
	humid = (humid / 16383) * 100;
 
}
 

	
 
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
 
{
 
	return spiTemp;
 
}
 
@@ -212,13 +213,13 @@ int8_t sensors_getBoardTemp(void)	// Get
 
{
 
	return boardTemp;
 
}
 
 
int32_t sensors_getPressure(void)	// Gets pressure from variable
 
{
 
	return truePres;
 
	return pressure;
 
}
 
 
int sensors_getHumid(void)			// Gets relative humidity from variable
 
{
 
	return humid;
 
}
slave/slave/lib/sensors.h
Show inline comments
 
@@ -13,14 +13,16 @@
 
void sensors_setupPressure(void);	// Reads pressure calibration values
 
void sensors_readSpiTemp(void);		// Reads spi temperature
 
void sensors_readBoardTemp(void);	// Reads board temperature
 
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
 
@@ -123,12 +123,13 @@
 
	// Gathers data and performs functions for sensor daughter board
 
	sensors_readBoardTemp();		//Data Read
 
	sensors_readSpiTemp();			//Data Read
 
	sensors_readPressure();			//Data Read
 
	sensors_readHumid();			//Data Read
 
	sensors_readLight();			//Data Read
 
	//sensors_readBatt();
 
	 
 
 }
 
  
 
 void modules_geiger()
 
 {
 
	// No data gatering function needed for geiger daughter board
0 comments (0 inline, 0 general)