]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
Use timer 4 instead of 3 for systick (1ms).
authorLeo C <erbl259-lmu@yahoo.de>
Fri, 15 Apr 2016 15:26:42 +0000 (17:26 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Fri, 15 Apr 2016 15:26:42 +0000 (17:26 +0200)
avr/main.c
avr/timer.c
include/timer.h

index 2199454fa0bd9654ea83804c2ebf051594a59d4b..0a1cab6535be3d4268a2d4264998a04687b089aa 100644 (file)
@@ -115,10 +115,10 @@ void setup_avr(void)
        CLKPR = 0;
 
        /* Timer */
-       PRR1 &= ~_BV(PRTIM3);
-       OCR3A = F_CPU / 1000 - 1;       /* Timer3: 1000Hz interval (OC3A) */
-       TCCR3B = (0b01<<WGM32)|(0b001<<CS30); /* CTC Mode, Prescaler 1 */
-       TIMSK3 = _BV(OCIE3A);           /* Enable TC2.oca interrupt */
+       PRR1 &= ~_BV(PRTIM4);
+       OCR4A = F_CPU / 1000 - 1;       /* Timer4: 1000Hz interval */
+       TCCR4B = (0b00<<WGM42)|(0b001<<CS40); /* Normal Mode, Prescaler 1 */
+       TIMSK4 = _BV(OCIE4A);           /* Enable Output Compare A interrupt */
 
        /* INT5, INT6: falling edge */
        EICRB = (EICRB & ~((0b11 << ISC50) | (0b11 << ISC60))) |
index f45f2675564f0f26028774de91c63b0ae395f5d5..1b1598540f82090c3dbe56e7610e33280342734e 100644 (file)
@@ -1,14 +1,13 @@
 /*
  * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
  *
- * SPDX-License-Identifier:    GPL-2.0+
+ * SPDX-License-Identifier:    GPL-2.0
  */
 
-#include "common.h"
+#include "timer.h"
 #include <avr/interrupt.h>
 #include <util/atomic.h>
 #include "time.h"
-#include "timer.h"
 
 /* timer interrupt/overflow counter */
 /* counts up every ms. */
@@ -16,9 +15,9 @@ static volatile
 uint32_t timestamp;
 
 /*
- * 1000Hz timer interrupt generated by OC3A
+ * 1000Hz timer interrupt generated by OC4A
  */
-ISR(TIMER3_COMPA_vect)
+ISR(TIMER4_COMPA_vect)
 {
        static int_fast8_t tick_10ms;
        static int_fast8_t tick_1s;
@@ -26,6 +25,8 @@ ISR(TIMER3_COMPA_vect)
 
        extern void disk_timerproc(void);
 
+       OCR4A += F_CPU / 1000;  /* 1000Hz interval */
+
        timestamp++;
 
        i = tick_10ms + 1;
@@ -47,24 +48,6 @@ ISR(TIMER3_COMPA_vect)
 }
 
 
-/*--------------------------------------------------------------------------*/
-
-#if 0
-void timer_setup(void)
-{
-
-       /* Clock */
-       CLKPR = _BV(CLKPCE);
-       CLKPR = 0;
-
-       /* Timer */
-
-       OCR1A = F_CPU / 1000 - 1; // Timer1: 1000Hz interval (OC1A)
-       TCCR1B = 0b00001001;
-       TIMSK1 = _BV(OCIE1A); // Enable TC1.oca interrupt
-}
-#endif
-
 /*--------------------------------------------------------------------------*/
 
 uint32_t get_timer(uint32_t base)
index c6d605332d6ff91b5e46027c701840e07a5f5383..83bc3298ed834eb6ef8caf4c1a582f5f2b358c5a 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef TIMER_H
 #define TIMER_H
 
+#include "common.h"
+
 uint32_t get_timer(uint32_t);
 
 #endif /* TIMER_H */