Changeset - 51c8e8809a90
[Not reviewed]
default
0 3 6
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2012-11-19 21:49:58
kripperger@CL-SEC241-09.cedarville.edu
Added Interrupts and more lib files
9 files changed with 180 insertions and 34 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/cameras.c
Show inline comments
 
new file 100644
 
/*
 
 * cameras.c
 
 *
 
 * Created: 11/19/2012 9:25:23 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
 #include <inttypes.h>
 
 #include <avr/io.h>
 
 #include <avr/interrupt.h>
 
 #include "../config.h"
 
 #include <util/delay.h>
 
 #include "cameras.h"
 
 
 
 
 
 
 
\ No newline at end of file
slave/slave/lib/cameras.h
Show inline comments
 
new file 100644
 
/*
 
 * cameras.h
 
 *
 
 * Created: 11/19/2012 9:25:36 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#ifndef CAMERAS_H_
 
#define CAMERAS_H_
 
 
 
 
 
 
#endif /* CAMERAS_H_ */
 
\ No newline at end of file
slave/slave/lib/geiger.c
Show inline comments
 
new file 100644
 
/*
 
 * geiger.c
 
 *
 
 * Created: 11/19/2012 9:24:05 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "geiger.h"
 
 
volatile uint8_t seconds;		// Counts Seconds from Timer2 interrupt
 
volatile uint16_t counts;		// Counts the pulses
 
volatile uint16_t cpm;			// Counts per minuite
 
 
 
ISR(TIMER2_OVF_vect)    // Timer 2 overflow interrupt handler
 
{
 
	// This executes every second.  Update real-time clocks.
 
	// Used only in Geiger module
 
	
 
	seconds++;
 
	if (seconds==60)
 
	{
 
		seconds = 0;
 
		cpm = counts;
 
		counts = 0;
 
	}
 
}
 
 
ISR(PCINT0_vect)    // Interrupt on PA0
 
{
 
	// Interrupts when pulse received from Geiger tube
 
	counts++;	// Increment counter.
 
}
 
 
uint16_t geiger_getCpm()
 
{
 
	return cpm;
 
}
 
\ No newline at end of file
slave/slave/lib/geiger.h
Show inline comments
 
new file 100644
 
/*
 
 * geiger.h
 
 *
 
 * Created: 11/19/2012 9:24:17 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#ifndef GEIGER_H_
 
#define GEIGER_H_
 
 
uint16_t geiger_getCpm();
 
 
 
#endif /* GEIGER_H_ */
 
\ No newline at end of file
slave/slave/lib/sensors.c
Show inline comments
 
new file 100644
 
/*
 
 * 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"
 
slave/slave/lib/sensors.h
Show inline comments
 
new file 100644
 
/*
 
 * sensors.h
 
 *
 
 * Created: 11/19/2012 9:24:50 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#ifndef SENSORS_H_
 
#define SENSORS_H_
 
 
 
 
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -4,12 +4,13 @@
 
 * 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"
 
 
 
 
 
 
 
@@ -79,19 +80,29 @@
 
 {
 
	  
 
 }
 
  
 
 void modules_geiger_setup()
 
 {
 
	ASSR = 0x20;    //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 = 0x1;    //reset timer2 overflow interrupt flag
 
	TIMSK2 = 0x01;  //enable interrupt on overflow
 
	// 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()
 
 {
 
	  	  
 
 }
slave/slave/slave.c
Show inline comments
 
/*
 
 * Slave Firmware
 
 *
 
 * Wireless Observational Modular Aerial Network
 
 * 
 
 *
 
 * Kyle Ripperger
 
 * Ethan Zonca
 
 * Matthew Kanning
 
 * Kyle Ripperger
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#include "config.h"
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <compat/twi.h>
 
#include <util/delay.h>
 
#include <avr/interrupt.h>
 
#include "modules.h"
 
//#include "lib/serial.h"		//Not made yet
 
#include "lib/led.h"
 
#include "lib/inputOutput.h"
 
#include "lib/i2c.h"
 
#include "lib/spi.h"
 
#include "lib/geiger.h"
 
#include "lib/sensors.h"
 
#include "lib/cameras.h"
 
 
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	DDRA = 0xFF;		//PORTA is output //DEBUG
 
 
 
 
	DDRA = 0xFE;		//PORTA is output //DEBUG
 
 
 
}
 
 
ISR(TIMER2_OVF_vect)    //Timer 2 overflow interrupt handler
 
{
 
	// This executes every second.  Update real-time clocks
 
	// Used only in Geiger module
 
 
	
 
	TIFR2 = 0x1;    // Reset timer2 overflow interrupt flag 
 
}
 
 
 
int main(void)
 
{
 
	// Initialize
 
	micro_setup();			// Generic microcontroller config options
 
	led_configure();		//
 
	i2c_init();				// Setup I2C
 
	//serial_setup();		// Config serial ports
 
	
 
	uint8_t moduleID = io_getModuleId(); // Slave Module ID from rotary dip switch
 
	moduleID=2;	//DEBUG///////////////////////////////////////////////////////////////////////////////////////////
 
	modules_setup(moduleID);
 
 
	
 
 
	
 
	
 
	uint8_t temp;	//DEBUG
 
	uint8_t temp;	//DEBUG///////////////////////////////////////////////////////////////////////////////////////
 
	
 
	
 
	PORTA=0;//DEBUG
 
	temp=0;//DEBUG
 
	//PORTA &= ~(1 << PA1);	//DEBUG///////////////////////////////////////////////////////////////////////////////
 
	//PORTA |= (1 << PA1);	//DEBUG///////////////////////////////////////////////////////////////////////////////
 
	//PORTA=0;//DEBUG/////////////////////////////////////////////////////////////////////////////////////////////
 
	temp=0;//DEBUG////////////////////////////////////////////////////////////////////////////////////////////////
 
	
 
    while(1)
 
    {
 
 
 
		
 
		modules_run(moduleID);
 
 
 
 
 
 
 
 
 
 
        //serial_SendCommand('0','A',0,0);	//DEBUG: EXAMPLE
 
        //serial_SendCommand('0','A',0,0);	//DEBUG: EXAMPLE//////////////////////////////////////////////////////
 
        
 
        //i2c_write(RTC_ADDR, 0x05, 0x3A);	//DEBUG: EXAMPLE
 
        //i2c_write(RTC_ADDR, 0x05, 0x3A);	//DEBUG: EXAMPLE//////////////////////////////////////////////////////
 
 
        //_delay_ms(10);
 
        //temp = i2c_read(RTC_ADDR, 0x02);		//DEBUG: EXAMPLE: seconds
 
        _delay_ms(10);
 
        //temp = i2c_read(RTC_ADDR, 0x02);		//DEBUG: EXAMPLE: seconds/////////////////////////////////////////
 
        
 
      //  PORTA = temp;		//DEBUG
 
      //  PORTA = temp;		//DEBUG///////////////////////////////////////////////////////////////////////////////
 
 
 
 
    }
 
	
 
	return 0;
slave/slave/slave.cproj
Show inline comments
 
@@ -111,12 +111,24 @@
 
    </ToolchainSettings>
 
  </PropertyGroup>
 
  <ItemGroup>
 
    <Compile Include="config.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\cameras.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\cameras.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\geiger.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\geiger.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\i2c.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\i2c.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
@@ -129,12 +141,18 @@
 
    <Compile Include="lib\led.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\led.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sensors.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\sensors.h">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\spi.c">
 
      <SubType>compile</SubType>
 
    </Compile>
 
    <Compile Include="lib\spi.h">
 
      <SubType>compile</SubType>
 
    </Compile>
0 comments (0 inline, 0 general)