Changeset - 88a84e3b4dd9
[Not reviewed]
default
0 6 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-04-08 17:21:07
kripperger@CL-SEC241-09.cedarville.edu
Fixed Geiger
6 files changed with 18 insertions and 12 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/geiger.c
Show inline comments
 
@@ -24,26 +24,32 @@ ISR(TIMER2_OVF_vect)    // Timer 2 overf
 
	// Used only in Geiger module
 
	seconds++;
 
	if (seconds>=30)
 
	{
 
		cpm = (counts*2);
 
		seconds = 0;
 
		counts = 0;
 
	}
 
}
 
 
ISR(PCINT0_vect)    // Interrupt on PA0
 
{
 
	// Interrupts when pulse received from Geiger tube
 
	counts++;	// Increment counter.
 
	if(((PINA & 0b00000001))==1)
 
	{
 
		// Interrupts when pulse received from Geiger tube
 
		counts++;	// Increment counter.
 
		led_toggle(2);
 
		_delay_ms(5);
 
	}
 
 
}
 
 
uint16_t geiger_getCpm()
 
{
 
	return cpm;
 
}
 
 
uint8_t geiger_getCount()	//DEBUG
 
{
 
	return counts;
 
}
 
slave/slave/lib/inputOutput.c
Show inline comments
 
@@ -34,25 +34,25 @@ int8_t	moduleID;	// Slave Module ID from
 
	//ADCSRA |= (1 << ADIF);								// 
 
	//ADCSRA |= (1 << ADIE);								// ADC interrupt enable set
 
	ADCSRB &= ~((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0));// Set ADC auto trigger source to free running mode
 
	ADCSRA |= (1 << ADEN);									// Enable ADC
 
	ADCSRA |= (1 << ADSC);									// Start ADC measurements.  ADC should now continuously run conversions, which are stored in ADCH 0x79
 
	
 
 }
 
 
 
  
 
 void io_readModuleId()
 
 {
 
	// Get ID from rotary dip and return it. 
 
	moduleID = 1;
 
	moduleID = 2;
 
	
 
	/*
 
	// This method is temporary as the next release will read the module ID from EEPROM
 
	PORTC |= (1 << PC2);	// Pull pins on rotary dip high
 
	PORTC |= (1 << PC3);	// Pull pins on rotary dip high
 
	PORTC |= (1 << PC4);	// Pull pins on rotary dip high
 
	PORTC |= (1 << PC5);	// Pull pins on rotary dip high
 
	
 
	moduleID = ((PINC & 0b00011100) >> 2);		// Read Dip Encoder
 
	moduleID = ~moduleID;						//Invert Dip reading
 
	moduleID = (moduleID & 0b0111);				//Mask bits
 
	*/
slave/slave/lib/masterComm.c
Show inline comments
 
@@ -102,25 +102,25 @@ void masterComm_modules()
 
	// Send module specific sensor readings
 
	switch(io_getModuleId())
 
	{
 
		case 0:
 
			// Generic
 
			
 
			break;
 
		
 
		case 1:
 
			// Sensors
 
			
 
			// Send SPI Temperature (Air)
 
			masterComm_packetSend_unsigned(3,sensors_getSpiTemp());
 
			masterComm_packetSend_signed(3,sensors_getSpiTemp());
 
			
 
			// Send Ambient Light (Needs to be formatted)
 
			masterComm_packetSend_unsigned(4,sensors_getLux());
 
			
 
			// Send Humidity
 
			masterComm_packetSend_unsigned(5,/*Humidity Get Function Here */999);		
 
			
 
			// Send Pressure 
 
			masterComm_packetSend_unsigned(6,sensors_getPressure());			
 
			
 
			// Send Altitude
 
			masterComm_packetSend_unsigned(7,sensors_getAltitude());
slave/slave/lib/watchdog.c
Show inline comments
 
@@ -8,21 +8,21 @@
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include <avr/wdt.h>
 
 
//initialize watchdog
 
void watchdog_setup(void)
 
{
 
	cli();
 
	wdt_reset();
 
	// Set change enable bit, enable the WDT
 
	WDTCSR = (1<<WDCE)|(1<<WDE);
 
	// Start watchdog, 4 second timeout
 
	WDTCSR = (1<<WDE)|(1<<WDP3)|(1<<WDP0);
 
	WDTCSR = (1<<WDE)|(1<<WDP2)|(1<<WDP1);
 
	sei();
 
}
 
 
// ISR for watchdog timeout. ///////////Not currently used, interrupt is disabled.
 
ISR(WDT_vect)
 
{
 
	
 
}
slave/slave/modules.c
Show inline comments
 
@@ -9,25 +9,25 @@
 
 #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;
 
// uint32_t lastRefresh;	// Time in ms when last geiger refresh occurred 
 
 uint32_t lastRefresh;	// Time in ms when last geiger refresh occurred 
 
 
 
 void modules_setup(uint8_t id)
 
 {
 
	switch(id)
 
	{
 
		case 0:
 
			modules_generic_setup();
 
			break;
 
			
 
		case 1:
 
			modules_sensors_setup();
 
			break;
 
@@ -81,32 +81,32 @@
 
 }
 
  
 
 void modules_sensors_setup()
 
 {
 
	DESELECT_TEMP;
 
	setup_spi();
 
	sensors_setupPressure();
 
 }
 
  
 
 void modules_geiger_setup()
 
 {
 
	// Pin setup
 
	//DDRA &= ~(1 << DDA0);	// PA0 is an input
 
	//DDRA |= (1 << DDA1);	// PA1 is an output	///////////
 
	DDRA &= ~(1 << DDA0);	// PA0 is an input
 
	DDRA |= (1 << DDA1);	// PA1 is an output
 
	
 
	//geiger_on();	// Turn on HV supply	//////////////
 
	geiger_on();	// Turn on HV supply
 
	
 
	// Setup for interrupt input on PA0 (PCINT0)
 
	//PCMSK0 |= (1 << PCINT0);	// Enable interrupt for PA0
 
	//PCICR |= (1 << PCIE0);		// Enable ioc section PCIF0
 
	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(100);			// 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
 
 }
 
  
 
  
 
  
slave/slave/slave.c
Show inline comments
 
@@ -35,38 +35,38 @@
 
#include "lib/loopTimer.h"
 
#include "lib/masterComm.h"
 
#include "lib/watchdog.h"
 

	
 
bool WDTreset = false;
 

	
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	WDTreset = ((MCUSR & 0b00001000) > 0);	// Check if WDT reset occured
 
	MCUSR = 0;		// Clear reset flags
 
	wdt_disable();	// Disable WDT
 
	watchdog_setup();		// Setup watchdog timer
 
	_delay_ms(50);	// Power debounce
 
	sei();			// Enable interrupts
 
}
 

	
 

	
 

	
 
int main(void)
 
{
 

	
 
		
 
	// Initialize	
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();			// Setup loop timer and interrupts (TIMER0)
 
	watchdog_setup();		// Setup watchdog timer
 
	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 0
 
	serial1_setup();		// Config serial port 1
 
	
 
	_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
 

	
0 comments (0 inline, 0 general)