Ich habe folgenden Code auf meinen ATtiny2313 hochgeladen.
Die LED an PD1 blinkt wie erwartet.
Nun mein Problem, wie kann ich den Speed des Timers verstellen ?
TCCR0B und die nachfolgenden Werte habe ich schon probiert, die LED
blink immer gleich schnell.
1 | #include "Arduino.h"
|
2 |
|
3 | #define ledPin 1
|
4 |
|
5 | void dw(unsigned char port, bool on) {
|
6 | if (on) {
|
7 | PORTD |= (1 << port);
|
8 | } else {
|
9 | PORTD &= ~(1 << port);
|
10 | }
|
11 | }
|
12 |
|
13 | ISR(TIMER1_COMPA_vect) {
|
14 | int t = 5000;
|
15 | static int b;
|
16 | b = b + 1;
|
17 | dw(ledPin, (b > t));
|
18 |
|
19 | if (b > t * 2)
|
20 | b = 0;
|
21 | }
|
22 |
|
23 | void setup() {
|
24 | DDRD = DDRD | (1 << ledPin);
|
25 |
|
26 | TIMSK |= (1 << OCIE1A);
|
27 |
|
28 | TCCR1A = 1 << COM1A0; // toggle OC1A on Compare Match
|
29 | TCCR1B = 1 << WGM12 | 1 << CS10; // CTC, no prescaler
|
30 | OCR1A = 9; // compare A register value to 10 (zero relative)
|
31 | TCCR0A = 0x83; // Timer/Counter 0 initialization
|
32 | TCCR0B = 0x01; // Clock source: System Clock and Clock value: 16000,000 kHz
|
33 | TCNT0 = 0x00; // Mode: Fast PWM top=FFh
|
34 | OCR0A = 0x00; // OC0A output: Non-Inverted PWM
|
35 | OCR0B = 0x00; // OC0B output: Disconnected
|
36 |
|
37 | sei();
|
38 | }
|
39 |
|
40 | // The loop function is called in an endless loop
|
41 | void loop() {
|
42 | }
|