Files @ f9a07af0c946
Branch filter:

Location: seniordesign-firmware/slave/slave/lib/loopTimer.c

ethanzonca@CL-ENS241-08.cedarville.edu
Merge
/*
 * looptimer.c
 *
 * Created: 11/29/2012 3:35:18 PM
 *  Author: kripperger
 */ 


#include "../config.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include "loopTimer.h"

volatile uint32_t millis; // Milliseconds since initialization


void time_setup()
{
	// 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)
{
	
	millis = millis + 1;
	
}

uint32_t time_millis()
{
	return millis; // meh accuracy, but that's OK
}