Changeset - f04abd553284
[Not reviewed]
Merge default
0 6 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-18 16:50:38
ethanzonca@CL-ENS241-08.cedarville.edu
Merge
6 files changed with 51 insertions and 27 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -31,14 +31,14 @@
 
#define SENSOR_LOOP 100				// Frequency of sensor reads (in ms) (should be 200)
 
#define HEATER_THRESHOLD 40			// Temperature threshold in Fahrenheit where heater is activated
 
 
 //I2C Addresses
 
 #define EEPROM_ADDR 0xA0		// Read 0xA1 - Write 0xA0
 
 #define BOARDTEMP_ADDR 0x90	// Read 0x91 - Write 0x90
 
 #define PRESSURE_ADDR 0xEF		// Read 0xEF - Write 0xEE
 
 #define HUMID_ADDR 0x27		// Read 0x27 - Write 0x26
 
 #define LIGHT_ADDR 0x95		// Read 0x95 - Write 0x94
 
 #define PRESSURE_ADDR 0xEE		// Read 0xEF - Write 0xEE
 
 #define HUMID_ADDR 0x26		// Read 0x27 - Write 0x26
 
 #define LIGHT_ADDR 0x94		// Read 0x95 - Write 0x94
 
 #define RTC_ADDR 0xB2			//DEBUG [Used for testing]      // Read 0xA3 - Write 0xA2
 
 
 
 
 #endif /* CONFIG_H_ */
 
\ No newline at end of file
slave/slave/lib/masterComm.c
Show inline comments
 
@@ -87,16 +87,16 @@ void masterComm_packetSend_signed(uint8_
 
void masterComm_modules()
 
{
 
	// Send Board Temperature (Common for all modules)
 
	masterComm_packetSend_signed(0,sensors_getBoardTemp());
 
 
	// Send Heater Status (Common for all modules)
 
	masterComm_packetSend_unsigned(1,/*Heater Status Get Function Here */0);
 
	masterComm_packetSend_unsigned(1,io_heaterStatus());
 
	
 
	// Send Battery Level (Common for all modules)
 
	masterComm_packetSend_unsigned(2,/*Battery Level Get Function Here */0);
 
	masterComm_packetSend_unsigned(2,/*Battery Level Get Function Here */999);
 
	
 
	
 
	// Send module specific sensor readings
 
	switch(io_getModuleId())
 
	{
 
		case 0:
 
@@ -108,22 +108,22 @@ void masterComm_modules()
 
			// Sensors
 
			
 
			// Send SPI Temperature (Air)
 
			masterComm_packetSend_unsigned(3,sensors_getSpiTemp());
 
			
 
			// Send Ambient Light (Needs to be formatted)
 
			masterComm_packetSend_unsigned(4,/*Ambient Light Get Function Here */123);
 
			masterComm_packetSend_unsigned(4,sensors_getLux());
 
			
 
			// Send Humidity
 
			masterComm_packetSend_unsigned(5,/*Humidity Get Function Here */456);		
 
			masterComm_packetSend_unsigned(5,/*Humidity Get Function Here */999);		
 
			
 
			// Send Pressure 
 
			masterComm_packetSend_unsigned(6,/*Pressure Get Function Here */7890);			
 
			masterComm_packetSend_unsigned(6,sensors_getPressure());			
 
			
 
			// Send Altitude
 
			masterComm_packetSend_unsigned(7,/*Altitude Get Function Here */456789);
 
			masterComm_packetSend_unsigned(7,sensors_getAltitude());
 
			break;
 
			
 
		case 2:
 
			// Geiger
 
			
 
			// Send CPM (radiation)
slave/slave/lib/sensors.c
Show inline comments
 
@@ -4,12 +4,13 @@
 
 * Created: 11/19/2012 9:25:01 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <math.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "sensors.h"
 
#include "spi.h"
 
@@ -18,13 +19,17 @@
 
int16_t	spiTemp;	// Thermocouple Temperature (from spi)
 
int8_t	boardTemp;	// Board Temperature (from i2c)
 
//Should these two be int16_t?  CHANGED TO INT32 BASED ON DATASHEET
 
int32_t ut;			// Temperature from BMP085 (from i2c)
 
int32_t up;			// Pressure from BMP085 (from i2c)
 
uint16_t humid;		// Humidity (from i2c)
 
uint8_t light;		// Lux reading (from i2c)
 
uint8_t lightH;		// Higher byte from light sensor (from i2c)
 
uint8_t lightL;		// Lower byte from light sensor
 
uint8_t exponent;	// Exponent for Lux
 
uint8_t mantissa;	// Mantissa for Lux
 
uint32_t lux;		// Calculated Lux value
 
int8_t batt;		// Read battery voltage from ADC
 
 
int16_t ac1;		// The following 11 variables are the calibration values for the BMP085
 
int16_t ac2;
 
int16_t ac3;
 
uint16_t ac4;
 
@@ -43,12 +48,13 @@ int32_t b3;
 
uint32_t b4;
 
int32_t b5;
 
int32_t b6;
 
uint32_t b7;
 
int32_t trueTemp;
 
int32_t pressure;
 
uint32_t altitude;
 
 
 
 
void sensors_setupPressure()
 
{
 
	//This function reads in the calibration values from the BMP085.  This is done only once.
 
@@ -129,19 +135,19 @@ void sensors_readBoardTemp()
 
	boardTemp = ((boardTemp*18)/10) + (32);			// Converting Celsius to Fahrenheit
 
	boardTemp = boardTemp - 3;						// Linear offset
 
}
 
 
void sensors_readPressure()
 
{
 
	i2c_write(0xEE, 0xF4, 0x2E);				//write 0x2E (temp) into 0xF4 (control register), (write is 0xEE)
 
	i2c_write(PRESSURE_ADDR, 0xF4, 0x2E);				//write 0x2E (temp) into 0xF4 (control register), (write is 0xEE)
 
	_delay_us(4500);							//wait 4.5 ms
 
	ut = i2c_read(PRESSURE_ADDR, 0xF6);
 
	ut = ut << 8;
 
	ut = ut | i2c_read(PRESSURE_ADDR, 0xF7);	//ut = MSB<<8 + LSB
 
	
 
	i2c_write(0xEE, 0xF4, 0x34);				//write 0x34 (pressure) into 0xF4 (control register), (write is 0xEE)
 
	i2c_write(PRESSURE_ADDR, 0xF4, 0x34);				//write 0x34 (pressure) into 0xF4 (control register), (write is 0xEE)
 
	_delay_us(4500);							//wait 4.5 ms
 
	up = i2c_read(PRESSURE_ADDR, 0xF6);
 
	up = up << 8;
 
	up = up | i2c_read(PRESSURE_ADDR, 0xF7);	//up = (MSB<<16 + LSB<<8 + XLSB(NOT USED)) >> (8-oss)
 
	
 
	//calculate true temperature
 
@@ -176,29 +182,41 @@ void sensors_readPressure()
 
	}
 
	
 
	x1 = (pressure >> 8) * (pressure >> 8);
 
	x1 = (x1 * 3038) >> 16;
 
	x2 = (-7357 * pressure) >> 16;
 
	pressure += (x1 + x2 + 3791) >> 4;				//This is the final value for our pressure
 
	
 
	//altitude = 44330 * (1 - pow((pressure / 101325), (1 / 5.255)));
 
	altitude = (float)44330 * (1 - pow(((float) pressure/101325), 0.190295));
 
}
 
 
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()
 
void sensors_readLux()
 
{
 
	// 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
 
	lightH = i2c_read(LIGHT_ADDR, 0x03);
 
	lightL = i2c_read(LIGHT_ADDR, 0x04);
 
	
 
	exponent = lightH;
 
	exponent = exponent >> 4;
 
	
 
	lightH = lightH << 4;
 
	mantissa = lightH | lightL;
 
	//mantissa = mantissa << 4;
 
	//mantissa = mantissa >> 4;
 
	
 
	//lux = (pow(2, exponent) * (float)(mantissa * 0.045));
 
	lux = (float)(pow(2,exponent) * mantissa) * 0.045;
 
 
	// 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
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 128xM7 + 64xM6 + 32xM5 + 16xM4 + 8xM3 + 4xM2 + 2xM1 + M0
 
@@ -227,16 +245,21 @@ int32_t sensors_getPressure(void)	// Get
 
 
uint16_t sensors_getHumid(void)			// Gets relative humidity from variable
 
{
 
	return humid;
 
}
 
 
uint8_t sensors_getLight(void)		// Gets light from variable
 
uint32_t sensors_getLux(void)		// Gets light from variable
 
{
 
	return light;
 
	return lux;
 
}
 
 
//possibly uint8_t
 
int8_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return batt;
 
}
 
 
uint32_t sensors_getAltitude(void)
 
{
 
	return altitude;
 
}
 
\ No newline at end of file
slave/slave/lib/sensors.h
Show inline comments
 
@@ -12,17 +12,18 @@
 
 
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_readLux(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
 
uint32_t sensors_getLux(void);		// Gets lux from variable
 
int8_t sensors_getBatt(void);		// Gets battery voltage from variable
 
uint32_t sensors_getAltitude(void);		// Gets altitude from variable
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -120,16 +120,16 @@
 
  
 
 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_readPressure();			//Data Read
 
	//sensors_readHumid();				//Data Read
 
	//sensors_readLight();				//Data Read
 
	sensors_readBatt();
 
	sensors_readLux();				//Data Read
 
	sensors_readBatt();				//Data Read
 
	 
 
 }
 
  
 
 void modules_geiger()
 
 {
 
	// No data gatering function needed for geiger daughter board
slave/slave/slave.c
Show inline comments
 
@@ -59,13 +59,13 @@ int main(void)
 
	
 
	//uint8_t test;		//Debug
 
	//uint8_t test2;	//Debug	
 
	
 
	
 
	// Serial output //DEBUG
 
	char buff[64];							//Buffer for serial output //DEBUG
 
	char buff[128];							//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");
 
			
 
    while(1)
 
    {	
 
		
 
		// Master communication
 
@@ -79,14 +79,14 @@ int main(void)
 
			led_on(0);
 
			sensors_readBoardTemp();	// Read board temperature sensor (Common on all slaves) (Data Read)
 
			modules_run(io_getModuleId());		// Runs specific module functions (like data reading)
 
			
 
			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 

	
 
			//snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |SpiTemp: %i\r\n",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getSpiTemp()); //DEBUG
 
			//serial0_sendString(buff); //DEBUG
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Heater: %u |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu \r\n",io_getModuleId(),sensors_getBoardTemp(),io_heaterStatus(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude()); //DEBUG
 
			serial0_sendString(buff); //DEBUG
 

	
 
			_delay_ms(2);		// Delay to prevent the sensor loop from running again before time_millis changes
 
			led_off(0);
 
			led_off(2);
 
		}
 

	
0 comments (0 inline, 0 general)