# HG changeset patch # User kripperger@CL-SEC241-09.cedarville.edu # Date 2012-11-19 21:49:58 # Node ID 51c8e8809a90e1d513f2f7d5a3b6da83e68ec186 # Parent dc66341db8147ea0129c64081b7d0e3c1e7209a9 Added Interrupts and more lib files diff --git a/slave/slave/lib/cameras.c b/slave/slave/lib/cameras.c new file mode 100644 --- /dev/null +++ b/slave/slave/lib/cameras.c @@ -0,0 +1,17 @@ +/* + * cameras.c + * + * Created: 11/19/2012 9:25:23 PM + * Author: kripperger + */ + + + #include + #include + #include + #include "../config.h" + #include + #include "cameras.h" + + + \ No newline at end of file diff --git a/slave/slave/lib/cameras.h b/slave/slave/lib/cameras.h new file mode 100644 --- /dev/null +++ b/slave/slave/lib/cameras.h @@ -0,0 +1,16 @@ +/* + * 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 diff --git a/slave/slave/lib/geiger.c b/slave/slave/lib/geiger.c new file mode 100644 --- /dev/null +++ b/slave/slave/lib/geiger.c @@ -0,0 +1,44 @@ +/* + * geiger.c + * + * Created: 11/19/2012 9:24:05 PM + * Author: kripperger + */ + + +#include +#include +#include +#include "../config.h" +#include +#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 diff --git a/slave/slave/lib/geiger.h b/slave/slave/lib/geiger.h new file mode 100644 --- /dev/null +++ b/slave/slave/lib/geiger.h @@ -0,0 +1,15 @@ +/* + * 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 diff --git a/slave/slave/lib/sensors.c b/slave/slave/lib/sensors.c new file mode 100644 --- /dev/null +++ b/slave/slave/lib/sensors.c @@ -0,0 +1,15 @@ +/* + * sensors.c + * + * Created: 11/19/2012 9:25:01 PM + * Author: kripperger + */ + + +#include +#include +#include +#include "../config.h" +#include +#include "sensors.h" + diff --git a/slave/slave/lib/sensors.h b/slave/slave/lib/sensors.h new file mode 100644 --- /dev/null +++ b/slave/slave/lib/sensors.h @@ -0,0 +1,16 @@ +/* + * 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 diff --git a/slave/slave/modules.c b/slave/slave/modules.c --- a/slave/slave/modules.c +++ b/slave/slave/modules.c @@ -7,6 +7,7 @@ #include #include + #include #include "config.h" #include #include "modules.h" @@ -82,13 +83,23 @@ 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() diff --git a/slave/slave/slave.c b/slave/slave/slave.c --- a/slave/slave/slave.c +++ b/slave/slave/slave.c @@ -2,10 +2,10 @@ * Slave Firmware * * Wireless Observational Modular Aerial Network - * + * + * Kyle Ripperger * Ethan Zonca * Matthew Kanning - * Kyle Ripperger * Matthew Kroening * */ @@ -17,33 +17,26 @@ #include #include #include +#include #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) { @@ -54,20 +47,24 @@ int main(void) //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); @@ -75,17 +72,14 @@ int main(void) - - - - //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/////////////////////////////////////////////////////////////////////////////// diff --git a/slave/slave/slave.cproj b/slave/slave/slave.cproj --- a/slave/slave/slave.cproj +++ b/slave/slave/slave.cproj @@ -114,6 +114,18 @@ compile + + compile + + + compile + + + compile + + + compile + compile @@ -132,6 +144,12 @@ compile + + compile + + + compile + compile