Skip to content

Commit

Permalink
Version 2.1.0 Teensy support
Browse files Browse the repository at this point in the history
  • Loading branch information
ArminJo committed Jun 13, 2020
1 parent c51c445 commit 0e7e638
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 18 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# [ServoEasing](https://github.com/ArminJo/ServoEasing) - move your servo more natural
Available as Arduino library "ServoEasing"

### [Version 2.0.0](https://github.com/ArminJo/ServoEasing/releases)
### [Version 2.1.0](https://github.com/ArminJo/ServoEasing/releases)

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Installation instructions](https://www.ardu-badge.com/badge/ServoEasing.svg?)](https://www.ardu-badge.com/ServoEasing)
Expand Down Expand Up @@ -147,7 +147,7 @@ The OneServo example modified for using a PCA9685 expander board and the standar
You must comment out the line `#define USE_PCA9685_SERVO_EXPANDER` in *ServoEasing.h* to make the expander example work.

## PCA9685_ExpanderAndServo example
Combination of OneServo example and PCA9685_Expander example. Move one Servo attached to the Arduino board and one servo attached to the PCA9685 expander board simultaneously.
Combination of OneServo example and PCA9685_Expander example. Move one servo attached to the Arduino board and one servo attached to the PCA9685 expander board **simultaneously**.

## PCA9685_ExpanderFor32Servos example
Program to show the usage of 2 PCA9685 expander boards with 32 servos.
Expand Down Expand Up @@ -176,7 +176,7 @@ The API accepts only degree (except for write() and writeMicrosecondsOrUnits())
On **AVR** Timer1 is used for the Arduino Servo library. To have non blocking easing functions its unused **Channel B** is used to generate an interrupt 100 us before the end of the 20 ms Arduino Servo refresh period. This interrupt then updates all servo values for the next refresh period.

# Supported platforms
AVR, SAM, SAMD, ESP8266, ESP32, STM32, Apollo3
AVR, SAM, SAMD, ESP8266, ESP32, STM32, Apollo3, Teensy

# Adding a new platform / board
Every platform with a Servo library will work without any modifications in blocking mode.<br/>
Expand All @@ -198,6 +198,9 @@ If you see strange behavior, you can open the library file *ServoEasing.h* and c
This will print internal information visible in the Arduino *Serial Monitor* which may help finding the reason for it.

# Revision History
### Version 2.1.0
- Added support of **Teensy** boards.

### Version 2.0.0
- `PCA9685_Expander` and standard Servos can be controlled simultaneously by defining `USE_SERVO_LIB`.
- Changed some types to _fast types
Expand Down
4 changes: 2 additions & 2 deletions examples/EndPositionsTest/ADCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#if defined(__AVR__)
#include <Arduino.h>

// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 Mhz Clock => 19,2 kHz
// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 MHz Clock => 19,2 kHz
#define ADC_PRESCALE2 1 // 26 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE4 2 // 52 microseconds per ADC conversion at 1 MHz
// PRESCALE8 => 13 * 8 = 104 microseconds per ADC sample at 1 Mhz Clock => 9,6 kHz
// PRESCALE8 => 13 * 8 = 104 microseconds per ADC sample at 1 MHz Clock => 9,6 kHz
#define ADC_PRESCALE8 3 // 104 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE16 4 // 208 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE32 5 // 416 microseconds per ADC conversion at 1 MHz
Expand Down
4 changes: 2 additions & 2 deletions examples/QuadrupedControl/ADCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#if defined(__AVR__)
#include <Arduino.h>

// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 Mhz Clock => 19,2 kHz
// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 MHz Clock => 19,2 kHz
#define ADC_PRESCALE2 1 // 26 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE4 2 // 52 microseconds per ADC conversion at 1 MHz
// PRESCALE8 => 13 * 8 = 104 microseconds per ADC sample at 1 Mhz Clock => 9,6 kHz
// PRESCALE8 => 13 * 8 = 104 microseconds per ADC sample at 1 MHz Clock => 9,6 kHz
#define ADC_PRESCALE8 3 // 104 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE16 4 // 208 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE32 5 // 416 microseconds per ADC conversion at 1 MHz
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The OneServo example modified for using a PCA9685 expander board and the standar
You must comment out the line `#define USE_PCA9685_SERVO_EXPANDER` in *ServoEasing.h* to make the expander example work.

## PCA9685_ExpanderAndServo example
Combination of OneServo example and PCA9685_Expander example. Move one Servo attached to the Arduino board and one servo attached to the PCA9685 expander board simultaneously.
Combination of OneServo example and PCA9685_Expander example. Move one servo attached to the Arduino board and one servo attached to the PCA9685 expander board **simultaneously**.

## PCA9685_ExpanderFor32Servos example
Program to show the usage of 2 PCA9685 expander boards with 32 servos.
Expand Down
4 changes: 2 additions & 2 deletions examples/RobotArmControl/ADCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#if defined(__AVR__)
#include <Arduino.h>

// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 Mhz Clock => 19,2 kHz
// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 MHz Clock => 19,2 kHz
#define ADC_PRESCALE2 1 // 26 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE4 2 // 52 microseconds per ADC conversion at 1 MHz
// PRESCALE8 => 13 * 8 = 104 microseconds per ADC sample at 1 Mhz Clock => 9,6 kHz
// PRESCALE8 => 13 * 8 = 104 microseconds per ADC sample at 1 MHz Clock => 9,6 kHz
#define ADC_PRESCALE8 3 // 104 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE16 4 // 208 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE32 5 // 416 microseconds per ADC conversion at 1 MHz
Expand Down
4 changes: 2 additions & 2 deletions examples/SpeedTest/ADCUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
#if defined(__AVR__)
#include <Arduino.h>

// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 Mhz Clock => 19,2 kHz
// PRESCALE4 => 13 * 4 = 52 microseconds per ADC conversion at 1 MHz Clock => 19,2 kHz
#define ADC_PRESCALE2 1 // 26 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE4 2 // 52 microseconds per ADC conversion at 1 MHz
// PRESCALE8 => 13 * 8 = 104 microseconds per ADC sample at 1 Mhz Clock => 9,6 kHz
// PRESCALE8 => 13 * 8 = 104 microseconds per ADC sample at 1 MHz Clock => 9,6 kHz
#define ADC_PRESCALE8 3 // 104 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE16 4 // 208 microseconds per ADC conversion at 1 MHz
#define ADC_PRESCALE32 5 // 416 microseconds per ADC conversion at 1 MHz
Expand Down
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=ServoEasing
version=2.0.0
version=2.1.0
author=Armin Joachimsmeyer
maintainer=Armin Joachimsmeyer <[email protected]>
sentence=Enables smooth servo movement. <br/>Linear as well as other (Cubic, Circular, Bounce, etc.) ease movements for servos are provided. The Arduino Servo library or PCA9685 servo expanders are supported.<br/>
paragraph=Just use <b>myServo.easeTo()</b> instead of <b>myServo.write()</b> and you have smooth servo movement.<br/><b>Non blocking</b> movement for all servos attached to the Arduino Servo library is implemented by reusing the interrupts of the Arduino servo timer.<br/><b>All servos can move synchronized.</b><br/><br/>Includes the following <b>easing functions</b>:<ul><li><b>Linear</b>, <b>Quadratic</b>, <b>Cubic</b> and <b>Quartic</b></li><li><b>Sine</b>, <b>Circular</b>, <b>Back</b>, <b>Elastic</b> and <b>Bounce</b></li><li><b>User defined</b></li></ul>Each function supports the <b>easing types</b> <b>In</b>, <b>Out</b>, <b>InOut</b> and <b>BouncingOutIn</b><br/>Trim and reverse operations are supported as well as continuous rotating servos.<br/><br/><b>Requests for enhancements are welcome!</b><br/><br/><b>New:<b>PCA9685_Expander servos and plain servos can run simultaneously.
paragraph=Just use <b>myServo.easeTo()</b> instead of <b>myServo.write()</b> and you have smooth servo movement.<br/><b>Non blocking</b> movement for all servos attached to the Arduino Servo library is implemented by reusing the interrupts of the Arduino servo timer.<br/><b>All servos can move synchronized.</b><br/><br/>Includes the following <b>easing functions</b>:<ul><li><b>Linear</b>, <b>Quadratic</b>, <b>Cubic</b> and <b>Quartic</b></li><li><b>Sine</b>, <b>Circular</b>, <b>Back</b>, <b>Elastic</b> and <b>Bounce</b></li><li><b>User defined</b></li></ul>Each function supports the <b>easing types</b> <b>In</b>, <b>Out</b>, <b>InOut</b> and <b>BouncingOutIn</b><br/>Trim and reverse operations are supported as well as continuous rotating servos.<br/><br/><b>Requests for enhancements are welcome!</b><br/><br/><b>New:<b>Support of Teensy boards<br/>
category=Device Control
url=https://github.com/ArminJo/ServoEasing
includes=ServoEasing.h
Expand Down
11 changes: 10 additions & 1 deletion src/ServoEasing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ HardwareTimer Timer20ms(3); // 4 timers and 4. timer is used for tone()
#define ID_TC_FOR_20_MS_TIMER ID_TC8 // Timer 8 is TC2 channel 2
#define IRQn_FOR_20_MS_TIMER TC8_IRQn
#define HANDLER_FOR_20_MS_TIMER TC8_Handler

#elif defined(TEENSYDUINO)
// common for all Teensy
IntervalTimer Timer20ms;
#endif

// Enable this to see information on each call
Expand Down Expand Up @@ -1168,7 +1172,7 @@ void enableServoEasingInterrupt() {
#elif defined(ARDUINO_ARCH_SAMD)
// Servo uses timer 4 and we use timer 5. therefore we cannot change clock source to 32 kHz.
// Enable GCLK for TCC2 and TC5 (timer counter input clock)
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_TC4_TC5)); // GCLK1=32kHz, GCLK0=48Mhz
GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_TC4_TC5)); // GCLK1=32kHz, GCLK0=48MHz
// while (GCLK->STATUS.bit.SYNCBUSY) // not required to wait
// ;

Expand Down Expand Up @@ -1211,6 +1215,9 @@ void enableServoEasingInterrupt() {
am_hal_ctimer_int_enable(AM_HAL_CTIMER_INT_TIMERA3);
NVIC_EnableIRQ(CTIMER_IRQn);

#elif defined(TEENSYDUINO)
// common for all Teensy
Timer20ms.begin(handleServoTimerInterrupt, REFRESH_INTERVAL_MICROS);
#endif
sInterruptsAreActive = true;
}
Expand Down Expand Up @@ -1244,6 +1251,8 @@ void disableServoEasingInterrupt() {
#elif defined(ARDUINO_ARCH_APOLLO3)
am_hal_ctimer_int_disable(AM_HAL_CTIMER_INT_TIMERA3);

#elif defined(TEENSYDUINO)
Timer20ms.end();
#endif
sInterruptsAreActive = false;
}
Expand Down
9 changes: 6 additions & 3 deletions src/ServoEasing.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
#ifndef SERVOEASING_H_
#define SERVOEASING_H_

#define VERSION_SERVO_EASING "2.0.0"
#define VERSION_SERVO_EASING "2.1.0"
#define VERSION_SERVO_EASING_MAJOR 2
#define VERSION_SERVO_EASING_MINOR 0
#define VERSION_SERVO_EASING_MINOR 1

// @formatter:off
/* *****************************************************************************************************************************
Expand Down Expand Up @@ -70,7 +70,7 @@
#error "Please define only one of the symbols USE_PCA9685_SERVO_EXPANDER or USE_LEIGHTWEIGHT_SERVO_LIB"
#endif

#if ! ( defined(__AVR__) || defined(ESP8266) || defined(ESP32) || defined(STM32F1xx) || defined(__STM32F1__) || defined(__SAM3X8E__) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_APOLLO3))
#if ! ( defined(__AVR__) || defined(ESP8266) || defined(ESP32) || defined(STM32F1xx) || defined(__STM32F1__) || defined(__SAM3X8E__) || defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_APOLLO3)|| defined(TEENSYDUINO))
#warning "No periodic timer support existent (or known) for this platform. Only blocking functions and simple example will run!"
#endif

Expand Down Expand Up @@ -180,6 +180,9 @@
// @formatter:on

/*
* Version 2.1.0 - 6/2020
* - Teensy support.
*
* Version 2.0.0 - 5/2020
* - `PCA9685_Expander` and standard Servos can be controlled simultaneously by defining `USE_SERVO_LIB`.
* - Changed some types to _fast types
Expand Down

0 comments on commit 0e7e638

Please sign in to comment.