Browse Source

use a higher-precision timer implementation

master
Peter Cai 1 year ago
parent
commit
8e1b13345a
  1. 3
      .gitmodules
  2. 3
      Makefile
  3. 1
      TimerCounter
  4. 3
      c_cpp_properties.json.template
  5. 6
      main.cpp

3
.gitmodules vendored

@ -1,3 +1,6 @@
[submodule "ArduinoMIDI"]
path = ArduinoMIDI
url = https://github.com/FortySevenEffects/arduino_midi_library
[submodule "TimerCounter"]
path = TimerCounter
url = https://github.com/ElectricRCAircraftGuy/eRCaGuy_TimerCounter

3
Makefile

@ -24,6 +24,7 @@ VPATH := $(foreach path, ${VPATH}, ${path} $(shell find ${path} -type d))
# the VPATH list
VPATH += ${PWD} \
${PWD}/ArduinoMIDI/src \
${PWD}/TimerCounter \
# Build parameters
BUILD_DIR := out
@ -36,7 +37,7 @@ INCS := \
$(foreach path, ${VPATH}, -I ${path}) \
$(foreach path, ${VARIANTS}, -I ${path}) \
CFLAGS := -O3 -DF_CPU=16000000UL ${MMCU} ${INCS}
CFLAGS := -O3 -DF_CPU=16000000UL -DARDUINO=1000 ${MMCU} ${INCS}
# Generate sections for each function and variable
# so that LD can eliminate unused functions and variables
CFLAGS += -ffunction-sections -fdata-sections

1
TimerCounter

@ -0,0 +1 @@
Subproject commit f2651c78bce8a1b5f69d707ac3d019ef17ab8055

3
c_cpp_properties.json.template

@ -10,7 +10,8 @@
],
"defines": [
"__ATmega328P__",
"__AVR_ATmega328P__"
"__AVR_ATmega328P__",
"ARDUINO=1000",
]
}
]

6
main.cpp

@ -1,5 +1,6 @@
#include <Arduino.h>
#include <MIDI.h>
#include <eRCaGuy_Timer2_Counter.h>
#include "motor_control.h"
#define NUM_MOTORS 4
@ -53,6 +54,9 @@ int main() {
// Needed for some functions to work (like micros)
init();
// Timer based on Timer 2 (this breaks PWM output)
timer2.setup();
// Enable the motor drivers
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
@ -70,7 +74,7 @@ int main() {
MIDI.setHandleNoteOff(midi_note_off);
while (true) {
unsigned long cur_micros = micros();
unsigned long cur_micros = timer2.get_count() / 2ul; // The unit of get_count is 0.5us
handle_tick(cur_micros);
MIDI.read();
}

Loading…
Cancel
Save