[ create a new paste ] login | about

Link: http://codepad.org/a7MBdjkU    [ raw code | output | fork ]

C, pasted on Oct 31:
uint16_t next_time;
uint16_t add_time;

main ()
{
	// init timer here, set constant prescaler ...
	// leave it running in normal mode (no CTC)
	
	// start with some tempo... whatever corresponds to 100 ticks
	add_time = 100;
	
	// schedule first output compare ISR
	next_time = TCNT1 + add_time;
	OCR1A = next_time;
}

ISR(TIMER1_COMPA_vect) { // something like that
	// here do your magic
	
	// compute time of next ISR and schedule it
	next_time += add_time;
	OCR1A = next_time;
}

// To change "period" in which the ISR is invoked, just change add_time.


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
Line 1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'next_time'
Line 2: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'add_time'
In function 'main':
Line 10: error: 'add_time' undeclared (first use in this function)
Line 10: error: (Each undeclared identifier is reported only once
Line 10: error: for each function it appears in.)
Line 13: error: 'next_time' undeclared (first use in this function)
Line 13: error: 'TCNT1' undeclared (first use in this function)
Line 14: error: 'OCR1A' undeclared (first use in this function)
In function 'ISR':
Line 21: error: 'next_time' undeclared (first use in this function)
Line 21: error: 'add_time' undeclared (first use in this function)
Line 22: error: 'OCR1A' undeclared (first use in this function)


Create a new paste based on this one


Comments: