Changeset - 5a775958ef65
[Not reviewed]
default
0 2 0
ethanzonca@CL-SEC241-08.cedarville.edu - 12 years ago 2012-11-20 12:13:06
ethanzonca@CL-SEC241-08.cedarville.edu
Program timer is operational
2 files changed with 7 insertions and 4 deletions:
0 comments (0 inline, 0 general)
master/master/lib/looptime.c
Show inline comments
 
/*
 
 * looptime.c
 
 *
 
 * Created: 11/19/2012 8:56:42 PM
 
 *  Author: ethanzonca
 
 */ 
 
 
#include "../config.h"
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
volatile uint32_t millis = 0; // Milliseconds since initialization
 
#include <avr/delay.h>
 
extern volatile uint32_t millis = 0; // Milliseconds since initialization
 

	
 

	
 

	
 
void time_setup() {
 
	DDRA = 0xff;
 
	
 
	// Generic microcontroller config options
 
	OCR0A = 173; // Approx 172.7969 ticks per ms with 64 prescaler
 
	
 
	TCCR0A |= (1 << WGM01) | (1 << WGM00); // Count until OCR0A, then overflow (wgm02 in the next line specifies this as well)
 
	TCCR0B |= (1 << CS01) | (1 << CS00) | (1 << WGM02); // clock div by 64
 
	TIFR0 |= ( 1 << TOV0 ); // clear pending interrupts
 
	TIMSK0 |= (1 << TOIE0); // enable overflow interrupt
 
}
 

	
 

	
 
ISR(TIMER0_OVF_vect) {
 
	PORTA = 0xff;
 
	millis++;
 
	millis = millis + 1;
 
}
 

	
 
uint32_t time_millis() {
 
	return millis; // meh accuracy, but that's OK
 
}
master/master/master.c
Show inline comments
 
@@ -16,24 +16,25 @@
 
#include <avr/io.h>
 
#include <util/delay.h>
 
#include <avr/wdt.h>
 
#include <avr/interrupt.h>
 

	
 
#include "lib/serial.h"
 
#include "lib/aprs.h"
 
#include "lib/afsk.h"
 
#include "lib/led.h"
 
#include "lib/logger.h"
 
#include "lib/watchdog.h"
 
#include "lib/sd/sd_raw_config.h"
 
#include "lib/looptime.h"
 

	
 
void micro_setup() {
 

	
 
}
 

	
 
int main(void)
 
{
 
    
 
	// Initialize. If this takes more than 4 seconds, be sure to reset the WDT
 
	time_setup();
 
	micro_setup();
 
	watchdog_setup();
 
@@ -44,25 +45,26 @@ int main(void)
 
	
 
	
 
	//led_on(POWER);
 
	
 
	uint16_t ctr1 = 0;
 
	uint16_t ctr2 = 255;
 
		
 
	char logbuf[32];
 
	
 
	while(1)
 
    {
 
		led_on(STAT);
 
		sprintf(logbuf, "%d,%d,%d,%d,%d,%d\n", time_millis(),5*ctr1,ctr2, 12*ctr2,43*ctr1,5*ctr2);
 
		//sprintf(logbuf, "%d,%d,%d,%d,%d,%d\n", time_millis(),5*ctr1,ctr2, 12*ctr2,43*ctr1,5*ctr2);
 
		sprintf(logbuf, "%d,\n", time_millis());
 
		logger_log(logbuf);
 
		led_off(STAT);
 
		
 
		// Wait for transmission to complete before starting another.
 
		// Hopefully this will never delay because it should issue on a timed schedule. Software timers!
 
		while(afsk_busy());
 
		aprs_send(); // non-blocking
 
		
 
		ctr1++;
 
		ctr2-=6;
 
		wdt_reset();
 
    }
0 comments (0 inline, 0 general)