-
Notifications
You must be signed in to change notification settings - Fork 2
/
calibrate.c
60 lines (50 loc) · 1.94 KB
/
calibrate.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
Crazy Clock calibrator
Copyright 2014 Nicholas W. Sayer
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* This is a calibration sketch. It's intended to connect the system clock as directly
* as possible to an I/O pin. The best we can do is generate a half-speed clock by
* telling timer0 to toggle OC0A with the system clock. The result is 16.384 kHz.
*/
#include <avr/io.h>
#include <avr/cpufunc.h>
#include <avr/power.h>
#include <stdlib.h>
void __ATTR_NORETURN__ main() {
ADCSRA = 0; // DIE, ADC!!! DIE!!!
ACSR = _BV(ACD); // Turn off analog comparator - but was it ever on anyway?
power_adc_disable();
power_usi_disable();
#ifdef __AVR_ATtiny44__
power_timer0_disable();
TCCR1A = _BV(COM1A0); // toggle OC1A
TCCR1B = _BV(WGM12) | _BV(CS10); // mode 4 - CTC, prescale = 1 (none)
OCR1A = 0; // as fast as possible
DDRA = _BV(DDA6); // All unused pins are input
DDRB = 0;
PORTA = 0; // Initialize all pins low.
PORTB = 0; // Initialize all pins low.
#else
power_timer1_disable();
TCCR0A = _BV(COM0A0) | _BV(WGM01); // mode 2 - CTC, toggle OC0A
TCCR0B = _BV(CS00); // prescale = 1 (none)
OCR0A = 0; // as fast as possible
DDRB = _BV(DDB0); // all unused pins are input
PORTB = 0; // Initialize all pins low.
#endif
// And we're done.
while(1);
__builtin_unreachable();
}