Changeset - 561ff9d0140a
[Not reviewed]
default
0 3 0
mkroening@CL-ENS241-07.cedarville.edu - 12 years ago 2013-02-21 15:46:13
mkroening@CL-ENS241-07.cedarville.edu
ADC is responsive, moved out of slave daughter
3 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/sensors.c
Show inline comments
 
@@ -209,57 +209,57 @@ void sensors_readLux()
 
	
 
	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
 
	// light = 2^(exponent)*mantissa*0.045
 
}
 
 
void sensors_readBatt()
 
{
 
	batt = ADCH;					// Read battery level from ADC
 
}
 
 
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 pressure;
 
}
 
 
uint16_t sensors_getHumid(void)			// Gets relative humidity from variable
 
{
 
	return humid;
 
}
 
 
uint32_t sensors_getLux(void)		// Gets light from variable
 
{
 
	return lux;
 
}
 
 
//possibly uint8_t
 
uint8_t sensors_getBatt(void)		// Gets battery voltage from variable
 
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/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"
 
 #include "lib/i2c.h"
 
 #include "lib/sensors.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)
 
 {
 
	 sensors_readBatt();				//Data Read
 
	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();
 
	sensors_setupPressure();
 
 }
 
  
 
 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_readLux();				//Data Read
 
	sensors_readBatt();				//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
slave/slave/slave.c
Show inline comments
 
@@ -37,88 +37,88 @@
 

	
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	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[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 |Lux: %lu |Pressure: %lu |Altitude: %lu |Battery: %u \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt()); //DEBUG
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu |Battery: %i \r\n ",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude(),sensors_getBatt()); //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
 
		i2c_write(RTC_ADDR, 0x05, 0x3A);	//i2c Write Example
 
		
 
		PORTA &= ~(1 << PA1);	//OFF
 
		PORTA |= (1 << PA1);	//ON
 
		PORTB ^= (1 << PB0);	//Toggle
 
		
 
		sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
		serial0_sendString(buff);
 
		
 
		**************************************************************/
 
		
 
		
 
		
 
		
 
\ No newline at end of file
0 comments (0 inline, 0 general)