Changeset - 6fe1c15f9458
[Not reviewed]
default
0 2 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-02-14 15:31:31
kripperger@CL-SEC241-09.cedarville.edu
Fixes for sensors
2 files changed with 5 insertions and 5 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/sensors.c
Show inline comments
 
@@ -161,50 +161,50 @@ void sensors_readPressure()
 
	
 
	//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)
 
	{
 
		pressure = (b7 << 1) / b4;
 
	}
 
	
 
	else
 
	{
 
		pressure = (b7 / b4) << 1;
 
	}
 
	
 
	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));
 
	//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()
 
{
 
	// 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
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 128xM7 + 64xM6 + 32xM5 + 16xM4 + 8xM3 + 4xM2 + 2xM1 + M0
 
	// light = 2^(exponent)*mantissa*0.045
slave/slave/slave.c
Show inline comments
 
@@ -41,70 +41,70 @@ void micro_setup()
 
	sei();	// Enable interrupts
 
	
 
}
 

	
 

	
 
int main(void)
 
{
 
	// Initialize		
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();			// Setup loop timer and interrupts (TIMER0)
 
	led_configure();		// Configure ports and registers for LED operation
 
	io_configure();			// Configure IO ports and registers
 
	i2c_init();				// Setup I2C
 
	serial0_setup();		// Config serial port
 
	
 
	io_readModuleId();
 
	modules_setup(io_getModuleId());				// Run setup functions for specific module
 

	
 
	
 
	//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
 
		masterComm_checkParser();
 
			
 
		
 
		
 
		// Main slave operations
 
		if ((time_millis() % SENSOR_LOOP) == 0)	// Uses program timer to run every so often. Time interval defined in config.h
 
		{
 
			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,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Light: %u |Pressure: %u \r\n",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLight(),sensors_getPressure()); //DEBUG
 
			serial0_sendString(buff); //DEBUG
 
			//snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Light: %u |Pressure: %lu |Altitude: %lu \r\n",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLight(),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);
 
		}
 

	
 
    }
 
	
 
	return 0;
 
}
 

	
 

	
 

	
 

	
 

	
 
		/********Examples of data reading and getting******************
 
		x = geiger_getCpm();				//Data get
 
		x = sensors_getSpiTemp();			//Data get
 
		x = sensors_getBoardTemp();			//Data get
 
		
 
		sensors_readSpiTemp();				//Data Read
 
		sensors_readBoardTemp();			//Data Read
 
		
 
		led_output(0xFF);					//Output value to LED array
0 comments (0 inline, 0 general)