From 37824f586b0e0a574b76570cc12a5c256cdfccdf Mon Sep 17 00:00:00 2001 From: David Cutting Date: Tue, 26 May 2020 03:16:05 -0600 Subject: [PATCH] Select Pololu Motor shield --- include/README | 39 -------------------------------------- platformio.ini | 19 ++++++++++++++----- src/main.cpp | 51 +++++++++++++++++++++++++++++++------------------- test/README | 11 ----------- 4 files changed, 46 insertions(+), 74 deletions(-) delete mode 100644 include/README delete mode 100644 test/README diff --git a/include/README b/include/README deleted file mode 100644 index 194dcd4..0000000 --- a/include/README +++ /dev/null @@ -1,39 +0,0 @@ - -This directory is intended for project header files. - -A header file is a file containing C declarations and macro definitions -to be shared between several project source files. You request the use of a -header file in your project source file (C, C++, etc) located in `src` folder -by including it, with the C preprocessing directive `#include'. - -```src/main.c - -#include "header.h" - -int main (void) -{ - ... -} -``` - -Including a header file produces the same results as copying the header file -into each source file that needs it. Such copying would be time-consuming -and error-prone. With a header file, the related declarations appear -in only one place. If they need to be changed, they can be changed in one -place, and programs that include the header file will automatically use the -new version when next recompiled. The header file eliminates the labor of -finding and changing all the copies as well as the risk that a failure to -find one copy will result in inconsistencies within a program. - -In C, the usual convention is to give header files names that end with `.h'. -It is most portable to use only letters, digits, dashes, and underscores in -header file names, and at most one dot. - -Read more about using header files in official GCC documentation: - -* Include Syntax -* Include Operation -* Once-Only Headers -* Computed Includes - -https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html diff --git a/platformio.ini b/platformio.ini index 6737792..49dd6ea 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,15 +9,13 @@ ; https://docs.platformio.org/page/projectconf.html [platformio] -default_envs = samd21, mega2560 +default_envs = samd21 [env] lib_deps = https://github.com/davidcutting42/CommandStation.git#master https://github.com/davidcutting42/ArduinoTimers.git#master - SparkFun External EEPROM Arduino Library - DIO2 - + [env:samd21] platform = atmelsam board = sparkfun_samd21_dev_usb @@ -25,6 +23,7 @@ framework = arduino upload_protocol = atmel-ice lib_deps = ${env.lib_deps} + SparkFun External EEPROM Arduino Library build_flags = -D ATSAMD21G [env:mega2560] @@ -33,4 +32,14 @@ board = megaatmega2560 framework = arduino lib_deps = ${env.lib_deps} -build_flags = -D ATMEGA2560 \ No newline at end of file + DIO2 +build_flags = -D ATMEGA2560 + +[env:mega328] +platform = atmelavr +board = uno +framework = arduino +lib_deps = + ${env.lib_deps} + DIO2 +build_flags = -D ATMEGA328 \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 01ebd78..663db8d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,37 +2,50 @@ #include #include -DCC* mainTrack = DCC::Create_WSM_SAMCommandStation_Main(50); -DCC* progTrack = DCC::Create_WSM_SAMCommandStation_Prog(2); +#define DCC_IRQ_MICROSECONDS 58 + +//////////////////////////////////////////////////////////////// +// Motor driver selection: +// Comment out all but the two lines that you want to use + +// ;DCC* mainTrack = DCC::Create_WSM_SAMCommandStation_Main(50); +// DCC* progTrack = DCC::Create_WSM_SAMCommandStation_Prog(2); + +// DCC* mainTrack = DCC::Create_Arduino_L298Shield_Main(50); +// DCC* progTrack = DCC::Create_Arduino_L298Shield_Prog(2); + +DCC* mainTrack = DCC::Create_Pololu_MC33926Shield_Main(10); +DCC* progTrack = DCC::Create_Pololu_MC33926Shield_Prog(2); + +//////////////////////////////////////////////////////////////// void main_IrqHandler() { - mainTrack->interrupt_handler(); - progTrack->interrupt_handler(); + mainTrack->interruptHandler(); + progTrack->interruptHandler(); } void setup() { -#if defined (ATSAMD21G) - CommManager::registerInterface(new USBInterface(SerialUSB)); // Register SerialUSB as an interface - - TimerTCC0.initialize(); - TimerTCC0.setPeriod(58); - TimerTCC0.attachInterrupt(main_IrqHandler); - TimerTCC0.start(); -#elif defined(ATMEGA2560) - CommManager::registerInterface(new SerialInterface(Serial)); // Register Serial (USB port on mega/uno) as an interface + // TimerA is TCC0 on SAMD21, Timer1 on MEGA2560, and Timer1 on MEGA328 + // We will fire an interrupt every 58us to generate the signal on the track + TimerA.initialize(); + TimerA.setPeriod(DCC_IRQ_MICROSECONDS); + TimerA.attachInterrupt(main_IrqHandler); + TimerA.start(); - Timer3.initialize(); - Timer3.setPeriod(58); - Timer3.attachInterrupt(main_IrqHandler); - Timer3.start(); +#if defined (ARDUINO_ARCH_SAMD) + CommManager::registerInterface(new USBInterface(SerialUSB)); // Register SerialUSB as an interface +#elif defined(ARDUINO_ARCH_AVR) + CommManager::registerInterface(new SerialInterface(Serial)); // Register Serial (USB port on mega/uno) as an interface #endif + //EEStore::init(); + StringParser::init(mainTrack, progTrack); // Set up the string parser to accept commands from the interfaces CommManager::showInitInfo(); } void loop() { CommManager::update(); - mainTrack->check(); - progTrack->check(); + mainTrack->loop(); + progTrack->loop(); } \ No newline at end of file diff --git a/test/README b/test/README deleted file mode 100644 index df5066e..0000000 --- a/test/README +++ /dev/null @@ -1,11 +0,0 @@ - -This directory is intended for PIO Unit Testing and project tests. - -Unit Testing is a software testing method by which individual units of -source code, sets of one or more MCU program modules together with associated -control data, usage procedures, and operating procedures, are tested to -determine whether they are fit for use. Unit testing finds problems early -in the development cycle. - -More information about PIO Unit Testing: -- https://docs.platformio.org/page/plus/unit-testing.html