Changeset - 82d01332900d
[Not reviewed]
default
0 5 0
mkroening@CL-ENS241-07.cedarville.edu - 12 years ago 2013-04-03 21:31:54
mkroening@CL-ENS241-07.cedarville.edu
Sensor fixes
5 files changed with 69 insertions and 94 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
@@ -30,8 +30,8 @@
 
//Sensors and IO
 
#define SENSOR_LOOP 200				// Frequency of sensor reads (in ms) (should be 200)
 
#define HEATER_THRESHOLD 0			// Temperature threshold in Fahrenheit where heater is activated
 
#define CAMERA_FREQ 5000		// Camera pulse frequency (Should be 30000 for 30 Secs)
 
#define CAMERA_PULSE 2500			// Camera pulse duration
 
#define CAMERA_FREQ 30000		// Camera pulse frequency (Should be 30000 for 30 Secs)
 
#define CAMERA_PULSE 500 			// Camera pulse duration
 
 
 //I2C Addresses
 
 #define EEPROM_ADDR 0xA0		// Read 0xA1 - Write 0xA0
slave/slave/lib/i2c.c
Show inline comments
 
@@ -46,7 +46,7 @@ unsigned char i2c_start(unsigned char ad
 
 
	// wait until transmission completed
 
//	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	while(!(TWCR & (1<<TWINT)));
 
//	{
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
@@ -64,7 +64,7 @@ unsigned char i2c_start(unsigned char ad
 
 
	// wail until transmission completed and ACK/NACK has been received
 
//	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	while(!(TWCR & (1<<TWINT)));
 
//	{
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
@@ -99,14 +99,14 @@ void i2c_start_wait(unsigned char addres
 
	    TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
 
    
 
    	// wait until transmission completed
 
		startTime = time_millis();
 
    	while(!(TWCR & (1<<TWINT)))
 
		{
 
			if ((time_millis() - startTime) > 10)
 
			{
 
				break;	// Timeout Reached!
 
			}
 
		}
 
		//startTime = time_millis();
 
    	while(!(TWCR & (1<<TWINT)));
 
		//{
 
			//if ((time_millis() - startTime) > 10)
 
			//{
 
				//break;	// Timeout Reached!
 
			//}
 
		//}
 
    
 
    	// check value of TWI Status Register. Mask prescaler bits.
 
    	twst = TW_STATUS & 0xF8;
 
@@ -117,14 +117,14 @@ void i2c_start_wait(unsigned char addres
 
    	TWCR = (1<<TWINT) | (1<<TWEN);
 
    
 
    	// wail until transmission completed
 
		startTime = time_millis();
 
    	while(!(TWCR & (1<<TWINT)))
 
		{
 
			if ((time_millis() - startTime) > 10)
 
			{
 
				break;	// Timeout Reached!
 
			}
 
		}
 
		//startTime = time_millis();
 
    	while(!(TWCR & (1<<TWINT)));
 
		//{
 
			//if ((time_millis() - startTime) > 10)
 
			//{
 
				//break;	// Timeout Reached!
 
			//}
 
		//}
 
    
 
    	// check value of TWI Status Register. Mask prescaler bits.
 
    	twst = TW_STATUS & 0xF8;
 
@@ -134,14 +134,14 @@ void i2c_start_wait(unsigned char addres
 
	        TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
 
	        
 
	        // wait until stop condition is executed and bus released
 
			startTime = time_millis();
 
	        while(TWCR & (1<<TWSTO))
 
			{
 
				if ((time_millis() - startTime) > 10)
 
				{
 
					break;	// Timeout Reached!
 
				}
 
			}
 
			//startTime = time_millis();
 
	        while(TWCR & (1<<TWSTO));
 
			//{
 
				//if ((time_millis() - startTime) > 10)
 
				//{
 
					//break;	// Timeout Reached!
 
				//}
 
			//}
 
	        
 
    	    continue;
 
    	}
 
@@ -179,7 +179,7 @@ void i2c_stop(void)
 
	
 
	// wait until stop condition is executed and bus released
 
//	startTime = time_millis();
 
	while(TWCR & (1<<TWSTO))
 
	while(TWCR & (1<<TWSTO));
 
	{
 
//		if ((time_millis() - startTime) > 10)
 
//		{
 
@@ -207,14 +207,14 @@ unsigned char i2c_writeX( unsigned char 
 
	TWCR = (1<<TWINT) | (1<<TWEN);
 
 
	// wait until transmission completed
 
	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
	}
 
	//startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)));
 
	//{
 
		//if ((time_millis() - startTime) > 10)
 
		//{
 
			//break;	// Timeout Reached!
 
		//}
 
	//}
 
	
 
	
 
	// check value of TWI Status Register. Mask prescaler bits
 
@@ -235,14 +235,14 @@ unsigned char i2c_readAck(void)
 
{
 
	TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
 
	
 
	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
	}  
 
	//startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)));
 
	//{
 
		//if ((time_millis() - startTime) > 10)
 
		//{
 
			//break;	// Timeout Reached!
 
		//}
 
	//}  
 
 
    return TWDR;
 
 
@@ -259,14 +259,14 @@ unsigned char i2c_readNak(void)
 
{
 
	TWCR = (1<<TWINT) | (1<<TWEN);
 
	
 
	startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)))
 
	{
 
		if ((time_millis() - startTime) > 10)
 
		{
 
			break;	// Timeout Reached!
 
		}
 
	}
 
	//startTime = time_millis();
 
	while(!(TWCR & (1<<TWINT)));
 
	//{
 
		//if ((time_millis() - startTime) > 10)
 
		//{
 
			//break;	// Timeout Reached!
 
		//}
 
	//}
 
	
 
    return TWDR;
 
slave/slave/lib/sensors.c
Show inline comments
 
@@ -186,8 +186,9 @@ void sensors_readPressure()
 
	x1 = (x1 * 3038) >> 16;
 
	x2 = (-7357 * pressure) >> 16;
 
	pressure += (x1 + x2 + 3791) >> 4;				//This is the final value for our pressure
 
	pressure = pressure - 21000;	// Linear Offset (Debug?)
 
	
 
	altitude = (float)44330 * (1 - pow(((float) pressure/101325), 0.190295));
 
	altitude = (float)44330 * (1 - pow(((float) pressure/101325), 0.190295));	// 101325
 
}
 
 
void sensors_readHumid()
slave/slave/modules.c
Show inline comments
 
@@ -18,7 +18,6 @@
 
 #include "lib/led.h"
 
 
 
 uint32_t lastPicture;
 
 uint8_t pulseOn;
 
 uint32_t lastRefresh;	// Time in ms when last geiger refresh occurred 
 
 
 
 void modules_setup(uint8_t id)
 
@@ -113,8 +112,7 @@
 
  
 
 void modules_cameras_setup()
 
 {
 
	 lastPicture = time_millis();
 
	 pulseOn = time_millis();	 
 
	 lastPicture = time_millis();	 
 
	 
 
	 DDRA |= (1 << DDA0);	// Set PA0 to Output for Camera
 
	 DDRA |= (1 << DDA1);	// Set PA1 to Output for Camera
 
@@ -156,25 +154,22 @@
 
  
 
 void modules_cameras()
 
 {
 
	 
 
	// Gathers data and performs functions for cameras daughter board
 
		
 
		//cameras_readAccelXYZ();
 
		
 
		//if ((time_millis() - pulseOn) > CAMERA_PULSE)
 
		//{
 
		//	PORTA &= ~(1 << PA0);	// Pull pin on usb low
 
		//	PORTA &= ~(1 << PA1);	// Pull pin on usb low
 
		//	PORTA &= ~(1 << PA2);	// Pull pin on usb low
 
		//	PORTA &= ~(1 << PA3);	// Pull pin on usb low
 
			
 
		//	if ((time_millis() - lastPicture) > CAMERA_FREQ)	// Frequency of photos
 
		//	{
 
		//		cameras_sendPulse();
 
		//		lastPicture = time_millis();
 
		//	}
 
			
 
		//	pulseOn = time_millis();
 
		//}
 
		
 
		if ((time_millis() - lastPicture) > CAMERA_FREQ)
 
		{
 
			cameras_sendPulse();
 
			lastPicture = time_millis();
 
		}
 
		else if ((time_millis() - lastPicture) > CAMERA_PULSE)
 
		{
 
			PORTA &= ~(1 << PA0);	// Pull pin on usb low
 
			PORTA &= ~(1 << PA1);	// Pull pin on usb low
 
			PORTA &= ~(1 << PA2);	// Pull pin on usb low
 
			PORTA &= ~(1 << PA3);	// Pull pin on usb low
 
		}		
 
 } 
 
  
 
\ No newline at end of file
slave/slave/slave.c
Show inline comments
 
@@ -37,8 +37,6 @@
 
#include "lib/watchdog.h"
 

	
 
bool WDTreset = false;
 
 uint32_t lastPicture;
 
 uint8_t pulseOn;
 

	
 
void micro_setup()
 
{
 
@@ -107,25 +105,6 @@ int main(void)
 
//i2c_write(EEPROM_ADDR, 0x05, 0x02);			
 
			
 
		}	// IFloop
 
		
 
		//if (io_getModuleId() == 3)
 
		//{
 
		//	if ((time_millis() - pulseOn) > CAMERA_PULSE)
 
		//	{
 
		//		PORTA &= ~(1 << PA0);	// Pull pin on usb low
 
		//		PORTA &= ~(1 << PA1);	// Pull pin on usb low
 
		//		PORTA &= ~(1 << PA2);	// Pull pin on usb low
 
		//		PORTA &= ~(1 << PA3);	// Pull pin on usb low
 
				
 
		//		if ((time_millis() - lastPicture) > CAMERA_FREQ)	// Frequency of photos
 
		//		{
 
		//			cameras_sendPulse();
 
		//			lastPicture = time_millis();
 
		//		}
 
				
 
		//		pulseOn = time_millis();
 
		//	}
 
		//}
 

	
 
    }	// While(1)
 
	
0 comments (0 inline, 0 general)