Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.2.0 to fix bug
Browse files Browse the repository at this point in the history
### Releases v1.2.0

1. Permit using servos with different pulse ranges simultaneously. Check [Fix Bug #5 : Permit using servos with different pulse ranges simultaneously #4](khoih-prog/RP2040_ISR_Servo#4)
2. Delete left-over `cpp`
  • Loading branch information
khoih-prog authored Apr 24, 2022
1 parent 69b76fd commit faa076e
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 37 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Please ensure to specify the following:
Arduino IDE version: 1.8.19
Arduino NRF52 Core Version 1.3.0
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-100-generic #113-Ubuntu SMP Thu Feb 3 18:43:29 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.13.0-40-generic #45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while trying to use the Timer Interrupt.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ https://github.com/khoih-prog/NRF52_ISR_Servo/blob/4260125278f38956f8fdeaca58249

```
Starting NRF52_MultipleRandomServos on NRF52840_FEATHER
NRF52_ISR_Servo v1.1.0
NRF52_ISR_Servo v1.2.0
Setup OK Servo index = 0
Setup OK Servo index = 1
Setup OK Servo index = 2
Expand Down Expand Up @@ -305,7 +305,7 @@ Servos sweeps from 0-180 degree

```
Starting NRF52_MultipleRandomServos on NRF52840_ITSYBITSY
NRF52_ISR_Servo v1.1.0
NRF52_ISR_Servo v1.2.0
Setup OK Servo index = 0
Setup OK Servo index = 1
Setup OK Servo index = 2
Expand Down Expand Up @@ -422,7 +422,7 @@ Submit issues to: [NRF52_ISR_Servo issues](https://github.com/khoih-prog/NRF52_I
6. Add example [multiFileProject](examples/multiFileProject) to demo for multiple-file project
7. Optimize code by using passing by `reference` instead of by `value`
8. Add support to `Sparkfun Pro nRF52840 Mini`

9. Permit using servos with different pulse ranges simultaneously

---
---
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
## Table of Contents

* [Changelog](#changelog)
* [Releases v1.2.0](#releases-v120)
* [Releases v1.1.0](#releases-v110)
* [Releases v1.0.0](#releases-v100)

Expand All @@ -21,6 +22,11 @@

## Changelog

### Releases v1.2.0

1. Permit using servos with different pulse ranges simultaneously. Check [Fix Bug #5 : Permit using servos with different pulse ranges simultaneously #4](https://github.com/khoih-prog/RP2040_ISR_Servo/pull/4)
2. Delete left-over `cpp`

### Releases v1.1.0

1. Convert to `h-only` style.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#define TIMER_INTERRUPT_DEBUG 4
#define ISR_SERVO_DEBUG 4

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "NRF52_ISR_Servo.h"

// Published values for SG90 servos; adjust if needed
Expand All @@ -68,7 +67,7 @@

typedef struct
{
int8_t servoIndex;
int servoIndex;
uint8_t servoPin;
} ISR_servo_t;

Expand Down
5 changes: 2 additions & 3 deletions examples/nRF52_MultipleServos/nRF52_MultipleServos.ino
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
#define TIMER_INTERRUPT_DEBUG 1
#define ISR_SERVO_DEBUG 1

// To be included only in main(), .ino with setup() to avoid `Multiple Definitions` Linker Error
#include "NRF52_ISR_Servo.h"

// Published values for SG90 servos; adjust if needed
Expand All @@ -68,7 +67,7 @@

typedef struct
{
int8_t servoIndex;
int servoIndex;
uint8_t servoPin;
} ISR_servo_t;

Expand All @@ -89,7 +88,7 @@ void setup()
Serial.print(F("\nStarting NRF52_MultipleServos on ")); Serial.println(BOARD_NAME);
Serial.println(NRF52_ISR_SERVO_VERSION);

for (int8_t index = 0; index < NUM_SERVOS; index++)
for (int index = 0; index < NUM_SERVOS; index++)
{
ISR_servo[index].servoIndex = NRF52_ISR_Servos.setupServo(ISR_servo[index].servoPin, MIN_MICROS, MAX_MICROS);

Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "NRF52_ISR_Servo",
"version": "1.1.0",
"version": "1.2.0",
"keywords": "timing, device, control, timer, interrupt, isr, pwm, servo, isr-servo, hardware-timer, mission-critical, accuracy, precise, non-blocking, nrf52, nrf52840, nrf52832, feather-nrf52840, sparkfun-nrf52840, itsybitsy-nrf52840",
"description": "This library enables you to use 1 Hardware PWM module on nRF52832/nRF52840-based board, such as AdaFruit Feather nRF52832, nRF52840 Express, Itsy-Bitsy nRF52840 Express, etc. to control up to 16 or more servo motors.",
"authors":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=NRF52_ISR_Servo
version=1.1.0
version=1.2.0
author=Khoi Hoang
maintainer=Khoi Hoang <khoih.prog@gmail.com>
license=MIT
Expand Down
3 changes: 2 additions & 1 deletion src/NRF52_ISR_Servo.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_ISR_Servo
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 22/08/2021 Initial coding for nRF52832/nRF52840 boards
1.1.0 K Hoang 03/03/2022 Convert to `h-only` style. Optimize code. Add support to `Sparkfun Pro nRF52840 Mini`
1.2.0 K Hoang 23/04/2022 Permit using servos with different pulse ranges simultaneously. Delete left-over `cpp`
*****************************************************************************************************************************/

#pragma once
Expand Down
19 changes: 11 additions & 8 deletions src/NRF52_ISR_Servo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_ISR_Servo
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 22/08/2021 Initial coding for nRF52832/nRF52840 boards
1.1.0 K Hoang 03/03/2022 Convert to `h-only` style. Optimize code. Add support to `Sparkfun Pro nRF52840 Mini`
1.2.0 K Hoang 23/04/2022 Permit using servos with different pulse ranges simultaneously. Delete left-over `cpp`
*****************************************************************************************************************************/

#pragma once
Expand All @@ -33,13 +34,13 @@
#include <Adafruit_TinyUSB.h>

#if !defined(NRF52_ISR_SERVO_VERSION)
#define NRF52_ISR_SERVO_VERSION "NRF52_ISR_Servo v1.1.0"
#define NRF52_ISR_SERVO_VERSION "NRF52_ISR_Servo v1.2.0"

#define NRF52_ISR_SERVO_VERSION_MAJOR 1
#define NRF52_ISR_SERVO_VERSION_MINOR 1
#define NRF52_ISR_SERVO_VERSION_MINOR 2
#define NRF52_ISR_SERVO_VERSION_PATCH 0

#define NRF52_ISR_SERVO_VERSION_INT 1001000
#define NRF52_ISR_SERVO_VERSION_INT 1002000

#endif

Expand Down Expand Up @@ -104,7 +105,9 @@ class NRF52_ISR_Servo
//////////////////////////////////////////////////

// Bind servo to the timer and pin, return servoIndex
int8_t setupServo(const uint8_t& pin, const uint16_t& minUs = MIN_PULSE_WIDTH, const uint16_t& maxUs = MAX_PULSE_WIDTH, int value = 0);
//int8_t setupServo(const uint8_t& pin, const uint16_t& minUs = MIN_PULSE_WIDTH, const uint16_t& maxUs = MAX_PULSE_WIDTH, int value = 0);
int8_t setupServo(const uint8_t& pin, const uint16_t& minPulseUs = MIN_PULSE_WIDTH,
const uint16_t& maxPulseUs = MAX_PULSE_WIDTH, uint16_t value = 0);

// if value is < MIN_PULSE_WIDTH its treated as an angle, otherwise as pulse width in microseconds
void write(const uint8_t& servoIndex, uint16_t value);
Expand Down Expand Up @@ -186,15 +189,15 @@ class NRF52_ISR_Servo

//////////////////////////////////////////////////

uint16_t _minUs;
uint16_t _maxUs;

typedef struct
{
uint8_t pin; // pin servo connected to
int position; // In degrees
bool enabled; // true if enabled

uint16_t minPulseUs; // The minimum pulse width the servo can handle
uint16_t maxPulseUs; // The maximum pulse width the servo can handle

HardwarePWM* pwm;
} servo_t;

Expand Down
3 changes: 2 additions & 1 deletion src/NRF52_ISR_Servo_Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_ISR_Servo
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 22/08/2021 Initial coding for nRF52832/nRF52840 boards
1.1.0 K Hoang 03/03/2022 Convert to `h-only` style. Optimize code. Add support to `Sparkfun Pro nRF52840 Mini`
1.2.0 K Hoang 23/04/2022 Permit using servos with different pulse ranges simultaneously. Delete left-over `cpp`
*****************************************************************************************************************************/

#pragma once
Expand Down
34 changes: 18 additions & 16 deletions src/NRF52_ISR_Servo_Impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
Built by Khoi Hoang https://github.com/khoih-prog/NRF52_ISR_Servo
Licensed under MIT license
Version: 1.1.0
Version: 1.2.0
Version Modified By Date Comments
------- ----------- ---------- -----------
1.0.0 K Hoang 22/08/2021 Initial coding for nRF52832/nRF52840 boards
1.1.0 K Hoang 03/03/2022 Convert to `h-only` style. Optimize code. Add support to `Sparkfun Pro nRF52840 Mini`
1.2.0 K Hoang 23/04/2022 Permit using servos with different pulse ranges simultaneously. Delete left-over `cpp`
*****************************************************************************************************************************/

#pragma once
Expand Down Expand Up @@ -65,7 +66,8 @@ int8_t NRF52_ISR_Servo::findFirstFreeSlot()

//////////////////////////////////////////////////

int8_t NRF52_ISR_Servo::setupServo(const uint8_t& pin, const uint16_t& minUs, const uint16_t& maxUs, int value)
//int8_t NRF52_ISR_Servo::setupServo(const uint8_t& pin, const uint16_t& minUs, const uint16_t& maxUs, int value)
int8_t NRF52_ISR_Servo::setupServo(const uint8_t& pin, const uint16_t& minPulseUs, const uint16_t& maxPulseUs, uint16_t value)
{
int8_t servoIndex;

Expand All @@ -81,10 +83,10 @@ int8_t NRF52_ISR_Servo::setupServo(const uint8_t& pin, const uint16_t& minUs, co
return -1;

pinMode(pin, OUTPUT);

_maxUs = maxUs;
_minUs = minUs;

servo[servoIndex].maxPulseUs = maxPulseUs;
servo[servoIndex].minPulseUs = minPulseUs;

servo[servoIndex].position = 0;

numServos++;
Expand Down Expand Up @@ -139,7 +141,7 @@ int8_t NRF52_ISR_Servo::setupServo(const uint8_t& pin, const uint16_t& minUs, co
///////////////////////////////////////////

ISR_SERVO_LOGDEBUG1("Index =", servoIndex);
ISR_SERVO_LOGDEBUG3("min =", _minUs, ", max =", _maxUs);
ISR_SERVO_LOGDEBUG3("min =", servo[servoIndex].minPulseUs, ", max =", servo[servoIndex].maxPulseUs);

Serial.print("setupServo Index ="); Serial.println(servoIndex);

Expand All @@ -155,7 +157,7 @@ void NRF52_ISR_Servo::write(const uint8_t& servoIndex, uint16_t value)
{
// assumed to be 0-180 degrees servo
value = constrain(value, 0, 180);
value = map(value, 0, 180, _minUs, _maxUs);
value = map(value, 0, 180, servo[servoIndex].minPulseUs, servo[servoIndex].maxPulseUs);
}

writeMicroseconds(servoIndex, value);
Expand All @@ -165,7 +167,7 @@ void NRF52_ISR_Servo::write(const uint8_t& servoIndex, uint16_t value)

void NRF52_ISR_Servo::writeMicroseconds(const uint8_t& servoIndex, uint16_t value)
{
value = constrain(value, _minUs, _maxUs);
value = constrain(value, servo[servoIndex].minPulseUs, servo[servoIndex].maxPulseUs);
servo[servoIndex].position = value;

if ( (servo[servoIndex].enabled) && (servo[servoIndex].pwm) )
Expand All @@ -189,7 +191,7 @@ bool NRF52_ISR_Servo::setPosition(const uint8_t& servoIndex, uint16_t position)
{
// assumed to be 0-180 degrees servo
position = constrain(position, 0, 180);
position = map(position, 0, 180, _minUs, _maxUs);
position = map(position, 0, 180, servo[servoIndex].minPulseUs, servo[servoIndex].maxPulseUs);
}

servo[servoIndex].position = position;
Expand Down Expand Up @@ -239,12 +241,12 @@ bool NRF52_ISR_Servo::setPulseWidth(const uint8_t& servoIndex, uint16_t& pulseWi
// Updates interval of existing specified servo
if ( servo[servoIndex].enabled && (servo[servoIndex].pin <= NRF52_MAX_PIN) )
{
if (pulseWidth < _minUs)
pulseWidth = _minUs;
else if (pulseWidth > _maxUs)
pulseWidth = _maxUs;
if (pulseWidth < servo[servoIndex].minPulseUs)
pulseWidth = servo[servoIndex].minPulseUs;
else if (pulseWidth > servo[servoIndex].maxPulseUs)
pulseWidth = servo[servoIndex].maxPulseUs;

servo[servoIndex].position = map(pulseWidth, _minUs, _maxUs, 0, 180);
servo[servoIndex].position = map(pulseWidth, servo[servoIndex].minPulseUs, servo[servoIndex].maxPulseUs, 0, 180);

ISR_SERVO_LOGERROR3("Idx =", servoIndex, ", pos =",servo[servoIndex].position);

Expand Down Expand Up @@ -344,7 +346,7 @@ bool NRF52_ISR_Servo::enable(const uint8_t& servoIndex)
return false;
}

if ( servo[servoIndex].position >= _minUs )
if ( servo[servoIndex].position >= servo[servoIndex].minPulseUs )
servo[servoIndex].enabled = true;

return true;
Expand Down Expand Up @@ -373,7 +375,7 @@ void NRF52_ISR_Servo::enableAll()

for (int8_t servoIndex = 0; servoIndex < MAX_SERVOS; servoIndex++)
{
if ( (servo[servoIndex].position >= _minUs) && !servo[servoIndex].enabled
if ( (servo[servoIndex].position >= servo[servoIndex].minPulseUs) && !servo[servoIndex].enabled
&& (servo[servoIndex].pin <= NRF52_MAX_PIN) )
{
servo[servoIndex].enabled = true;
Expand Down

0 comments on commit faa076e

Please sign in to comment.