Skip to content

Commit

Permalink
Version 1.16rc2
Browse files Browse the repository at this point in the history
Fixed several bugs in file time stamping
Fixed M280 and M42 commands using unused heaster channels on Duet 0.6
and 0.8.5
Reduced the amount of I2C traffic, by using DueX5 interrupt line to tell
if new data is available and by only sending fan PWM values when they
change
Display TMC2660 driver status and DueX2/X5 stall status in M122 response
Removed E parameter from M574 command (use M558 I parameter instead)
Fixed response to M307 with H parameter only
  • Loading branch information
dc42 committed Nov 5, 2016
1 parent 6f71c76 commit 619e5c4
Show file tree
Hide file tree
Showing 22 changed files with 209 additions and 95 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions src/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ Licence: GPL
// Firmware name is now defined in the Pins file

#ifndef VERSION
# define VERSION "1.16rc1"
# define VERSION "1.16rc2"
#endif

#ifndef DATE
# define DATE "2016-11-03"
# define DATE "2016-11-05"
#endif

#define AUTHORS "reprappro, dc42, zpl, t3p3, dnewman"
Expand Down
4 changes: 3 additions & 1 deletion src/Duet/Webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ void Webserver::HttpInterpreter::GetJsonResponse(const char* request, OutputBuff
if (numQualKeys > 1 && StringEquals(qualifiers[1].key, "time") && !platform->IsDateTimeSet())
{
struct tm timeInfo;
memset(&timeInfo, 0, sizeof(timeInfo));
if (strptime(qualifiers[1].value, "%Y-%m-%dT%H:%M:%S", &timeInfo) != nullptr)
{
time_t newTime = mktime(&timeInfo);
Expand Down Expand Up @@ -1589,6 +1590,7 @@ bool Webserver::HttpInterpreter::ProcessMessage()
if (numQualKeys > 1 && StringEquals(qualifiers[1].key, "time"))
{
struct tm timeInfo;
memset(&timeInfo, 0, sizeof(timeInfo));
if (strptime(qualifiers[1].value, "%Y-%m-%dT%H:%M:%S", &timeInfo) != nullptr)
{
fileLastModified = mktime(&timeInfo);
Expand Down Expand Up @@ -2333,7 +2335,7 @@ void Webserver::FtpInterpreter::ProcessLine()
// Example for a typical UNIX-like file list:
// "drwxr-xr-x 2 ftp ftp 0 Apr 11 2013 bin\r\n"
const char dirChar = (fileInfo.isDirectory) ? 'd' : '-';
struct tm *timeInfo = localtime(&fileInfo.lastModified);
const struct tm * const timeInfo = gmtime(&fileInfo.lastModified);
dataTransaction->Printf("%crw-rw-rw- 1 ftp ftp %13lu %s %02d %04d %s\r\n",
dirChar, fileInfo.size, platform->GetMassStorage()->GetMonthName(timeInfo->tm_mon + 1),
timeInfo->tm_mday, timeInfo->tm_year + 1900, fileInfo.fileName);
Expand Down
35 changes: 28 additions & 7 deletions src/DuetNG/DueXn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

#include "DueXn.h"
#include "SX1509.h"
#include "Platform.h"

namespace DuetExpansion
{
static SX1509 expander;
static uint16_t inputMask;
static ExpansionBoardType boardType = ExpansionBoardType::none;
static uint16_t inputBits;

const uint8_t DueXnAddress = 0x3E; // address of the SX1509B on the DueX0/DueX2/DueX5

Expand All @@ -33,7 +35,8 @@ namespace DuetExpansion
const unsigned int E4StopBit = 2;
const unsigned int E5StopBit = 1;
const unsigned int E6StopBit = 13;
const uint16_t AllStopBits = (1u << E2StopBit) | (1u << E3StopBit) | (1u << E4StopBit) | (1u << E5StopBit) | (1u << E6StopBit);
const uint16_t AllStopBitsX2 = (1u << E2StopBit) | (1u << E3StopBit);
const uint16_t AllStopBitsX5 = AllStopBitsX2 | (1u << E4StopBit) | (1u << E5StopBit) | (1u << E6StopBit);

const unsigned int Gpio1Bit = 11;
const unsigned int Gpio2Bit = 10;
Expand Down Expand Up @@ -64,16 +67,21 @@ namespace DuetExpansion

if (boardType != ExpansionBoardType::none)
{
pinMode(DueX_INT, INPUT_PULLUP);
pinMode(DueX_SG, INPUT_PULLUP);

expander.pinModeMultiple(AllFanBits, OUTPUT_PWM); // Initialise the PWM pins
expander.pinModeMultiple(AllStopBits, INPUT); // Initialise the endstop inputs (no pullups because 5V-tolerant)
const uint16_t stopBits = (boardType == ExpansionBoardType::DueX5) ? AllStopBitsX5 : AllStopBitsX2; // I am assuming that the X0 has 2 endstop inputs
expander.pinModeMultiple(stopBits, INPUT); // Initialise the endstop inputs (no pullups because 5V-tolerant)
expander.pinModeMultiple(AllGpioBits, INPUT); // Initialise the GPIO pins as inputs

// Set up the interrupt on any input change
inputMask = AllStopBits | AllGpioBits;
inputMask = stopBits | AllGpioBits;
expander.enableInterruptMultiple(inputMask, CHANGE);

// Clear any initial interrupts
expander.interruptSource(true);
(void)expander.interruptSource(true);
inputBits = expander.digitalReadAll();
}

return boardType;
Expand Down Expand Up @@ -114,6 +122,10 @@ namespace DuetExpansion
case OUTPUT_PWM:
mode = OUTPUT_PWM_OPEN_DRAIN;
break;
case INPUT_PULLUP:
case INPUT_PULLDOWN:
mode = INPUT; // we are using 5rV-tolerant input with external pullup resistors, so don't enable internal pullup/pulldown resistors
break;
default:
break;
}
Expand All @@ -127,9 +139,18 @@ namespace DuetExpansion
// We need to use the SX15089 interrupt to read the data register using interrupts, and just retrieve that value here.
bool DigitalRead(Pin pin)
{
return (boardType != ExpansionBoardType::none)
? expander.digitalRead(pin)
: false;
if (boardType == ExpansionBoardType::none || pin >= 16)
{
return false;
}

if (!digitalRead(DueX_INT))
{
// Interrupt is active, so input data may have changed
inputBits = expander.digitalReadAll();
}

return (inputBits & (1 << pin)) != 0;
}

// Write a pin
Expand Down
1 change: 0 additions & 1 deletion src/DuetNG/Pins_DuetNG.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const Pin DueX_INT = 17; // DueX interrupt pin = PA17 (was E6_STOP)
// Endstops
// RepRapFirmware only has a single endstop per axis.
// Gcode defines if it is a max ("high end") or min ("low end") endstop and sets if it is active HIGH or LOW.
//const Pin END_STOP_PINS[DRIVES] = { 46, 02, 93, 74, 48, 96, 97, 98, 99, 17 };
const Pin END_STOP_PINS[DRIVES] = { 46, 02, 93, 74, 48, 200, 203, 202, 201, 213 };

// HEATERS
Expand Down
15 changes: 4 additions & 11 deletions src/DuetNG/TMC2660.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include "RepRapFirmware.h"
#include "TMC2660.h"

#if !defined(PROTOTYPE_1)

Expand All @@ -25,7 +26,8 @@ const Pin DriversSclkPin = 23; // PA23
#define TMC_CLOCK_CHAN 1
#define TMC_CLOCK_ID ID_TC1 // this is channel 1 on TC0

const uint32_t DriversSpiClockFrequency = 1000000; // 1MHz SPI clock for now
const uint32_t DriversSpiClockFrequency = 4000000; // 4MHz SPI clock
const int StallGuardThreshold = 1; // Range is -64..63. Zero seems to be too sensitive. Higher values reduce sensitivity of stall detection.

// TMC2660 registers
const uint32_t TMC_REG_DRVCTRL = 0;
Expand Down Expand Up @@ -100,15 +102,6 @@ const uint32_t TMC_SMARTEN_SEDN_1 = 3 << 13;
const uint32_t TMC_SMARTEN_SEIMIN_HALF = 0 << 15;
const uint32_t TMC_SMARTEN_SEIMIN_QTR = 1 << 15;

// Read response. The microstep counter can also be read, but we don't include that here.
const uint32_t TMC_RR_SG = 1 << 0; // stall detected
const uint32_t TMC_RR_OT = 1 << 1; // over temperature shutdown
const uint32_t TMC_RR_OTPW = 1 << 2; // over temperature warning
const uint32_t TMC_RR_S2G = 3 << 3; // short to ground counter (2 bits)
const uint32_t TMC_RR_OLA = 1 << 5; // open load A
const uint32_t TMC_RR_OLB = 1 << 6; // open load B
const uint32_t TMC_RR_STST = 1 << 7; // standstill detected

const unsigned int NumWriteRegisters = 5;

// Chopper control register defaults
Expand All @@ -125,7 +118,7 @@ const uint32_t defaultChopConfToff = 4; // default value for TOFF when drive is
// StallGuard configuration register
const uint32_t defaultSgscConfReg =
TMC_REG_SGCSCONF
| 0; // minimum current until user has set it
| TMC_SGCSCONF_SGT(StallGuardThreshold);

// Driver configuration register
const uint32_t defaultDrvConfReg =
Expand Down
9 changes: 9 additions & 0 deletions src/DuetNG/TMC2660.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@

#include "Pins.h"

// TMC2660 Read response. The microstep counter can also be read, but we don't include that here.
const uint32_t TMC_RR_SG = 1 << 0; // stall detected
const uint32_t TMC_RR_OT = 1 << 1; // over temperature shutdown
const uint32_t TMC_RR_OTPW = 1 << 2; // over temperature warning
const uint32_t TMC_RR_S2G = 3 << 3; // short to ground counter (2 bits)
const uint32_t TMC_RR_OLA = 1 << 5; // open load A
const uint32_t TMC_RR_OLB = 1 << 6; // open load B
const uint32_t TMC_RR_STST = 1 << 7; // standstill detected

namespace TMC2660
{
void Init(const Pin[DRIVES], size_t numTmcDrivers)
Expand Down
2 changes: 2 additions & 0 deletions src/DuetNG/Webserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ bool Webserver::ProcessFirstFragment(HttpSession& session, const char* command,
if (timeVal != nullptr && !platform->IsDateTimeSet())
{
struct tm timeInfo;
memset(&timeInfo, 0, sizeof(timeInfo));
if (strptime(timeVal, "%Y-%m-%dT%H:%M:%S", &timeInfo) != nullptr)
{
time_t newTime = mktime(&timeInfo);
Expand Down Expand Up @@ -623,6 +624,7 @@ bool Webserver::ProcessFirstFragment(HttpSession& session, const char* command,
// Try to obtain the last modified time
time_t fileLastModified = 0;
struct tm timeInfo;
memset(&timeInfo, 0, sizeof(timeInfo));
if (timeVal != nullptr && strptime(timeVal, "%Y-%m-%dT%H:%M:%S", &timeInfo) != nullptr)
{
fileLastModified = mktime(&timeInfo);
Expand Down
51 changes: 35 additions & 16 deletions src/Fan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ void Fan::Init(Pin p_pin, bool hwInverted)
val = 0.0;
minVal = 0.1; // 10% minimum fan speed
blipTime = 100; // 100ms fan blip
blipStartTime = 0;
freq = DefaultFanPwmFreq;
pin = p_pin;
hardwareInverted = hwInverted;
inverted = false;
inverted = blipping = false;
heatersMonitored = 0;
triggerTemperature = HOT_END_FAN_TEMPERATURE;
lastPwm = -1.0;
Refresh();
}

Expand All @@ -28,10 +28,11 @@ void Fan::SetValue(float speed)
{
speed /= 255.0;
}
const float newVal = (speed > 0.0) ? constrain<float>(speed, minVal, 1.0) : 0.0;
if (val == 0.0 && newVal < 1.0 && blipTime != 0)
const float newVal = constrain<float>(speed, 0.0, 1.0);
if (val == 0.0 && newVal > 0.0 && newVal < 1.0 && blipTime != 0)
{
// Starting the fan from standstill, so blip the fan
blipping = true;
blipStartTime = millis();
}
val = newVal;
Expand Down Expand Up @@ -68,7 +69,17 @@ void Fan::SetHardwarePwm(float pwmVal)
{
invert = !invert;
}
Platform::WriteAnalog(pin, (invert) ? (1.0 - pwmVal) : pwmVal, freq);
if (invert)
{
pwmVal = 1.0 - pwmVal;
}

// Only set the PWM if it has changed, to avoid a lot of I2C traffic when we have a DueX5 connected
if (pwmVal != lastPwm)
{
lastPwm = pwmVal;
Platform::WriteAnalog(pin, pwmVal, freq);
}
}
}

Expand All @@ -91,23 +102,31 @@ void Fan::Refresh()
: (reprap.GetPlatform()->AnyHeaterHot(heatersMonitored, triggerTemperature))
? max<float>(0.5, val) // make sure that thermostatic fans always run at 50% speed or more
: 0.0;
if (reqVal > 0.0 && millis() - blipStartTime < blipTime)
{
SetHardwarePwm(1.0);
}
else if (reqVal > 0.0 && reqVal < minVal)
if (reqVal > 0.0)
{
SetHardwarePwm(minVal);
}
else
{
SetHardwarePwm(reqVal);
if (reqVal < minVal)
{
reqVal = minVal;
}

if (blipping)
{
if (millis() - blipStartTime < blipTime)
{
reqVal = 1.0;
}
else
{
blipping = false;
}
}
}
SetHardwarePwm(reqVal);
}

void Fan::Check()
{
if (heatersMonitored != 0 || blipTime != 0)
if (heatersMonitored != 0 || blipping)
{
Refresh();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Fan.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ class Fan
float val;
float minVal;
float triggerTemperature;
float lastPwm;
uint32_t blipTime; // in milliseconds
uint32_t blipStartTime;
uint16_t freq;
uint16_t heatersMonitored;
Pin pin;
bool inverted;
bool hardwareInverted;
bool blipping;

void Refresh();
void SetHardwarePwm(float pwmVal);
Expand Down
13 changes: 5 additions & 8 deletions src/GCodes/GCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3237,7 +3237,7 @@ bool GCodes::HandleMcode(GCodeBuffer* gb, StringRef& reply)
const int logicalPin = gb->GetIValue();
Pin pin;
bool invert;
if (platform->GetFirmwarePin(logicalPin, PinAccess::write, pin, invert))
if (platform->GetFirmwarePin(logicalPin, PinAccess::pwm, pin, invert))
{
if (gb->Seen('S'))
{
Expand Down Expand Up @@ -4313,7 +4313,7 @@ bool GCodes::HandleMcode(GCodeBuffer* gb, StringRef& reply)
}
else if (!model.IsEnabled())
{
reply.printf("Heater %u is disabled");
reply.printf("Heater %u is disabled", heater);
}
else
{
Expand Down Expand Up @@ -5071,10 +5071,9 @@ bool GCodes::HandleMcode(GCodeBuffer* gb, StringRef& reply)
{
bool seen = false;
bool logicLevel = (gb->Seen('S')) ? (gb->GetIValue() != 0) : true;
for (size_t axis = 0; axis <= numAxes; ++axis)
for (size_t axis = 0; axis < numAxes; ++axis)
{
const char letter = (axis == numAxes) ? extrudeLetter : axisLetters[axis];
if (gb->Seen(letter))
if (gb->Seen(axisLetters[axis]))
{
int ival = gb->GetIValue();
if (ival >= 0 && ival <= 3)
Expand All @@ -5096,8 +5095,6 @@ bool GCodes::HandleMcode(GCodeBuffer* gb, StringRef& reply)
(config == EndStopType::highEndStop) ? "high end" : (config == EndStopType::lowEndStop) ? "low end" : "none",
(config == EndStopType::noEndStop) ? "" : (logic) ? "high" : "low");
}
platform->GetEndStopConfiguration(E0_AXIS, config, logic);
reply.catf(" E (active %s)", (logic) ? "high" : "low");
}
}
break;
Expand Down Expand Up @@ -5634,7 +5631,7 @@ bool GCodes::HandleMcode(GCodeBuffer* gb, StringRef& reply)
case 905: // Set current RTC date and time
{
const time_t now = platform->GetDateTime();
struct tm * const timeInfo = localtime(&now);
struct tm * const timeInfo = gmtime(&now);
bool seen = false;

if (gb->Seen('P'))
Expand Down
4 changes: 2 additions & 2 deletions src/Libraries/Fatfs/fattime_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ uint32_t get_fattime(void);
*
* bit10:5 Minute (0..59)
*
* bit4:0 Second (0..59)
* bit4:0 Second/2 (0..29)
*
* \return Current time.
*/
Expand All @@ -84,7 +84,7 @@ uint32_t get_fattime(void)
| (ul_day << 16)
| (ul_hour << 11)
| (ul_minute << 5)
| (ul_second << 0);
| (ul_second >> 1);

return ul_time;
}
Expand Down
Loading

0 comments on commit 619e5c4

Please sign in to comment.