From 6a27fb816b274d0954771cba6a496e124844e0e0 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 18 Jan 2016 21:58:30 +0100 Subject: [PATCH] change interrupt routine --- src/switch.cpp | 25 +++++++++++++++++++++++++ src/time.cpp | 15 +++++++++++++-- src/time.h | 3 ++- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 src/switch.cpp diff --git a/src/switch.cpp b/src/switch.cpp new file mode 100644 index 0000000..67bec25 --- /dev/null +++ b/src/switch.cpp @@ -0,0 +1,25 @@ + +/* +void switch_interrupt() { + unsigned long currentEvent = millis(); + + if ((lastEvent == 0) || (lastEvent + DEBOUNCING_DEAD_TIME < currentEvent)) { + lastEvent = currentEvent; + + switchState = true; + } +} + + + +bool getAndResetSwitchState() { + bool res = false; + + noInterrupts(); + res = switchState; + switchState = false; + interrupts(); + + return res; +} +*/ \ No newline at end of file diff --git a/src/time.cpp b/src/time.cpp index cb046e1..7c3282b 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -1,7 +1,7 @@ /* * time.c * - * Created on: 20.05.2014 + * Created on: 17.01.2016 * Author: wn */ #include @@ -11,13 +11,16 @@ #include "time.h" -volatile uint16_t timestamp; +volatile uint16_t timestamp = 0; +volatile uint32_t tickCnt = 0; const uint16_t TICK = 1024; uint16_t pwmVal = 128; volatile uint16_t onTime = 500; volatile uint16_t offTime = 200; ISR(TIMER0_A0, TA0_ISR) { + tickCnt++; + static uint8_t state0 = 0; static uint8_t state1 = 0; @@ -77,4 +80,12 @@ void timeInit() { } +uint32_t ticks() { + __disable_interrupt(); + uint32_t t = tickCnt; + __enable_interrupt(); + + return t; +} + diff --git a/src/time.h b/src/time.h index 2ee6a1e..358f5d1 100644 --- a/src/time.h +++ b/src/time.h @@ -1,7 +1,7 @@ /* * time.h * - * Created on: 20.05.2014 + * Created on: 17.01.2016 * Author: wn */ @@ -11,6 +11,7 @@ void timeInit(); +uint32_t ticks();