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 73 insertions and 58 deletions:
0 comments (0 inline, 0 general)
slave/slave/lib/geiger.c
Show inline comments
 
@@ -22,12 +22,11 @@ ISR(TIMER2_OVF_vect)    // Timer 2 overf
 
{
 
	// 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;
 
	}
 
}
 
@@ -38,7 +37,13 @@ ISR(PCINT0_vect)    // Interrupt on PA0
 
	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
 
@@ -9,7 +9,7 @@
 
#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
 
@@ -7,6 +7,19 @@
 
 
 #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()
 
 {
 
	 
 
@@ -20,12 +33,9 @@
 
		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
 
@@ -9,6 +9,7 @@
 
 #ifndef IO_H_
 
 #define IO_H_
 
 
 void io_configure();
 
 uint8_t io_getModuleId();	// Get ID from rotary dip and return it.
 
 
slave/slave/lib/led.c
Show inline comments
 
@@ -11,10 +11,10 @@
 
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
 
@@ -37,4 +37,12 @@ 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
 
@@ -18,6 +18,7 @@
 
 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
 
@@ -46,9 +46,9 @@ void sensors_readSpiTemp()
 

	
 
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
slave/slave/modules.c
Show inline comments
 
@@ -16,7 +16,6 @@
 
 
 
 void modules_setup(uint8_t id)
 
 {
 
 
	switch(id)
 
	{
 
		case 0:
 
@@ -44,7 +43,7 @@
 
 
 
 void modules_run(uint8_t id)
 
 {
 
 
	sensors_readBoardTemp();		// Read board temperature sensor (Common on all slaves) (Data Read)
 
	 switch(id)
 
	 {
 
		 case 0:
 
@@ -121,15 +120,16 @@
 
 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)
 
	  
 
 }
 
  
slave/slave/slave.c
Show inline comments
 
@@ -17,6 +17,7 @@
 
#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"
 
@@ -34,18 +35,6 @@ 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//
 
	
 
}
 
 
 
@@ -54,13 +43,17 @@ int main(void)
 
	// 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	
 
	
 
 
	
 
@@ -68,38 +61,29 @@ int main(void)
 
	//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////////////////////////////////////////////////////////////////
 
		test = geiger_getCount();	//Debug//////////
 
		
 
		//PORTB |= (1 << PB4);	//DEBUG///////////////ON//////HEATER/////////////////////////////////////////////////////	
 
		
 
		
 
		moduleID = io_getModuleId();	//Debug
 
 
		PORTB &= ~(0b1111);				// Clears the bottom 4 bits of PortB	
 
		PORTB |= (moduleID & 0b1111);	// Masks Module ID and assigns it to PortB
 
		led_output(test);//DEBUG//////////
 
	
 
		
 
		/********Examples of data reading and getting******************
 
@@ -111,8 +95,14 @@ int main(void)
 
		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
 
 
    }
 
	
0 comments (0 inline, 0 general)