-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added example for blue-pill, improved example for arduino-nano
- Loading branch information
Showing
8 changed files
with
200 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...es/arduino_nano/encoder_input/project.xml → ...no_nano/encoder_input_bitbang/project.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright (c) 2021, Thomas Sommer | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/debug/logger.hpp> | ||
#include <modm/processing/timer.hpp> | ||
#include <modm/driver/encoder/encoder_input.hpp> | ||
|
||
// ---------------------------------------------------------------------------- | ||
// Set the log level | ||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::INFO | ||
|
||
// Create an IODeviceWrapper around the Uart Peripheral we want to use | ||
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; | ||
|
||
// Set all four logger streams to use the UART | ||
modm::log::Logger modm::log::debug(loggerDevice); | ||
modm::log::Logger modm::log::info(loggerDevice); | ||
modm::log::Logger modm::log::warning(loggerDevice); | ||
modm::log::Logger modm::log::error(loggerDevice); | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
Usart2::connect<GpioOutputA2::Tx>(); | ||
Usart2::initialize<Board::SystemClock, 115200_Bd>(); | ||
|
||
// Each Timer can drive one Encoder | ||
// For Timer2 and Timer3 you have 2 Gpio options | ||
// When using one of PB3 or PB4 you also have to disable JTAG debugging during shared pins | ||
|
||
// Timer1: | ||
modm::EncoderInput<Timer1, GpioInputA8, GpioInputA9> encoder; | ||
|
||
// Timer2: | ||
// modm::EncoderInput<Timer2, GpioInputA0, GpioInputA1> encoder; | ||
// modm::EncoderInput<Timer2, GpioInputA15, GpioInputB3> encoder; | ||
// AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE; | ||
|
||
// Timer3: | ||
// modm::EncoderInput<Timer3, GpioInputA6, GpioInputA7> encoder; | ||
// modm::EncoderInput<Timer3, GpioInputB4, GpioInputB5> encoder; | ||
// Disable JTAG to make PB3, PB4 available as Gpio | ||
// AFIO->MAPR |= AFIO_MAPR_SWJ_CFG_JTAGDISABLE; | ||
|
||
// Timer4: | ||
// modm::EncoderInput<Timer4, GpioInputB6, GpioInputB7> encoder; | ||
|
||
encoder.initialize(true); | ||
|
||
modm::ShortPeriodicTimer heartbeat(500ms); | ||
|
||
while (true) | ||
{ | ||
if(heartbeat.execute()) { | ||
Board::LedGreen::toggle(); | ||
MODM_LOG_INFO << "Encoder Delta: " << encoder.getDelta() << modm::endl; | ||
MODM_LOG_INFO << "Encoder Absolut: " << encoder.getValue() << modm::endl; | ||
} | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Replace this with your custom programmer | ||
source [find interface/stlink-v2.cfg] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<library> | ||
<extends>modm:blue-pill-f103</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/blue_pill_f103/encoder_input</option> | ||
<option name="modm:build:openocd.cfg">openocd.cfg</option> | ||
</options> | ||
<modules> | ||
<module>modm:debug</module> | ||
<module>modm:platform:uart:2</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:driver:encoder_input</module> | ||
<module>modm:platform:timer:1</module> | ||
<module>modm:platform:timer:2</module> | ||
<module>modm:platform:timer:3</module> | ||
<module>modm:platform:timer:4</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2021, Thomas Sommer | ||
* | ||
* This file is part of the modm project. | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include <modm/board.hpp> | ||
#include <modm/debug/logger.hpp> | ||
#include <modm/processing/timer.hpp> | ||
#include <modm/driver/encoder/bitbang_encoder_input.hpp> | ||
|
||
// ---------------------------------------------------------------------------- | ||
// Set the log level | ||
#undef MODM_LOG_LEVEL | ||
#define MODM_LOG_LEVEL modm::log::INFO | ||
|
||
// Create an IODeviceWrapper around the Uart Peripheral we want to use | ||
modm::IODeviceWrapper< Usart2, modm::IOBuffer::BlockIfFull > loggerDevice; | ||
|
||
// Set all four logger streams to use the UART | ||
modm::log::Logger modm::log::debug(loggerDevice); | ||
modm::log::Logger modm::log::info(loggerDevice); | ||
modm::log::Logger modm::log::warning(loggerDevice); | ||
modm::log::Logger modm::log::error(loggerDevice); | ||
|
||
// Connect the encoders outputs to D7 and D8 Pins (usually the outer pins) | ||
// The common third pin (usually in the middle) is connected to GND. | ||
modm::BitBangEncoderInput<GpioInputB6, GpioInputB7, 4, int16_t> encoder; | ||
|
||
MODM_ISR(TIM2) | ||
{ | ||
Timer2::acknowledgeInterruptFlags(Timer2::InterruptFlag::Update); | ||
encoder.update(); | ||
} | ||
|
||
void | ||
init_Timer2(const uint16_t period) | ||
{ | ||
Timer2::enable(); | ||
Timer2::setMode(Timer2::Mode::UpCounter); | ||
|
||
Timer2::template setPeriod<Board::SystemClock>(period); | ||
Timer2::enableInterruptVector(true, 10); | ||
Timer2::enableInterrupt(Timer2::Interrupt::Update); | ||
|
||
Timer2::applyAndReset(); | ||
Timer2::start(); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
Board::initialize(); | ||
|
||
Usart2::connect<GpioOutputA2::Tx>(); | ||
Usart2::initialize<Board::SystemClock, 115200_Bd>(); | ||
|
||
encoder.initialize(); | ||
init_Timer2(1000); // 1ms period | ||
|
||
int value(0); | ||
|
||
modm::ShortPeriodicTimer heartbeat(1s); | ||
|
||
while (true) | ||
{ | ||
if (heartbeat.execute()) { | ||
Board::LedGreen::toggle(); | ||
|
||
const auto delta = encoder.getDelta(); | ||
MODM_LOG_INFO << "Delta: " << delta << modm::endl; | ||
|
||
value += delta; | ||
MODM_LOG_INFO << "Encoder Absolut: " << value << modm::endl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Replace this with your custom programmer | ||
source [find interface/stlink-v2.cfg] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<library> | ||
<extends>modm:blue-pill-f103</extends> | ||
<options> | ||
<option name="modm:build:build.path">../../../build/blue_pill_f103/encoder_input_bitbang</option> | ||
<option name="modm:build:openocd.cfg">openocd.cfg</option> | ||
</options> | ||
<modules> | ||
<module>modm:debug</module> | ||
<module>modm:platform:uart:2</module> | ||
<module>modm:processing:timer</module> | ||
<module>modm:driver:encoder_input.bitbang</module> | ||
<module>modm:platform:timer:2</module> | ||
<module>modm:build:scons</module> | ||
</modules> | ||
</library> |