Changeset - 7d5c2f8392e7
[Not reviewed]
default
0 2 0
mkroening@CL-ENS241-07.cedarville.edu - 12 years ago 2013-01-30 17:11:35
mkroening@CL-ENS241-07.cedarville.edu
Started writing pressure config
2 files changed with 45 insertions and 2 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/sensors.c
Show inline comments
 
/*
 
 * sensors.c
 
 *
 
 * Created: 11/19/2012 9:25:01 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "sensors.h"
 
#include "spi.h"
 
#include "i2c.h"
 
 
int16_t	spiTemp;	// Thermocouple Temperature (from spi)
 
int8_t	boardTemp;	// Board Temperature (from i2c)
 
uint16_t pressure;	// Pressure (from i2c)
 
//int humid;		// Humidity (from i2c)
 
uint8_t light;		// Lux reading (from i2c)
 
 
 
void sensors_readSpiTemp()
 
{
 
	// Select TEMP wait 100 microseconds then read four bytes
 
	SELECT_TEMP;
 
	_delay_us(100);
 
	uint8_t one = send_spi(0xFF);
 
	_delay_us(100);
 
	uint8_t two = send_spi(0xFF);
 
	_delay_us(100);
 
	uint8_t three = send_spi(0xFF);
 
	_delay_us(100);
 
	uint8_t four = send_spi(0xFF);
 
	DESELECT_TEMP;
 
	
 
	int16_t temperature = ((one<<4)|(two>>4));	// Shift and place into larger int. (Cuts off Decimal)
 
	temperature = (temperature & (0x0800)) ? (temperature & 0xF000) : temperature;	// Sign extend
 
	
 
	//int16_t temperature = ((one<<6)|(two>>2));	// Shift and place into larger int. (Includes Decimal)
 
	//temperature = (temperature & (0x2000)) ? (temperature & 0xC000) : temperature;	// Sign extend
 
	
 
	temperature = (two & 0x01) ? 0x00DE : temperature;	// Error Condition. If error is detected output is set to 222 degrees (0x00DE)
 
	
 
	// Note: Temperature still needs to be scaled in order to be accurate (eg. boil water). Do this before implementing.
 
	spiTemp = temperature;
 
}
 

	
 
void sensors_readBoardTemp()
 
{
 
	boardTemp = i2c_read(BOARDTEMP_ADDR, 0x00);		// Read only the first byte of data (we don't need the resolution here)
 
	boardTemp = ((boardTemp*18)/10) + (32);			// Converting Celsius to Fahrenheit
 
	boardTemp = boardTemp - 3;						// Linear offset
 
}
 

	
 
void sensors_readPressure()
 
{//needs editing
 
	//write 0x34 + (oss<<6) into 0xF4 (write is 0xEE), wait
 
	pressure = i2c_read(PRESSURE_ADDR, 0xF6);
 
	pressure = pressure << 8;
 
	pressure = pressure | i2c_read(PRESSURE_ADDR, 0xF7);
 
	//pressure = (MSB<<16 + LSB<<8 + XLSB(NOT USED)) >> (8-oss)
 
	//calculate true pressure with calibration data from modules.c, maybe write own function used here
 
}
 

	
 
void sensors_readHumid()
 
{
 
	//humid = i2c_read(HUMID_ADDR, 0xXX);
 
}
 

	
 
void sensors_readLight()
 
{
 
	light = i2c_read(LIGHT_ADDR, 0x03);
 
	// 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
 
}
 

	
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	return boardTemp;
 
}
 
 
uint16_t sensors_getPressure(void)
 
{
 
	return pressure;
 
}
 
 
//int sensors_getHumid(void)
 
//{
 
	//return humid;
 
//}
 
 
uint8_t sensors_getLight(void)
 
{
 
	return light;
 
}
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
/*
 
 * modules.c
 
 *
 
 * Created: 11/9/2012 11:44:22 AM
 
 *  Author: kripperger
 
 */ 
 
 
 #include <inttypes.h>
 
 #include <avr/io.h>
 
 #include <avr/interrupt.h>
 
 #include "config.h"
 
 #include <util/delay.h>
 
 #include "modules.h"
 
 #include "lib/spi.h"
 
 
 
 
 
 void modules_setup(uint8_t id)
 
 {
 
	switch(id)
 
	{
 
		case 0:
 
			modules_generic_setup();
 
			break;
 
			
 
		case 1:
 
			modules_sensors_setup();
 
			break;
 
			
 
		case 2:
 
			modules_geiger_setup();
 
			break;
 
			
 
		case 3:
 
			modules_cameras_setup();
 
			break;
 
			
 
		default:
 
			modules_generic_setup();
 
			break;
 
	}
 
	  
 
 }
 
 
 
 void modules_run(uint8_t id)
 
 {
 
	switch(id)
 
	{
 
		case 0:
 
			modules_generic();
 
			break;
 
		  
 
		case 1:
 
			modules_sensors();
 
			break;
 
		  
 
		case 2:
 
			modules_geiger();
 
			break;
 
		  
 
		case 3:
 
			modules_cameras();
 
			break;
 
		  
 
		default:
 
			modules_generic();
 
			break;
 
	}
 
	  
 
 }
 
 
 
 
 
 void modules_generic_setup()
 
 {
 
	  
 
 }
 
  
 
 void modules_sensors_setup()
 
 {
 
	 DESELECT_TEMP;
 
	 setup_spi();
 
	//setup_pressure();
 
 }
 
  
 
 void modules_geiger_setup()
 
 {
 
	// Pin setup
 
	DDRA &= ~(1 << DDA0);	// PA0 is an input
 
	
 
	
 
	 
 
	// Setup for interrupt input on PA0 (PCINT0)
 
	PCMSK0 |= (1 << PCINT0);	// Enable interrupt for PA0
 
	PCICR |= (1 << PCIE0);		// Enable ioc section PCIF0
 
	
 
	// Setup for interrupt from Timer2
 
	ASSR &= ~(1 << EXCLK);	// Disable external clock input (enabling crystal use)
 
	ASSR |= (1 << AS2);		// Enable timer2 async mode with an external crystal	
 
	_delay_ms(250);			// Let external 32KHz crystal stabilize
 
	TCCR2B = 0x05;			// Set the prescaler to 128: 32.768kHz / 128 = 1Hz overflow
 
	TIFR2 = 0x01;			// Reset timer2 overflow interrupt flag
 
	TIMSK2 = 0x01;			// Enable interrupt on overflow
 
	
 
	sei();					// Enable all interrupts
 
 }
 
  
 
  
 
  
 
 void modules_cameras_setup()
 
 {
 
	  	  
 
 }
 
  
 
 
 void modules_generic()
 
 {
 
	// 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
 
	 
 
 }
 
  
 
 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()
 
 {
 
	// Gathers data and performs functions for cameras daughter board
 
  
 
 } 
 
  
 
\ No newline at end of file
 
  
 
  ///////////do I need to change .h file?
 
  void setup_pressure()
 
  {
 
	  int16_t ac1 = i2c_read(PRESSURE_ADDR, 0xAA);
 
	  ac1 = ac1 << 8;
 
	  ac1 = ac1 | i2c_read(PRESSURE_ADDR, 0xAB);
 
	  int16_t ac2 = i2c_read(PRESSURE_ADDR, 0xAC);
 
	  ac2 = ac2 << 8;
 
	  ac2 = ac2 | i2c_read(PRESSURE_ADDR, 0xAD);	  
 
	  int16_t ac3 = i2c_read(PRESSURE_ADDR, 0xAE);
 
	  ac3 = ac3 << 8;
 
	  ac3 = ac3 | i2c_read(PRESSURE_ADDR, 0xAF);
 
	  uint16_t ac4 = i2c_read(PRESSURE_ADDR, 0xB0);
 
	  ac4 = ac4 << 8;
 
	  ac4 = ac4 | i2c_read(PRESSURE_ADDR, 0xB1);
 
	  uint16_t ac5 = i2c_read(PRESSURE_ADDR, 0xB2);
 
	  ac5 = ac5 << 8;
 
	  ac5 = ac5 | i2c_read(PRESSURE_ADDR, 0xB3);
 
	  uint16_t ac6 = i2c_read(PRESSURE_ADDR, 0xB4);
 
	  ac6 = ac6 << 8;
 
	  ac6 = ac6 | i2c_read(PRESSURE_ADDR, 0xB5);
 
	  int16_t b1 = i2c_read(PRESSURE_ADDR, 0xB6);
 
	  b1 = b1 << 8;
 
	  b1 = b1 | i2c_read(PRESSURE_ADDR, 0xB7);
 
	  int16_t b2 = i2c_read(PRESSURE_ADDR, 0xB8);
 
	  b2 = b2 << 8;
 
	  b2 = b2 | i2c_read(PRESSURE_ADDR, 0xB9);
 
	  int16_t mb = i2c_read(PRESSURE_ADDR, 0xBA);
 
	  mb = mb << 8;
 
	  mb = mb | i2c_read(PRESSURE_ADDR, 0xBB);
 
	  int16_t mc = i2c_read(PRESSURE_ADDR, 0xBC);
 
	  mc = mc << 8;
 
	  mc = mc | i2c_read(PRESSURE_ADDR, 0xBD);
 
	  int16_t md = i2c_read(PRESSURE_ADDR, 0xBE);
 
	  md = md << 8;
 
	  md = md | i2c_read(PRESSURE_ADDR, 0xBF);
 
  }
 
\ No newline at end of file
0 comments (0 inline, 0 general)