Changeset - f7fad1196562
[Not reviewed]
default
0 3 0
mkroening@CL-ENS241-07.cedarville.edu - 12 years ago 2013-03-21 16:56:16
mkroening@CL-ENS241-07.cedarville.edu
Camera functions
3 files changed with 21 insertions and 11 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/cameras.c
Show inline comments
 
@@ -13,45 +13,40 @@
 
 #include <util/delay.h>
 
 #include "cameras.h"
 
 
 
 #include "i2c.h"
 
 
 
 int8_t xmsb;	// Acceleration data in x-direction (MSB)
 
 int8_t ymsb;	// Acceleration data in y-direction (MSB)
 
 int8_t zmsb;	// Acceleration data in z-direction (MSB)
 
 
 
 
 
 
 
 void cameras_readAccelXYZ()
 
 {
 
	 xmsb = i2c_read(ACCEL_ADDR, 0x01);
 
	 ymsb = i2c_read(ACCEL_ADDR, 0x03);
 
	 zmsb = i2c_read(ACCEL_ADDR, 0x05);
 
 }
 
 
 
 void cameras_sendPulse()
 
 {
 
	 PORTA |= (1 << PA0);	// Pull pin on usb high
 
	 PORTA |= (1 << PA1);	// Pull pin on usb high
 
	 PORTA |= (1 << PA2);	// Pull pin on usb high
 
	 PORTA |= (1 << PA3);	// Pull pin on usb high
 
	 _delay_ms(250);
 
	 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
 
 }
 
 
 
 int8_t cameras_getAccelX()
 
 {
 
	 return xmsb;
 
 }
 
 
 
 int8_t cameras_getAccelY()
 
 {
 
	 return ymsb;
 
 }
 
 
 
 int8_t cameras_getAccelZ()
 
 {
 
	 return zmsb;
 
 }
 
\ 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"
 
 #include "lib/loopTimer.h"
 
 #include "lib/led.h"
 
 
 
 uint32_t lastPicture;
 
 uint8_t pulseOn;
 
 
 
 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;
 
@@ -88,70 +90,82 @@
 
 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
 
 }
 
  
 
  
 
  
 
 void modules_cameras_setup()
 
 {
 
	 lastPicture = time_millis();
 
	 pulseOn = time_millis();	 
 
	 
 
	 DDRA |= (1 << DDA0);	// Set PA0 to Output for Camera
 
	 DDRA |= (1 << DDA1);	// Set PA1 to Output for Camera
 
	 DDRA |= (1 << DDA2);	// Set PA2 to Output for Camera
 
	 DDRA |= (1 << DDA3);	// Set PA3 to Output for Camera
 
 }
 
  
 
 
 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
 
	 
 
 }
 
  
 
 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
 
 
		
 
		cameras_readAccelXYZ();
 
		
 
		if ((time_millis() - lastPicture) > CAMERA_FREQ)	// Frequency of photos
 
		if ((time_millis() - pulseOn) > CAMERA_PULSE)
 
		{
 
			cameras_sendPulse();
 
			lastPicture = time_millis();
 
			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();
 
		}
 
			
 
 
		
 
 } 
 
  
 
\ No newline at end of file
slave/slave/slave.c
Show inline comments
 
@@ -66,48 +66,49 @@ int main(void)
 
	
 
	_delay_ms(50);	// Setup hold delay
 
	if(WDTreset) led_on(1);	// Turn on LED if WDT reset has occurred	
 
	
 
	io_readModuleId();
 
	modules_setup(io_getModuleId());	// Run setup functions for specific module
 

	
 
	uint32_t lastLoop = 0;	// Time in ms when last loop occurred 
 
	
 
	// Serial output //DEBUG
 
	char buff[128];						//Buffer for serial output //DEBUG
 
	serial1_sendString("Starting Slave\r\n");	//DEBUG
 
			
 
    while(1)
 
    {	
 
		wdt_reset();	// Resets WDT (to prevent restart)
 
		
 
		// Master communication
 
		masterComm_checkParser();	//Checks parser for data requests from master
 

	
 
		// Main slave operations
 
		if ((time_millis() - lastLoop) > SENSOR_LOOP)	// Uses program timer to run every so often. Time interval defined in config.h
 
		{
 
			led_on(0);
 
			
 
			sensors_readBatt();				// Read Battery level
 
			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
 
			serial1_sendString(buff); //DEBUG
 
			
 
			led_off(0);
 
			lastLoop = time_millis();
 
			
 
// Writes ID to EEPROM, change for all modules and delete after programming
 
// 0 is for generic setup,	 1 is for sensors,	 2 is for Geiger,	3 is for cameras
 
//i2c_write(EEPROM_ADDR, 0x05, 0x03);			
 
			
 
		}
 

	
 
    }
 
	
 
	return 0;
 
}
 

	
 

	
0 comments (0 inline, 0 general)