Changeset - b23f284b2449
[Not reviewed]
default
0 9 0
kripperger@CL-SEC241-09.cedarville.edu - 12 years ago 2013-01-09 22:28:52
kripperger@CL-SEC241-09.cedarville.edu
Lots of work on module identification, sensor integration, and debug serial output formatting. Extra setup work was done porting code to new micros.
9 files changed with 89 insertions and 74 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/geiger.c
Show inline comments
 
@@ -13,32 +13,37 @@
 
#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)
 
	if (seconds>=30)
 
	{
 
		cpm = (counts*2);
 
		seconds = 0;
 
		cpm = counts;
 
		counts = 0;
 
	}
 
}
 
 
ISR(PCINT0_vect)    // Interrupt on PA0
 
{
 
	// Interrupts when pulse received from Geiger tube
 
	counts++;	// Increment counter.
 
}
 
 
inline uint16_t geiger_getCpm()
 
uint16_t geiger_getCpm()
 
{
 
	return cpm;
 
}
 
\ No newline at end of file
 
}
 
 
uint8_t geiger_getCount()	//DEBUG
 
{
 
	return seconds;
 
}
 
slave/slave/lib/geiger.h
Show inline comments
 
/*
 
 * geiger.h
 
 *
 
 * Created: 11/19/2012 9:24:17 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#ifndef GEIGER_H_
 
#define GEIGER_H_
 
 
inline uint16_t geiger_getCpm();
 
 
uint16_t geiger_getCpm();
 
uint8_t geiger_getCount();	//DEBUG
 
 
#endif /* GEIGER_H_ */
 
\ No newline at end of file
slave/slave/lib/inputOutput.c
Show inline comments
 
/*
 
 * io.c
 
 *
 
 * Created: 11/7/2012 7:17:52 PM
 
 *  Author: kripperger
 
 */ 
 
 
 #include <avr/io.h>
 
 
 
 void io_configure()
 
 {
 
	 
 
	// Configure ports/pins
 
	DDRB |= (1 << DDB4);		// Set PB4 to Output for Heater (also allows SCK to operate)
 
	
 
	DDRC &= ~(1 << DDC2);		// Set PC2 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC3);		// Set PC3 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip    //TEMPORARY//
 
	 
 
 }
 
 
 
 uint8_t io_getModuleId()
 
 {
 
	 
 
	// Get ID from rotary dip and return it. 
 
	uint8_t id;
 
	id = 0;
 
	
 
	// 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
 
	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
 
	
 
	//while (id == 0)	// Keep reading until valid ID is read
 
	//{	
 
	id = ((PINC & 0b00111100) >> 2);	// Read Dip Encoder
 
	id = ((PINC & 0b00011100) >> 2);	// Read Dip Encoder
 
	id = ~id;							//Invert Dip reading
 
	id = (id & 0b1111);					//Mask bits
 
	//}
 
	id = (id & 0b0111);					//Mask bits
 
 
	return id;
 
 }
 
\ No newline at end of file
slave/slave/lib/inputOutput.h
Show inline comments
 
/*
 
 * io.h
 
 *
 
 * Created: 11/7/2012 7:18:08 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
 #ifndef IO_H_
 
 #define IO_H_
 
 
 
 
 void io_configure();
 
 uint8_t io_getModuleId();	// Get ID from rotary dip and return it.
 
 
 
 #endif /* IO_H_ */
 
\ No newline at end of file
slave/slave/lib/led.c
Show inline comments
 
@@ -2,39 +2,47 @@
 
* led.c
 
*
 
* Created: 10/25/2012 10:03:22 PM
 
*  Author: mkanning
 
*/
 
 
#include <avr/io.h>
 
#include "led.h"
 
 
void led_configure()
 
{
 
	// Configure ports/pins for LEDs
 
	DDRB |= (1 << DDB0);		// Set PB0 to Output
 
	DDRB |= (1 << DDB1);		// Set PB1 to Output
 
	DDRB |= (1 << DDB2);		// Set PB2 to Output
 
	DDRB |= (1 << DDB3);		// Set PB3 to Output	
 
	DDRB |= (1 << DDB0);		// Set PB0 to Output for LED0
 
	DDRB |= (1 << DDB1);		// Set PB1 to Output for LED1
 
	DDRB |= (1 << DDB2);		// Set PB2 to Output for LED2
 
	DDRB |= (1 << DDB3);		// Set PB3 to Output for LED3
 
	
 
	// Setup PWM
 
		//TODO
 
	
 
}
 
 
void led_on(uint8_t led)
 
{
 
	// Turn the specified LED on
 
	 
 
}
 
 
void led_off(uint8_t led)
 
{
 
	// Turn the specified LED off
 
	 
 
}
 
 
void led_toggle(uint8_t led)
 
{
 
	// Toggle the specified LED
 
	 
 
}
 
 
void led_output(uint8_t led)
 
{
 
	// Output variable to LED array
 
	PORTB &= ~(0b1111);			// Clears the bottom 4 bits of PortB
 
	PORTB |= (led & 0b1111);	// Masks variable to 4 bits and assigns it to PortB
 
	
 
}
 
\ No newline at end of file
slave/slave/lib/led.h
Show inline comments
 
@@ -9,15 +9,16 @@
 
 #ifndef LED_H_
 
 #define LED_H_
 
 
 #define POWER 1
 
 #define ERROR 2
 
 #define STAT 3
 
 #define OK 4
 
 
 void led_configure();
 
 void led_on(uint8_t led);
 
 void led_off(uint8_t led);
 
 void led_toggle(uint8_t led);
 
 void led_output(uint8_t led);
 
 
 
 #endif /* LED_H_ */
slave/slave/lib/sensors.c
Show inline comments
 
@@ -37,27 +37,27 @@ void sensors_readSpiTemp()
 
	
 
	//int16_t temperature = ((one<<6)|(two>>2));	// Shift and place into larger int. (Includes Decimal)
 
	//temperature = (temperature & (0x2000)) ? (temperature & 0xC000) : temperature;	// Sign extend
 
	
 
	temperature = (two & 0x01) ? 0x00DE : temperature;	// Error Condition. If error is detected output is set to 222 degrees (0x00DE)
 
	
 
	// Note: Temperature still needs to be scaled in order to be accurate (eg. boil water). Do this before implementing.
 
	spiTemp = temperature;
 
}
 

	
 
void sensors_readBoardTemp()
 
{
 
	int8_t temperature = i2c_read(BOARDTEMP_ADDR, 0x00);	// Read only the first byte of data (we don't need the resolution here)
 
	
 
	boardTemp = temperature;
 
	boardTemp = i2c_read(BOARDTEMP_ADDR, 0x00);		// Read only the first byte of data (we don't need the resolution here)
 
	boardTemp = ((boardTemp*18)/10) + (32);			// Converting Celsius to Fahrenheit
 
	boardTemp = boardTemp - 1;						// Linear offset
 
}
 

	
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	return boardTemp;
 
}
 
slave/slave/modules.c
Show inline comments
 
@@ -7,25 +7,24 @@
 
 
 #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"
 
 
 
 
 
 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();
 
@@ -35,47 +34,47 @@
 
			modules_cameras_setup();
 
			break;
 
			
 
		default:
 
			modules_generic_setup();
 
			break;
 
	}
 
	  
 
 }
 
 
 
 void modules_run(uint8_t id)
 
 {
 
 
	 switch(id)
 
	 {
 
		 case 0:
 
	sensors_readBoardTemp();		// Read board temperature sensor (Common on all slaves) (Data Read)
 
	switch(id)
 
	{
 
		case 0:
 
			modules_generic();
 
			break;
 
		  
 
		 case 1:
 
		case 1:
 
			modules_sensors();
 
			break;
 
		  
 
		 case 2:
 
		case 2:
 
			modules_geiger();
 
			break;
 
		  
 
		 case 3:
 
		case 3:
 
			modules_cameras();
 
			break;
 
		  
 
		 default:
 
		default:
 
			modules_generic();
 
			break;
 
	 }
 
	}
 
	  
 
 }
 
 
 
 
 
 void modules_generic_setup()
 
 {
 
	  
 
 }
 
  
 
 void modules_sensors_setup()
 
 {
 
	 DESELECT_TEMP;
 
@@ -112,30 +111,31 @@
 
 }
 
  
 
 
 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_readBoardTemp();		//Data Read
 
 
	 
 
 }
 
  
 
 void modules_geiger()
 
 {
 
	// Gathers data and performs functions for geiger daughter board
 
		// This is taken care of in interrupt
 
	// 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
 
@@ -8,113 +8,103 @@
 
 * Matthew Kanning
 
 * Matthew Kroening
 
 *
 
 */
 
 
 
#include "config.h"
 
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <compat/twi.h>
 
#include <util/delay.h>
 
#include <avr/cpufunc.h>
 
#include <avr/interrupt.h>
 
#include "modules.h"
 
#include "lib/serial.h"
 
#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
 
	sei();	// Enable interrupts
 
	
 
	DDRB |= (1 << DDB0);		// Set PB0 to Output for LED0
 
	DDRB |= (1 << DDB1);		// Set PB1 to Output for LED1
 
	DDRB |= (1 << DDB2);		// Set PB2 to Output for LED2
 
	DDRB |= (1 << DDB3);		// Set PB3 to Output for LED3
 
	
 
	DDRB |= (1 << DDB4);		// Set PB4 to Output for Heater (also allows SCK to operate)
 
	
 
	DDRC &= ~(1 << DDC2);		// Set PC2 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC3);		// Set PC3 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC4);		// Set PC4 to input for rotary dip    //TEMPORARY//
 
	DDRC &= ~(1 << DDC5);		// Set PC5 to input for rotary dip    //TEMPORARY//
 
	
 
}
 
 
 
int main(void)
 
{
 
	// Initialize
 
	// Initialize		
 
	micro_setup();			// Generic microcontroller config options
 
	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
 
	
 
	uint8_t moduleID = io_getModuleId();	// Slave Module ID from rotary dip switch
 
	//modules_setup(moduleID);				// Run setup functions for specific module
 
 
	modules_setup(moduleID);				// Run setup functions for specific module
 
	
 
	
 
	uint8_t test;	//Debug
 
	uint8_t test2;	//Debug	
 
	
 
 
	
 
	//PORTA &= ~(1 << PA1);	//DEBUG////////////////OFF///////////////////////////////////////////////////////////////
 
	//PORTA |= (1 << PA1);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
	
 
	
 
	//char buff[32];	//DEBUG///////////////////////////////////////////////////////////////////////////////////////
 
	//serial0_sendString("Starting\r\n");
 
	// This is just a serial output example
 
	char buff[32];	//DEBUG///////////////////////////////////////////////////////////////////////////////////////
 
	serial0_sendString("Starting\r\n");
 
	
 
	
 
    while(1)
 
    {
 
				
 
		//modules_run(moduleID);	// Runs specific module functions (like data reading)
 
								// Use program timer to run every so often. Time interval defined in config.h
 
 
//Note to future kyle: Investigate why things lock up in when ID=1 when no node is attached and fix it so that it never frezes.
 
    {			
 
		modules_run(moduleID);	// Runs specific module functions (like data reading)
 
								// Use program timer to run every so often. Time interval defined in config.h (TODO)
 
 
 
		// This is just a serial output example
 
		//sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
		//serial0_sendString(buff);
 
 
 
        //i2c_write(RTC_ADDR, 0x05, 0x3A);	//DEBUG: EXAMPLE//////////////////////////////////////////////////////
 
		
 
        _delay_ms(10);	//DEBUG
 
        _delay_ms(10);	//DEBUG/////////////
 
		
 
		
 
		//PORTB |= (1 << PB0);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
		//PORTB |= (1 << PB1);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
		//PORTB |= (1 << PB2);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
		//PORTB |= (1 << PB3);	//DEBUG///////////////ON////////////////////////////////////////////////////////////////
 
		
 
		//PORTB |= (1 << PB4);	//DEBUG///////////////ON//////HEATER/////////////////////////////////////////////////////	
 
		test = geiger_getCount();	//Debug//////////
 
		
 
		led_output(test);//DEBUG//////////
 
		
 
		moduleID = io_getModuleId();	//Debug
 
 
		PORTB &= ~(0b1111);				// Clears the bottom 4 bits of PortB	
 
		PORTB |= (moduleID & 0b1111);	// Masks Module ID and assigns it to PortB
 
	
 
		
 
		/********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
 
		
 
		
 
		***************************************************/
 
		**************************************************************/
 
		
 
		
 
		test2 = sensors_getBoardTemp();	//DEBUG///////////////////////////////////////////////////////////////////////////
 
 
 
		sprintf(buff, "|ModuleID: %u |BoardTemp: %u |Seconds: %u\r\n",moduleID,test2,test); //DEBUG
 
		serial0_sendString(buff); //DEBUG
 
 
    }
 
	
 
	return 0;
 
}
 
\ No newline at end of file
0 comments (0 inline, 0 general)