Changeset - 0405269c2f4c
[Not reviewed]
default
0 5 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-26 15:05:05
ethanzonca@CL-ENS241-08.cedarville.edu
Added blackout mode for power-saving during actual launches
5 files changed with 55 insertions and 5 deletions:
0 comments (0 inline, 0 general)
master/master/config.h
Show inline comments
 
@@ -18,12 +18,14 @@
 
// --------------------------------------------------------------------------
 
// Module config (master.c)
 
// --------------------------------------------------------------------------
 
 
//#define DEBUG_OUTPUT
 
 
#define BLACKOUT_ENABLE
 
 
#define F_CPU 11059200
 
#define MODULE_ID '1'
 
#define BOARDTEMP_ADDR 0x90
 
 
#define HEATER_THRESHOLD 60
 
master/master/lib/led.c
Show inline comments
 
@@ -13,73 +13,113 @@
 
#include "../config.h"
 
#include <avr/io.h>
 
#include <util/delay.h>
 
#include <stdbool.h>
 
#include "led.h"
 
 
bool blackout = false;
 
 
// Configure port direction and initial state of LEDs
 
void led_setup() 
 
{
 
	for(int i=0; i<NUM_LEDS; i++)  
 
	{
 
		*(ledList[i].direction) |= (1<<ledList[i].pin); // set pin to output
 
		*(ledList[i].port) &= ~(1<<ledList[i].pin); // set pin low
 
	}
 
	
 
	// Beep on startup
 
	led_on(LED_POWER);
 
	OCR0B = 30; // Power LED
 
	
 
	led_on(LED_BUZZ);
 
	_delay_ms(1);
 
	led_off(LED_BUZZ);
 
}
 
 
void led_power_toggle() 
 
{
 
	OCR0B ^= 30;
 
}
 
 
// Turn the specified LED on
 
void led_on(uint8_t led) 
 
{
 
	if(blackout && led != LED_ERROR)
 
	{
 
		return;
 
	}		
 
	*(ledList[led].port) |= (1<<ledList[led].pin);
 
}
 
 
	// Turn the specified LED off
 
// Turn the specified LED off
 
void led_off(uint8_t led) 
 
{
 
	*(ledList[led].port) &= ~(1<<ledList[led].pin);
 
}
 
 
void led_toggle(uint8_t led)
 
{
 
	if(blackout && led != LED_ERROR)
 
	{
 
		return;
 
	}
 
	*(ledList[led].port) ^= (1<<ledList[led].pin);
 
}
 
 
void led_blackout() {
 
	if(!blackout) 
 
	{	
 
		blackout = true;
 
		for(int i=0; i<NUM_LEDS; i++)
 
		{
 
			if(i != LED_ERROR) 
 
			{
 
				*(ledList[i].port) &= ~(1<<ledList[i].pin); // set pin low
 
			}
 
		}
 
	}	
 
}
 
 
// Flashes error LED a set amount of times, then leaves it on
 
void led_errorcode(uint8_t code) 
 
{
 
	led_off(LED_ERROR);
 
	_delay_ms(400);
 
	for(int i=0; i<code; i++) 
 
	{
 
		// Direct port writing done here to show error LED during blackout
 
		led_on(LED_ERROR);
 
		_delay_ms(150);
 
		led_off(LED_ERROR);
 
		_delay_ms(150);
 
	}
 
	_delay_ms(400);
 
	// Direct port writing done here to show error LED during blackout
 
	led_on(LED_ERROR);
 
}
 
 
void led_alert() 
 
{
 
	if(blackout)
 
	{
 
		return;
 
	}
 
	led_on(LED_ACT0);
 
	led_on(LED_ACT1);
 
	led_on(LED_ACT2);
 
	led_on(LED_ACT3);
 
	_delay_ms(10);
 
}
 

	
 
uint8_t ctr = 0;
 
void led_spin() 
 
{
 
	if(blackout)
 
	{
 
		return;
 
	}
 
	
 
	if(ctr == 0) 
 
	{
 
		led_on(LED_ACT0);
 
		led_off(LED_ACT1);
 
		led_off(LED_ACT2);
 
@@ -110,12 +150,16 @@ void led_spin()
 
}
 

	
 

	
 
bool pulseUp = true;
 
void led_pulsate() 
 
{
 
	if(blackout)
 
	{
 
		return;
 
	}
 
	if(OCR0B >= 240 && pulseUp)
 
		pulseUp = false;
 
	else if(OCR0B <= 12 && !pulseUp);
 
		pulseUp = true;
 
		
 
	if(pulseUp)
master/master/lib/led.h
Show inline comments
 
@@ -53,14 +53,16 @@ static led_t ledList[] = {
 
	{&DDRA, &PORTA, PA7}, // BUZZER
 
};
 
 
#define NUM_LEDS 12
 
 
void led_setup();
 
void led_power_toggle();
 
void led_on(uint8_t led);
 
void led_off(uint8_t led);
 
void led_toggle(uint8_t led);
 
void led_blackout();
 
void led_errorcode(uint8_t code);
 
void led_spin();
 
void led_alert();
 
 
#endif /* LED_H_ */
master/master/lib/looptime.c
Show inline comments
 
@@ -20,15 +20,12 @@ volatile uint32_t millis = 0; // Millise
 

	
 
void time_setup() 
 
{
 
	// Generic microcontroller config options
 
	OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler
 
	
 
	
 
	OCR0B = 20; // Power LED
 
	
 
	TCCR0A |= (1 << WGM01) | (1 << WGM00) | // Count until OCR0A, then overflow (wgm02 in the next line specifies this as well)
 
			  (1<< COM0B1); // Non-inverting PWM on OC0B
 
	TCCR0B |= (1 << CS01) | (1 << CS00) | (1 << WGM02); // clock div by 64
 
	TIFR0 |= ( 1 << TOV0 ); // clear pending interrupts
 
	TIMSK0 |= (1 << TOIE0); // enable overflow interrupt
 
}
master/master/master.c
Show inline comments
 
@@ -74,12 +74,13 @@ int main(void)
 
	while(1)
 
    {
 
		
 
		// Periodic: LED execution indicator
 
		if(time_millis() - lastLedCycle > LEDCYCLE_RATE) 
 
		{
 
			led_power_toggle();
 
			led_spin();
 
			
 
			// Enable GPS serial interrupts if we aren't doing AFSK
 
			if(!afsk_busy())
 
				serial1_ion();
 
				
 
@@ -131,12 +132,16 @@ int main(void)
 
		}
 
		
 
		
 
		// Periodic: APRS transmission
 
		if(time_millis() - lastAprsBroadcast > APRS_TRANSMIT_PERIOD) 
 
		{
 
			#ifdef BLACKOUT_ENABLE
 
			led_blackout();
 
			#endif
 
			
 
			// Ensure we aren't already transmitting
 
			while(afsk_busy());
 
			
 
			// Turn off interrupts and transmit APRS sentence
 
			serial1_ioff();
 
			aprs_send(); // non-blocking
0 comments (0 inline, 0 general)