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
 
@@ -21,6 +21,8 @@
 
 
//#define DEBUG_OUTPUT
 
 
#define BLACKOUT_ENABLE
 
 
#define F_CPU 11059200
 
#define MODULE_ID '1'
 
#define BOARDTEMP_ADDR 0x90
master/master/lib/led.c
Show inline comments
 
@@ -16,6 +16,8 @@
 
#include <stdbool.h>
 
#include "led.h"
 
 
bool blackout = false;
 
 
// Configure port direction and initial state of LEDs
 
void led_setup() 
 
{
 
@@ -26,19 +28,29 @@ void led_setup()
 
	}
 
	
 
	// 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);
 
@@ -46,9 +58,27 @@ void led_off(uint8_t led)
 
 
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) 
 
{
 
@@ -56,17 +86,23 @@ void led_errorcode(uint8_t code)
 
	_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);
 
@@ -77,6 +113,10 @@ void led_alert()
 
uint8_t ctr = 0;
 
void led_spin() 
 
{
 
	if(blackout)
 
	{
 
		return;
 
	}
 
	
 
	if(ctr == 0) 
 
	{
 
@@ -113,6 +153,10 @@ void led_spin()
 
bool pulseUp = true;
 
void led_pulsate() 
 
{
 
	if(blackout)
 
	{
 
		return;
 
	}
 
	if(OCR0B >= 240 && pulseUp)
 
		pulseUp = false;
 
	else if(OCR0B <= 12 && !pulseUp);
master/master/lib/led.h
Show inline comments
 
@@ -56,9 +56,11 @@ static led_t ledList[] = {
 
#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();
master/master/lib/looptime.c
Show inline comments
 
@@ -23,9 +23,6 @@ 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
master/master/master.c
Show inline comments
 
@@ -77,6 +77,7 @@ int main(void)
 
		// 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
 
@@ -134,6 +135,10 @@ 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());
 
			
0 comments (0 inline, 0 general)