aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorStephane D'Alu <sdalu@sdalu.com>2016-11-24 12:00:11 +0100
committerStephane D'Alu <sdalu@sdalu.com>2016-11-24 12:00:11 +0100
commit5c85f5a7cea3a08662df1ab95d837d32982eecda (patch)
tree73f1a4032928689829434810e546319b130ac045 /os
parent7ea44ed39c7c25ad0b3e1ad331dcdd70ca534bae (diff)
downloadChibiOS-Contrib-5c85f5a7cea3a08662df1ab95d837d32982eecda.tar.gz
ChibiOS-Contrib-5c85f5a7cea3a08662df1ab95d837d32982eecda.tar.bz2
ChibiOS-Contrib-5c85f5a7cea3a08662df1ab95d837d32982eecda.zip
reducing to one magical value, putting reference to nrf51-pwm-library
Diffstat (limited to 'os')
-rw-r--r--os/hal/ports/NRF5/NRF51822/hal_pwm_lld.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/os/hal/ports/NRF5/NRF51822/hal_pwm_lld.c b/os/hal/ports/NRF5/NRF51822/hal_pwm_lld.c
index f446fd3..8f3ae25 100644
--- a/os/hal/ports/NRF5/NRF51822/hal_pwm_lld.c
+++ b/os/hal/ports/NRF5/NRF51822/hal_pwm_lld.c
@@ -18,6 +18,11 @@
* @file hal_pwm_lld.c
* @brief NRF51 PWM subsystem low level driver source.
*
+ * @note Using the method described in nrf51-pwm-library to correctly
+ * handle toggling of the pin with GPIOTE when changing period.
+ * It means it is generally unsafe to use GPIOTE with a period
+ * less than (2 * PWM_GPIOTE_DECISION_TIME / 16MHz)
+ *
* @addtogroup PWM
* @{
*/
@@ -31,6 +36,7 @@
/*===========================================================================*/
#define PWM_GPIOTE_PPI_CC 3
+#define PWM_GPIOTE_DECISION_TIME 160
/*===========================================================================*/
/* Driver exported variables. */
@@ -65,7 +71,16 @@ PWMDriver PWMD3;
/*===========================================================================*/
static const uint8_t pwm_margin_by_prescaler[] = {
- 80, 40, 20, 15, 10, 5, 2, 1, 1, 1
+ (PWM_GPIOTE_DECISION_TIME + 0) >> 0,
+ (PWM_GPIOTE_DECISION_TIME + 1) >> 1,
+ (PWM_GPIOTE_DECISION_TIME + 3) >> 2,
+ (PWM_GPIOTE_DECISION_TIME + 7) >> 3,
+ (PWM_GPIOTE_DECISION_TIME + 15) >> 4,
+ (PWM_GPIOTE_DECISION_TIME + 31) >> 5,
+ (PWM_GPIOTE_DECISION_TIME + 63) >> 6,
+ (PWM_GPIOTE_DECISION_TIME + 128) >> 7,
+ (PWM_GPIOTE_DECISION_TIME + 255) >> 8,
+ (PWM_GPIOTE_DECISION_TIME + 511) >> 9
};
/*===========================================================================*/
@@ -349,7 +364,7 @@ void pwm_lld_enable_channel(PWMDriver *pwmp,
current = pwmp->timer->CC[PWM_GPIOTE_PPI_CC];
if (pwm_within_safe_margins(pwmp, current, old_width) &&
- pwm_within_safe_margins(pwmp, current, new_width))
+ pwm_within_safe_margins(pwmp, current, new_width))
break;
}
if (((old_width <= current) && (current < new_width)) ||