Hi,
habe hier ein Beispiel gefunden. Und stehe mit 3 Punkten auf dem Schlauch.
Und zwar mit bzw in Zeile 15
OCR1A = (unsigned long)((62500UL / frequency) - 1UL);//our clock runs at 62.5kHz, which is 1/62.5kHz = 16us
(unsigned long) ?? Ohne Name einer Variablen.
Gefolgt von einer geklammerten Formel
Und dann 1UL
3 Rätsel für mich.
Ich bitte um eine kurze Erklärung. Habe trotz Suche keine verständliche Lösung gefunden
Der Code aus dem Beispiel:
PS: Warum kann man in dem neuen Forum keinen Code mehr darstellen wie bisher?
1. void setup() {
2. int frequency = 1; // in hz
3. //Interupt Service Routine and timer setup
4. noInterrupts();// kill interrupts until everybody is set up
5. //We use Timer 1 b/c it's the only 16 bit timer
6. TCCR1A = B00000000;//Register A all 0's since we're not toggling any pins
7. // TCCR1B clock prescalers
8. // 0 0 1 clkI/O /1 (No prescaling)
9. // 0 1 0 clkI/O /8 (From prescaler)
10. // 0 1 1 clkI/O /64 (From prescaler)
11. // 1 0 0 clkI/O /256 (From prescaler)
12. // 1 0 1 clkI/O /1024 (From prescaler)
13. TCCR1B = B00001100;//bit 3 set for CTC mode, will call interrupt on counter match, bit 2 set to divide clock by 256, so 16MHz/256=62.5KHz
14. TIMSK1 = B00000010;//bit 1 set to call the interrupt on an OCR1A match
15. OCR1A = (unsigned long)((62500UL / frequency) - 1UL);//our clock runs at 62.5kHz, which is 1/62.5kHz = 16us
16. interrupts();//restart interrupts
17. Serial.begin(115200);
18. pinMode(13, OUTPUT);
19. }