From 95d40ed01f8e66aa6aaa97f8601a366bdc73d0e7 Mon Sep 17 00:00:00 2001 From: PatrickPenguinTurtle Date: Fri, 24 Jun 2016 22:46:43 -0400 Subject: [PATCH] Fixed issue with digital outputs used as pwm on mxp (#14) When a digital output object that was tied to an mxp pin had enable pwm called on it it would pwm on a pin 6 lower (although if this wasn't an mxp pin it wouldn't do anything at all.) Fixed in Digital.cpp by adding 6 if it is an MXP pin in setPWMOutputChannel() This should fix the CanJaguar test because when digitalOutputs used as PWM were freed, the PWM generator was set to the number of pins, which meant it was actually outputing on pin 20. Change-Id: Ib48db3e6e3bf78659622145969d24011cc231ea6 Updated Hal to include some documentation about swaping mxp pins. Cannot find NI related documentation as to the pin numbers being wrong though Change-Id: I71d84431dc9bc7bf22aa29b6633e49723311b5f7 fixed formatting on changed files Change-Id: I5b7c16cd798132b6b20c1d03f334a95b42d2ee11 --- hal/lib/athena/DIO.cpp | 4 ++++ hal/lib/athena/DigitalInternal.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/hal/lib/athena/DIO.cpp b/hal/lib/athena/DIO.cpp index ce1cfc19ec..1326635b25 100644 --- a/hal/lib/athena/DIO.cpp +++ b/hal/lib/athena/DIO.cpp @@ -126,6 +126,10 @@ void setPWMDutyCycle(void* pwmGenerator, double dutyCycle, int32_t* status) { void setPWMOutputChannel(void* pwmGenerator, uint32_t pin, int32_t* status) { uint32_t id = (uint32_t)pwmGenerator; if (id > 5) return; + if (pin >= kNumHeaders) { // if it is on the MXP + pin += kMXPDigitalPWMOffset; // then to write as a digital PWM pin requires + // an offset to write on the correct pin + } digitalSystem->writePWMOutputSelect(id, pin, status); } diff --git a/hal/lib/athena/DigitalInternal.h b/hal/lib/athena/DigitalInternal.h index 44be4d3d5e..0bbf699172 100644 --- a/hal/lib/athena/DigitalInternal.h +++ b/hal/lib/athena/DigitalInternal.h @@ -16,7 +16,9 @@ namespace hal { constexpr uint32_t kNumHeaders = 10; // Number of non-MXP pins constexpr uint32_t kDigitalPins = 26; constexpr uint32_t kPwmPins = 20; - +constexpr uint32_t kMXPDigitalPWMOffset = 6; // MXP pins when used as digital + // output pwm are offset by 6 from + // actual value constexpr uint32_t kExpectedLoopTiming = 40; /**