Allow runtime config/register motor/axis iRun current
This commit introduces a new set of registers 0x1e, 0x1f and 0x20 which allow reading and writing iRun current values for each axis/motor. Please note the register contains raw TMC2130 iRun value which needs to be translated into mA to be understandable by people. Translation table of iRun -> mA is present in tmc2130.cpp for now.pull/256/head
parent
9c9322d02f
commit
0bca66aeb5
|
|
@ -3,6 +3,77 @@
|
|||
#include "../config/config.h"
|
||||
#include "../debug.h"
|
||||
|
||||
//! @brief Translate current to tmc2130 vsense and IHOLD or IRUN - copied from MK3 FW repo
|
||||
//! @param cur current in mA
|
||||
//! @return 0 .. 63
|
||||
//! @n most significant bit is CHOPCONF vsense bit (sense resistor voltage based current scaling)
|
||||
//! @n rest is to be used in IRUN or IHOLD register
|
||||
//!
|
||||
//! | mA | trinamic register | note |
|
||||
//! | --- | --- | --- |
|
||||
//! | 0 | 0 | doesn't mean current off, lowest current is 1/32 current with vsense low range |
|
||||
//! | 30 | 1 | |
|
||||
//! | 40 | 2 | |
|
||||
//! | 60 | 3 | |
|
||||
//! | 90 | 4 | |
|
||||
//! | 100 | 5 | |
|
||||
//! | 120 | 6 | |
|
||||
//! | 130 | 7 | |
|
||||
//! | 150 | 8 | |
|
||||
//! | 180 | 9 | |
|
||||
//! | 190 | 10 | |
|
||||
//! | 210 | 11 | |
|
||||
//! | 230 | 12 | |
|
||||
//! | 240 | 13 | |
|
||||
//! | 250 | 13 | |
|
||||
//! | 260 | 14 | |
|
||||
//! | 280 | 15 | |
|
||||
//! | 300 | 16 | |
|
||||
//! | 320 | 17 | |
|
||||
//! | 340 | 18 | |
|
||||
//! | 350 | 19 | |
|
||||
//! | 370 | 20 | |
|
||||
//! | 390 | 21 | |
|
||||
//! | 410 | 22 | |
|
||||
//! | 430 | 23 | |
|
||||
//! | 450 | 24 | |
|
||||
//! | 460 | 25 | |
|
||||
//! | 480 | 26 | |
|
||||
//! | 500 | 27 | |
|
||||
//! | 520 | 28 | |
|
||||
//! | 525 | 29 | |
|
||||
//! | 530 | 30 | |
|
||||
//! | 540 | 33 | |
|
||||
//! | 560 | 34 | |
|
||||
//! | 580 | 35 | |
|
||||
//! | 590 | 36 | |
|
||||
//! | 610 | 37 | |
|
||||
//! | 630 | 38 | |
|
||||
//! | 640 | 39 | |
|
||||
//! | 660 | 40 | |
|
||||
//! | 670 | 41 | |
|
||||
//! | 690 | 42 | |
|
||||
//! | 710 | 43 | |
|
||||
//! | 720 | 44 | |
|
||||
//! | 730 | 45 | |
|
||||
//! | 760 | 46 | |
|
||||
//! | 770 | 47 | |
|
||||
//! | 790 | 48 | |
|
||||
//! | 810 | 49 | |
|
||||
//! | 820 | 50 | |
|
||||
//! | 840 | 51 | |
|
||||
//! | 850 | 52 | |
|
||||
//! | 870 | 53 | |
|
||||
//! | 890 | 54 | |
|
||||
//! | 900 | 55 | |
|
||||
//! | 920 | 56 | |
|
||||
//! | 940 | 57 | |
|
||||
//! | 950 | 58 | |
|
||||
//! | 970 | 59 | |
|
||||
//! | 980 | 60 | |
|
||||
//! | 1000 | 61 | |
|
||||
//! | 1020 | 62 | |
|
||||
//! | 1029 | 63 | |
|
||||
namespace hal {
|
||||
namespace tmc2130 {
|
||||
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ bool Idler::FinishHomingAndPlanMoveToParkPos() {
|
|||
void Idler::FinishMove() {
|
||||
currentlyEngaged = plannedMove;
|
||||
if (Disengaged()) // reduce power into the Idler motor when disengaged (less force necessary)
|
||||
SetCurrents(config::idler.iRun, config::idler.iHold);
|
||||
SetCurrents(mm::motion.CurrentsForAxis(axis).iRun, mm::motion.CurrentsForAxis(axis).iHold);
|
||||
else if (Engaged()) { // maximum motor power when the idler is engaged
|
||||
SetCurrents(config::idler.iRun, config::idler.iRun);
|
||||
SetCurrents(mm::motion.CurrentsForAxis(axis).iRun, mm::motion.CurrentsForAxis(axis).iRun);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ bool Motion::InitAxis(Axis axis) {
|
|||
Disable(axis);
|
||||
|
||||
// Init also applies the currently pre-set StallGuard threshold into the TMC driver
|
||||
return axisData[axis].drv.Init(axisParams[axis].params, axisParams[axis].currents, axisParams[axis].mode);
|
||||
return axisData[axis].drv.Init(axisParams[axis].params, axisData[axis].currents, axisParams[axis].mode);
|
||||
}
|
||||
|
||||
void Motion::SetEnabled(Axis axis, bool enabled) {
|
||||
|
|
|
|||
|
|
@ -356,11 +356,19 @@ public:
|
|||
return axisData[axis].ctrl;
|
||||
}
|
||||
|
||||
inline const MotorCurrents &CurrentsForAxis(Axis axis) const {
|
||||
return axisData[axis].currents;
|
||||
}
|
||||
inline void SetIRunForAxis(Axis axis, uint8_t i) {
|
||||
axisData[axis].currents.iRun = i;
|
||||
}
|
||||
|
||||
private:
|
||||
struct AxisData {
|
||||
TMC2130 drv; ///< Motor driver
|
||||
pulse_gen::PulseGen ctrl; ///< Motor controller
|
||||
bool enabled; ///< Axis enabled
|
||||
MotorCurrents currents; ///< Axis related currents
|
||||
st_timer_t residual; ///< Axis timer residual
|
||||
};
|
||||
|
||||
|
|
@ -372,7 +380,8 @@ private:
|
|||
axisParams[axis].jerk,
|
||||
axisParams[axis].accel,
|
||||
},
|
||||
.enabled = false
|
||||
.enabled = false,
|
||||
.currents = axisParams[axis].currents
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ MovableBase::OperationResult MovableBase::InitMovement() {
|
|||
|
||||
MovableBase::OperationResult __attribute__((noinline)) MovableBase::InitMovementNoReinitAxis() {
|
||||
PrepareMoveToPlannedSlot();
|
||||
// @@TODO update axis currents at this spot?
|
||||
state = Moving;
|
||||
return OperationResult::Accepted;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "modules/fsensor.h"
|
||||
#include "modules/globals.h"
|
||||
#include "modules/idler.h"
|
||||
#include "modules/motion.h"
|
||||
#include "modules/pulley.h"
|
||||
#include "modules/selector.h"
|
||||
#include "modules/permanent_storage.h"
|
||||
|
|
@ -159,6 +160,9 @@
|
|||
| 0x1bh 27 | uint16 | Set/Get_Selector_slot | 0000h 0 | ffffh 65535 | unit slot [0-4/5] 5=park pos | Read / Write | M707 A0x1b | M708 A0x1b Xn
|
||||
| 0x1ch 28 | uint16 | Set/Get_Idler_slot | 0000h 0 | ffffh 65535 | unit slot [0-4/5] 5=disengaged | Read / Write | M707 A0x1c | M708 A0x1c Xn
|
||||
| 0x1dh 29 | uint8 | Set/Get Selector cut iRun current | 0 to 63 (aka 0-1024mA)| 31 (530mA) | | Read / Write | M707 A0x1d | M708 A0x1d Xn
|
||||
| 0x1eh 30 | uint16 | Set/Get Pulley iRun current| 0-63 | 14h 20 | 20->350mA: see TMC2130 current conversion| Read / Write | M707 A0x1e | M708 A0x1e Xn
|
||||
| 0x1fh 31 | uint16 |Set/Get Selector iRun current| 0-63 | 1fh 31 | 31->530mA: see TMC2130 current conversion| Read / Write | M707 A0x1f | M708 A0x1f Xn
|
||||
| 0x20h 32 | uint16 | Set/Get Idler iRun current | 0-63 | 1fh 31 | 31->530mA: see TMC2130 current conversion| Read / Write | M707 A0x20 | M708 A0x20 Xn
|
||||
*/
|
||||
|
||||
struct RegisterFlags {
|
||||
|
|
@ -374,6 +378,22 @@ static const RegisterRec registers[] /*PROGMEM*/ = {
|
|||
[]() -> uint16_t { return mg::globals.CutIRunCurrent(); },
|
||||
[](uint16_t d) { mg::globals.SetCutIRunCurrent(d); },
|
||||
1),
|
||||
|
||||
// 0x1e Get/Set Pulley iRun current RW
|
||||
RegisterRec(
|
||||
[]() -> uint16_t { return mm::motion.CurrentsForAxis(config::Pulley).iRun; },
|
||||
[](uint16_t d) { mm::motion.SetIRunForAxis(config::Pulley, d); },
|
||||
1),
|
||||
// 0x1f Set/Get Selector iRun current RW
|
||||
RegisterRec(
|
||||
[]() -> uint16_t { return mm::motion.CurrentsForAxis(config::Selector).iRun; },
|
||||
[](uint16_t d) { mm::motion.SetIRunForAxis(config::Selector, d); },
|
||||
1),
|
||||
// 0x20 Set/Get Idler iRun current RW
|
||||
RegisterRec(
|
||||
[]() -> uint16_t { return mm::motion.CurrentsForAxis(config::Idler).iRun; },
|
||||
[](uint16_t d) { mm::motion.SetIRunForAxis(config::Idler, d); },
|
||||
1),
|
||||
};
|
||||
|
||||
static constexpr uint8_t registersSize = sizeof(registers) / sizeof(RegisterRec);
|
||||
|
|
|
|||
Loading…
Reference in New Issue