29.08.2013 Views

Autonom robotväckarklocka med trådlös basstation - KTH

Autonom robotväckarklocka med trådlös basstation - KTH

Autonom robotväckarklocka med trådlös basstation - KTH

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

}<br />

{<br />

outfreq = 1;<br />

enable = 1;<br />

count = 0;<br />

start = 0;<br />

}<br />

if(count>10)<br />

{<br />

enable = 0;<br />

outfreq = 0;<br />

PORTB = outfreq;<br />

}<br />

count++;<br />

}<br />

ISR(TIMER1_CAPT_vect){<br />

TIFR &= ~0x10;<br />

if(timerOn){<br />

time = TCNT1;<br />

PORTC = PINC +1;<br />

timerOn = 0;<br />

}<br />

}<br />

ISR(TIMER1_OVF_vect){<br />

TIFR &= ~0x04;<br />

//PORTC = PINC +1;<br />

timerOverflowCount = 1;<br />

}<br />

void startProcessor(){<br />

DDRD=0b11111110; //All output but port 0<br />

DDRC=0xff; //All pins output<br />

DDRB=0xf3; //0-1 and 4-7 as output, 2 and 3 as input<br />

}<br />

// Setting up timer0 for 44kHz output<br />

TCCR0 = 0x09; //0b00001001 CTC, OC0 disconnected, clk div = 1<br />

OCR0 = 0x5E; //Counting to 94, gives ~1/44000/2)<br />

TCNT0 = 0; //Starting counting at 0<br />

TIMSK = 0x02; //overflow interrupt from timer0<br />

PORTC=0xff;<br />

_delay_ms(100);<br />

// Set up timer1 for time measurement<br />

TCCR1A = 0x00; //00000000; No output ports, no force output compare,<br />

TCCR1B = 0x22; //00100010; No noise canselation, trigger on positive edge, normal mode, clk/8<br />

TIMSK |= 0x24; //xx1xx1xx; Input capture and overflow enabled<br />

//Setting up analog comparator<br />

ACSR = 0b00100111; //AC on, Analog comparator output (?) on, AC input capture enable, interrupt on rising<br />

void TimerStart(){<br />

TimerReset();<br />

timerOn = 1;<br />

timerOverflowCount = 0;<br />

}<br />

void TimerReset(){<br />

TCNT1H = 0;<br />

TCNT1L = 0;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!