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
 
@@ -13,24 +13,30 @@
 
 
int8_t	moduleID;	// Slave Module ID from rotary dip switch (or EEPROM)
 
 
 void io_configure()
 
 {
 
	// Configure ports/pins
 
	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); 
 
	
 
 }
 
 
 
 
 
 
   
 
 
 
 
 
 void io_readModuleId()
 
 {
 
	// Get ID from rotary dip and return it. 
 
	moduleID = 0;
 
	
slave/slave/lib/sensors.c
Show inline comments
 
@@ -35,25 +35,25 @@ int16_t mb;
 
int16_t mc;
 
int16_t md;
 
 
int32_t x1;			// The following variables are needed to calculate the true pressure
 
int32_t x2;
 
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.
 
	ac1 = i2c_read(PRESSURE_ADDR, 0xAA);
 
	ac1 = ac1 << 8;
 
	ac1 = ac1 | i2c_read(PRESSURE_ADDR, 0xAB);
 
	
 
	ac2 = i2c_read(PRESSURE_ADDR, 0xAC);
 
	ac2 = ac2 << 8;
 
@@ -157,73 +157,74 @@ void sensors_readPressure()
 
	b3 = ((ac1 * 4 + x3) + 2) / 4;
 
	
 
	//calculate b4
 
	x1 = (ac3 * b6) >> 16;
 
	x2 = (b1 * ((b6 * b6) >> 12)) >> 16;
 
	x3 = ((x1 + x2) + 2) >> 2;
 
	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;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	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;
 
}
 
 
uint8_t sensors_getLight(void)		// Gets light from variable
 
{
 
	return light;
 
}
 
\ No newline at end of file
slave/slave/lib/sensors.h
Show inline comments
 
@@ -7,20 +7,22 @@
 
 
 
#ifndef SENSORS_H_
 
#define SENSORS_H_
 
 
 
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
 
@@ -117,24 +117,25 @@
 
	// Gathers data and performs functions for generic daughter board
 
	
 
 }
 
  
 
 void modules_sensors()
 
 {
 
	// 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
 
		// This is taken care of in interrupt (See geiger.c)
 
	  
 
 }
 
  
 
 void modules_cameras()
 
 {
0 comments (0 inline, 0 general)