When setting up the configuration for TMC2209 driver boards in the latest firmware release, I see there are some values that need to be set prior to compiling and uploading to the Nano. I have a few questions on this process:
The myFP2-TRINAMIC-09.pdf file states on page 23 that values need to be set in "myBoards.cpp". However, I see some values are defined at the top of "myBoardDefs.h". Should I be setting things like the current, TOFF_VALUE, etc. in this file instead?
For the fCLK value (system clock speed), the ATmega328p processor has a clock speed of 16MHz. The default in the PDF is 12. Should I change this to 16 or leave it at 12? Setting it to 16 gives a hint on line 39 that motor frequency might get quite high and to work with increase histeresis settings and measure actual frequency or use ChopSync. Do I just do some trial-and-error guessing on the HSTART and HEND values to get something that will work? Or how do I adjust this to avoid an overly-high frequency for chopping?
Lastly, the Current Scale setting (CS) indicates that the scalar is quite small for microstepping. I'm not sure what to do about this, as it gets the Rsense value for VSENSE=0 right at 0.110 ohms.
Any advice here would be appreciated. Thanks! :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The myFP2-TRINAMIC-09.pdf file states on page 23 that values need to be set in "myBoards.cpp". However, I see some values are defined at the top of "myBoardDefs.h". Should I be setting things like the current, TOFF_VALUE, etc. in this file instead?
It is myBoardDefs.h and examples on the next pages refer to myBoardDefs.h
So it is a mistake and I correct it and upload a revised PDF. Thanks for identifying the error.
I would probably leave it at 12, as that is in the code examples from BigTree as well as the code the beta users tested over and over.
HSTART and HEND and Current Scale setting (CS) values will come from the spreadsheet - see page 24, the spreadsheet calculates these values for you and those are what you use.
The only ones that require you to "determine" is basically stall guard.
Cheers
Robert
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks, Robert. I'll give it a try and see how it goes. I figured we should be setting values where they're defined, but wanted to be sure.
I'm a little concerned at how small my CS value is, as the notes all say values from 16-31 are ideal for microstepping. I guess I'll find out if it works!
Another thing you may want to note in the PDF is that current values for motors may not specify peak or RMS, and to confirm that with the manufacturer. I believe most of the ones not specified are peak values.
It seems like this is pretty new territory, and these TMC2209's are a bit more work to get right. So, big thanks to everyone involved for working to get the info put together for the rest of us.
Last edit: Eric Schubert 2021-06-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I should also ask... the part of the PDF where it says that the CS value is controlled in the code by using "mystepper->irun(xx)", should we be copying/pasting that into the code? I couldn't find it anywhere, so I assume so. But wanted to verify.
My motor specs also show that the lower voltage limit for microstepping to utilize full current is 20V (compared to my PSU voltage of 12V). Will this be a problem? What will this do during microstepping? Produce lower torque?
Last edit: Eric Schubert 2021-06-14
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There will be differences between the documentation and the code.
The code is the important thing here. That is the code which all users of the beta group used and verified. So there will be instances as you have discovered that the documentation says something different to the code - I did not document all the changes as they occured, and there were literally hundreds of code changes - I am not suprised the documentation says 1 thing and the code says another.
I have not had time to go back and correct all the errors in the documentation. Other things keep me busy at present. I will get round to it sometime.
I would point out that whilst I helped integrating the code into myFP2 I did not have any TMC chips to test myself, hence the reliance on a group of enthusiatic testers to test and report back. So it really is their work which has made this possible.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was also looking for where to put the CS value. There is no call tu irun() anywhere in the code anymore, and no other place to set the value either. (And I also got a low value of 4 for the 17NEMA PG27.) I also did not find any reason to set stepping to 4 instead of just 1; 5370 steps per revolution seems more than enough to me.
In addition, I have a problem with the StallGuard: It gets triggered ALWAYS when I press the PB_IN button, actually also when I try to quickly activate the "-1" movent several times in a row, and lately also quite often when I trigger just ANY movement in the negative direction. (I am still testing with no load at all, and I tried to play with the threshold values. No improvement.)
Last edit: wanthalf 2022-05-10
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is an email from the code developer which might shed some light
Hello all,
Just some additional info.
I wanted to emphasize the importance of using the right parameters and settings, in order to achieve the best possible results.
We commented on myBoards.cpp that the values need to be calculated with the spreadsheet provided by Trinamic for the specific chip.
mystepper->toff(3); // Use TMC22xx Calculations sheet to get these.
mystepper->tbl(2); // Use TMC22xx Calculations sheet to get these.
mystepper->hysteresis_start(0); // Use TMC22xx Calculations sheet to get these.
mystepper->hysteresis_end(0); // Use TMC22xx Calculations sheet to get these.
And I also added this setting, since it’s on the spreadsheet.
mystepper->irun(21); // Use TMC22xx Calculations sheet to get these - irun = CS (current scale setting).
The values the chip produces for SG_RESULT are highly dependent on the stepper properties and speed, and therefore these parameters.
I just played around with these settings, and can confirm, the HPSW ROUTINE works best when the correct setting are used.
Select the chip type you’re using, and find the spreadsheet under ‘Downloads’
Follow the instructions on tab1 - Velocity Calculation and tab2 - Chopper Parameters, enter the yellow fields.
In this example I used 60rpm (nice speed for a focuser), 12V VMOT, from nema17 datasheet –> 1.8 step-angle, 1.7A, 0,15 MH and 1.5Ohm
My BTT TMC2209 use 0.11 ohm RSENSE resistors, so enter a value in cell C27 on tab2 = CS that produces a RSENSE value in cell C47 that’s close to your chip’s RSENSE value.
CS := 21
Rsense using VSENSE=0
0.109
Ohm
The CS value is set with mystepper->irun(xx);
The hysteresis settings are found in Register value for CHOPCONF register bits
HSTRT setting
HEND setting
I’ll attach my calculations for a NEMA17 17HS4401.
I did a quick test with a geared stepper. The only one I had lying around is a rather beefy 17-HS19-1684S-PG51.
But that shouldn’t matter.
The calculation-sheet gives us for this stepper:
mystepper->beginSerial(TMC2209SPEED);
mystepper->pdn_disable(1); // Use PDN/UART pin for communication
mystepper->mstep_reg_select(true); // Adjust stepMode from the registers
// if you want to adjust current by software, uncomment these lines
mystepper->I_scale_analog(0); // Adjust current from the registers
mystepper->rms_current( TMC2209CURRENT ); // Set driver current
mystepper->toff(3); // Use TMC22xx Calculations sheet to get these.
mystepper->tbl(2); // TMC22xx Calculations sheets can be found.
mystepper->hysteresis_start(0); // on the Trinamic website: https://www.trinamic.com/products/integrated-circuits/
mystepper->hysteresis_end(1); // Use TMC22xx Calculations sheet to get these.
mystepper->irun(21); // irun = CS (current scale setting) on the sheet
mystepper->TCOOLTHRS(0xFFFFF); // 20bit max
mystepper->semin(2);
mystepper->semax(5);
mystepper->sedn(0b00);
mystepper->SGTHRS(STALL_VALUE); //STALL_VALUE = 0
I used these stepdelays:
define DRVFAST 1024 // delays for motorspeed
define DRVMED 2048
define DRVSLOW 4096
First thing I noticed is that when using the fastest speed, my stepper doesn’t run very smooth, it sounds like it’s at or over the highest attainable speed.
So I needed to drill the speed down a little:
define DRVFAST 2000 // delays for motorspeed
define DRVMED 4000
define DRVSLOW 8000
With these delays, the stepper moves very smooth and almost silent, exactly why we use these TMCs.
I started out with a stall value of 0 (and yes at the higher speeds I started with, even that was too sensitive).
With the more moderate speeds, I could easily go up to a STALL_VALUE = 10
So it is possible to also get a geared stepper to work, but it comes with proper tuning and maybe a little sacrifice in the maximum speed (but your stepper is of a lower ratio than mine).
According to the calculation-sheet, the values for your stepper would be:
define TMC2209CURRENT 400 // on myBoards.cpp
mystepper->I_scale_analog(0); // Adjust current from the registers
mystepper->rms_current( TMC2209CURRENT ); // Set driver current
mystepper->toff(3); // Use TMC22xx Calculations sheet to get these.
mystepper->tbl(2); // TMC22xx Calculations sheets can be found.
mystepper->hysteresis_start(0); // on the Trinamic website: https://www.trinamic.com/products/integrated-circuits/
mystepper->hysteresis_end(0); // Use TMC22xx Calculations sheet to get these.
mystepper->irun(4); // irun = CS (current scale setting) on the sheet
mystepper->TCOOLTHRS(0xFFFFF); // 20bit max
mystepper->semin(2);
mystepper->semax(5);
mystepper->sedn(0b00);
mystepper->SGTHRS(STALL_VALUE); //STALL_VALUE = t.b.d. by user
You can check if UART is working correctly by going on the ‘Motor Settings’ tab in the windows app, set a stepMode, and check if it comes back ok with a ‘Get stepMode’.
.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
This next part applies to the attached picture - using the serial monitor plot of the Arduino IDE
In the video, the serial plot output from ArduinoIDE for a TMC2226(similar to 2209)
running on an Arduino DUE (I needed a hardware Serial port).
The PURPLE line is the StallGuard value (driver.SG_RESULT)
The RED line is (driver.SG_RESULT() < STALL_VALUE)
and the GREEN line is the output from the DIAG_PIN (*100 for better display)
When running, the purple line is constant, if applied braking force on the axle,
the stallguard value rises,
when exceeds the threshold (STALL_VALUE) then the DIAG_PIN is set HIGH (pulsed) by stallguard.
From TMC datasheet:
DIAG is pulsed by StallGuard, when SG_RESULT falls below SGTHRS. It is only enabled in StealthChop
mode, and when TCOOLTHRS ≥ TSTEP > TPWMTHRS
The external motion controller should react to a single pulse by stopping the motor if desired. Set
TCOOLTHRS to match the lower velocity threshold where StallGuard delivers a good result.
So when calibrated correctly, in my opinion it would be possible to use the DIAG_PIN as a homing switch.
It's also an option to do it completely in software with:
if(driver.SG_RESULT() < STALL_VALUE)
.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stall Guard Test Program
/
* Author Milan Divkovic
*
You can control the motor with following commands:
* 0: Disables the motor
* 1: Enables the motor
* + or -: Increase or decrease speed in respect to rotation direction /
include <arduino.h></arduino.h>
include <tmcstepper.h></tmcstepper.h>
define STALL_VALUE 100 // [0... 255]
define TOFF_VALUE 4 // [1... 15]
define DIAG_PIN 12
define EN_PIN 8 // Enable pin
define SW_RX 10 // SoftwareSerial receive pin
define SW_TX 11 // SoftwareSerial transmit pin
//#define SERIAL_PORT Serial2 // HardwareSerial port
define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2
define R_SENSE 0.11f // Match to your driver
// SilentStepStick series use 0.11
// UltiMachine Einsy and Archim2 boards use 0.2
// Panucatt BSD2660 uses 0.1
// Watterott TMC5160 uses 0.075
// Select your stepper driver type
//TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS);
TMC2209Stepper driver(SW_RX, SW_TX, R_SENSE, DRIVER_ADDRESS);
using namespace TMC2208_n;
int32_t speed = 5000;
void setup() {
Serial.begin(115200); // Init serial port and set baudrate
while(!Serial); // Wait for serial port to connect
Serial.println("\nStart...");
// Sets the slow decay time (off time) [1... 15]. This setting also limits
// the maximum chopper frequency. For operation with StealthChop,
// this parameter is not used, but it is required to enable the motor.
// In case of operation with StealthChop only, any setting is OK.
driver.toff(TOFF_VALUE);
// VACTUAL allows moving the motor by UART control.
// It gives the motor velocity in +-(2^23)-1 [μsteps / t]
// 0: Normal operation. Driver reacts to STEP input.
// /=0: Motor moves with the velocity given by VACTUAL.
// Step pulses can be monitored via INDEX output.
// The motor direction is controlled by the sign of VACTUAL.
driver.VACTUAL(speed);
// Comparator blank time. This time needs to safely cover the switching
// event and the duration of the ringing on the sense resistor. For most
// applications, a setting of 16 or 24 is good. For highly capacitive
// loads, a setting of 32 or 40 will be required.
driver.blank_time(24);
driver.rms_current(1000); // mA
driver.microsteps(16);
// Lower threshold velocity for switching on smart energy CoolStep and StallGuard to DIAG output
driver.TCOOLTHRS(0xFFFFF); // 20bit max
// CoolStep lower threshold [0... 15].
// If SG_RESULT goes below this threshold, CoolStep increases the current to both coils.
// 0: disable CoolStep
driver.semin(5);
// CoolStep upper threshold [0... 15].
// If SG is sampled equal to or above this threshold enough times,
// CoolStep decreases the current to both coils.
driver.semax(2);
// Sets the number of StallGuard2 readings above the upper threshold necessary
// for each current decrement of the motor current.
driver.sedn(0b01);
// StallGuard4 threshold [0... 255] level for stall detection. It compensates for
// motor specific characteristics and controls sensitivity. A higher value gives a higher
// sensitivity. A higher value makes StallGuard4 more sensitive and requires less torque to
// indicate a stall. The double of this value is compared to SG_RESULT.
// The stall output becomes active if SG_RESULT fall below this value.
driver.SGTHRS(STALL_VALUE);
Serial.print("\nTesting connection...");
uint8_t result = driver.test_connection();
if (result) {
Serial.println("failed!");
Serial.print("Likely cause: ");
switch(result) {
case 1: Serial.println("loose connection"); break;
case 2: Serial.println("no power"); break;
}
Serial.println("Fix the problem and reset board.");
// We need this delay or messages above don't get fully printed out
delay(100);
abort();
}
if((ms-last_time) > 100 && driver.toff() != 0 && speed != 0) { // run every 0.1s
last_time = ms;
Serial.print("Status: ");
Serial.print(driver.SG_RESULT(), DEC);
Serial.print(" ");
Serial.print(digitalRead(DIAG_PIN)*150);
Serial.print(" ");
Serial.print((driver.SG_RESULT() < STALL_VALUE), DEC);
Serial.print(" ");
Serial.println(driver.cs2rms(driver.cs_actual()), DEC);
}
}
On Wednesday, May 11, 2022, 02:59:06 AM GMT+12, Pavel Vondricka wanthalf@users.sourceforge.net wrote:
I was also looking for where to put the CS value. There is no call tu irun() anywhere in the code anymore, and no other place to set the value either. (And I also got a low value of 4 for the 17NEMA PG27.) I also did not find any reason to set stepping to 4 instead of just 1: 5370 steps per revolution seems more than enough to me.
In addition, I have a problem with the StallGuard: It gets triggered ALWAYS when I press the PB_IN button, actually also when I try to quickly activate the "-1" movent several times in a row, and lately also quite often when I just trigger just ANY movement in the negative direction. (I am still testing with no load at all, and I tried to play with the threshold values. No improvement.)
As the firmware 307 was developed further and the code improved, a lot of calls, including irun were found to not be needed for trimac steppers. Hence they were dropped from later firmware.
I attach the spreadsheets and pdf from those who developed/tested/modified the code associated with tmc2209 etc.
because some users struggled with stall guard (not all testers were successful) the fallback to using a Home Position switch was put into the code, as some found stall guard too time consuming to get it right.
I have attached also the archive of the trimac firmware starting at 307.
Please let me know if any of that helps. You will be able to compare each update to the previous and see the evolution of the code.
thanks for the files. I will try to have a look at them and find any differences or what all the SG versions mean. I am just afraid of a possible hardware problem in my wiring or something similar. It also does look like the signals at the DIAG pin are more complex than just pulling down in the case of stall.
Also, the question is what is the whole point of the Trinamic spreadsheets if the most important value (CS) cannot or should not be entered anywhere in the code anymore. Yes, there are a few other values, but according to my observations, those do not make any significant difference to anything: neither the calculation in the spreadsheet nor in the real usage.
I also have problem with the OLED_GRAPHIC mode: it always just shows "offline", because the ConnectionStatus never changes to "connected". I will also have a look at that - I suppose it might be an unfinished part of the code, right...?
It is sometimes a bit confusing that the documentation contains some inconsistencies or even contradictions. I know that such a complex project with many combinations cannot be easilly maintained by a single person. I wonder whether it might possibly help to move the documentation to some GIT repository as well (like the firmware) and track the changes. But maybe it is a problem as there is a lot of non-textual files.
Anyway, I am trying to add additional buttons for finer control of the focuser. I will publish the results if I come to some satisfactory results.
Best regards,
Pavel
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Oh, I am in a wrong place, sorry! I am using the ESP32 version. Google search just lead me to this discussion related to TMC2209 in myFocuserPro, so I did not notice. Should I switch to the other discussion? Some existing thread or start a new one?
Last edit: wanthalf 2022-05-12
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
When setting up the configuration for TMC2209 driver boards in the latest firmware release, I see there are some values that need to be set prior to compiling and uploading to the Nano. I have a few questions on this process:
Any advice here would be appreciated. Thanks! :)
The myFP2-TRINAMIC-09.pdf file states on page 23 that values need to be set in "myBoards.cpp". However, I see some values are defined at the top of "myBoardDefs.h". Should I be setting things like the current, TOFF_VALUE, etc. in this file instead?
It is myBoardDefs.h and examples on the next pages refer to myBoardDefs.h
So it is a mistake and I correct it and upload a revised PDF. Thanks for identifying the error.
I would probably leave it at 12, as that is in the code examples from BigTree as well as the code the beta users tested over and over.
HSTART and HEND and Current Scale setting (CS) values will come from the spreadsheet - see page 24, the spreadsheet calculates these values for you and those are what you use.
The only ones that require you to "determine" is basically stall guard.
Cheers
Robert
Thanks, Robert. I'll give it a try and see how it goes. I figured we should be setting values where they're defined, but wanted to be sure.
I'm a little concerned at how small my CS value is, as the notes all say values from 16-31 are ideal for microstepping. I guess I'll find out if it works!
Another thing you may want to note in the PDF is that current values for motors may not specify peak or RMS, and to confirm that with the manufacturer. I believe most of the ones not specified are peak values.
It seems like this is pretty new territory, and these TMC2209's are a bit more work to get right. So, big thanks to everyone involved for working to get the info put together for the rest of us.
Last edit: Eric Schubert 2021-06-14
HSTART and HEND and
Current Scale setting (CS) values
will come from the spreadsheet - see page 24, the spreadsheet calculates these values for you and those are what you use.
The CS value is set with mystepper->irun(xx);
So if you had a value of 7 for CS then to set CS, it becomes
mystepper->irun(7);
I should also ask... the part of the PDF where it says that the CS value is controlled in the code by using "mystepper->irun(xx)", should we be copying/pasting that into the code? I couldn't find it anywhere, so I assume so. But wanted to verify.
My motor specs also show that the lower voltage limit for microstepping to utilize full current is 20V (compared to my PSU voltage of 12V). Will this be a problem? What will this do during microstepping? Produce lower torque?
Last edit: Eric Schubert 2021-06-14
There will be differences between the documentation and the code.
The code is the important thing here. That is the code which all users of the beta group used and verified. So there will be instances as you have discovered that the documentation says something different to the code - I did not document all the changes as they occured, and there were literally hundreds of code changes - I am not suprised the documentation says 1 thing and the code says another.
I have not had time to go back and correct all the errors in the documentation. Other things keep me busy at present. I will get round to it sometime.
I would point out that whilst I helped integrating the code into myFP2 I did not have any TMC chips to test myself, hence the reliance on a group of enthusiatic testers to test and report back. So it really is their work which has made this possible.
I was also looking for where to put the CS value. There is no call tu irun() anywhere in the code anymore, and no other place to set the value either. (And I also got a low value of 4 for the 17NEMA PG27.) I also did not find any reason to set stepping to 4 instead of just 1; 5370 steps per revolution seems more than enough to me.
In addition, I have a problem with the StallGuard: It gets triggered ALWAYS when I press the PB_IN button, actually also when I try to quickly activate the "-1" movent several times in a row, and lately also quite often when I trigger just ANY movement in the negative direction. (I am still testing with no load at all, and I tried to play with the threshold values. No improvement.)
Last edit: wanthalf 2022-05-10
Here is an email from the code developer which might shed some light
Hello all,
Just some additional info.
I wanted to emphasize the importance of using the right parameters and settings, in order to achieve the best possible results.
We commented on myBoards.cpp that the values need to be calculated with the spreadsheet provided by Trinamic for the specific chip.
mystepper->toff(3); // Use TMC22xx Calculations sheet to get these.
mystepper->tbl(2); // Use TMC22xx Calculations sheet to get these.
mystepper->hysteresis_start(0); // Use TMC22xx Calculations sheet to get these.
mystepper->hysteresis_end(0); // Use TMC22xx Calculations sheet to get these.
And I also added this setting, since it’s on the spreadsheet.
mystepper->irun(21); // Use TMC22xx Calculations sheet to get these - irun = CS (current scale setting).
The values the chip produces for SG_RESULT are highly dependent on the stepper properties and speed, and therefore these parameters.
I just played around with these settings, and can confirm, the HPSW ROUTINE works best when the correct setting are used.
The spreadsheets can be found on the Trinamic website: https://www.trinamic.com/products/integrated-circuits/
Select the chip type you’re using, and find the spreadsheet under ‘Downloads’
Follow the instructions on tab1 - Velocity Calculation and tab2 - Chopper Parameters, enter the yellow fields.
In this example I used 60rpm (nice speed for a focuser), 12V VMOT, from nema17 datasheet –> 1.8 step-angle, 1.7A, 0,15 MH and 1.5Ohm
My BTT TMC2209 use 0.11 ohm RSENSE resistors, so enter a value in cell C27 on tab2 = CS that produces a RSENSE value in cell C47 that’s close to your chip’s RSENSE value.
CS := 21
Rsense using VSENSE=0
0.109
Ohm
The CS value is set with mystepper->irun(xx);
The hysteresis settings are found in Register value for CHOPCONF register bits
HSTRT setting
HEND setting
I’ll attach my calculations for a NEMA17 17HS4401.
I did a quick test with a geared stepper. The only one I had lying around is a rather beefy 17-HS19-1684S-PG51.
But that shouldn’t matter.
The calculation-sheet gives us for this stepper:
mystepper->beginSerial(TMC2209SPEED);
mystepper->pdn_disable(1); // Use PDN/UART pin for communication
mystepper->mstep_reg_select(true); // Adjust stepMode from the registers
// if you want to adjust current by software, uncomment these lines
mystepper->I_scale_analog(0); // Adjust current from the registers
mystepper->rms_current( TMC2209CURRENT ); // Set driver current
mystepper->toff(3); // Use TMC22xx Calculations sheet to get these.
mystepper->tbl(2); // TMC22xx Calculations sheets can be found.
mystepper->hysteresis_start(0); // on the Trinamic website: https://www.trinamic.com/products/integrated-circuits/
mystepper->hysteresis_end(1); // Use TMC22xx Calculations sheet to get these.
mystepper->irun(21); // irun = CS (current scale setting) on the sheet
mystepper->TCOOLTHRS(0xFFFFF); // 20bit max
mystepper->semin(2);
mystepper->semax(5);
mystepper->sedn(0b00);
mystepper->SGTHRS(STALL_VALUE); //STALL_VALUE = 0
I used these stepdelays:
define DRVFAST 1024 // delays for motorspeed
define DRVMED 2048
define DRVSLOW 4096
First thing I noticed is that when using the fastest speed, my stepper doesn’t run very smooth, it sounds like it’s at or over the highest attainable speed.
So I needed to drill the speed down a little:
define DRVFAST 2000 // delays for motorspeed
define DRVMED 4000
define DRVSLOW 8000
With these delays, the stepper moves very smooth and almost silent, exactly why we use these TMCs.
I started out with a stall value of 0 (and yes at the higher speeds I started with, even that was too sensitive).
With the more moderate speeds, I could easily go up to a STALL_VALUE = 10
So it is possible to also get a geared stepper to work, but it comes with proper tuning and maybe a little sacrifice in the maximum speed (but your stepper is of a lower ratio than mine).
According to the calculation-sheet, the values for your stepper would be:
define TMC2209CURRENT 400 // on myBoards.cpp
mystepper->I_scale_analog(0); // Adjust current from the registers
mystepper->rms_current( TMC2209CURRENT ); // Set driver current
mystepper->toff(3); // Use TMC22xx Calculations sheet to get these.
mystepper->tbl(2); // TMC22xx Calculations sheets can be found.
mystepper->hysteresis_start(0); // on the Trinamic website: https://www.trinamic.com/products/integrated-circuits/
mystepper->hysteresis_end(0); // Use TMC22xx Calculations sheet to get these.
mystepper->irun(4); // irun = CS (current scale setting) on the sheet
mystepper->TCOOLTHRS(0xFFFFF); // 20bit max
mystepper->semin(2);
mystepper->semax(5);
mystepper->sedn(0b00);
mystepper->SGTHRS(STALL_VALUE); //STALL_VALUE = t.b.d. by user
You can check if UART is working correctly by going on the ‘Motor Settings’ tab in the windows app, set a stepMode, and check if it comes back ok with a ‘Get stepMode’.
.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
This next part applies to the attached picture - using the serial monitor plot of the Arduino IDE
In the video, the serial plot output from ArduinoIDE for a TMC2226(similar to 2209)
running on an Arduino DUE (I needed a hardware Serial port).
code:
Serial.print("Status: ");
Serial.print(driver.SG_RESULT(), DEC);
Serial.print(" ");
Serial.print(digitalRead(DIAG_PIN)*100);
Serial.print(" ");
Serial.print((driver.SG_RESULT() < STALL_VALUE), DEC);
Serial.print(" ");
Serial.println(driver.cs2rms(driver.cs_actual()), DEC);
So:
The PURPLE line is the StallGuard value (driver.SG_RESULT)
The RED line is (driver.SG_RESULT() < STALL_VALUE)
and the GREEN line is the output from the DIAG_PIN (*100 for better display)
When running, the purple line is constant, if applied braking force on the axle,
the stallguard value rises,
when exceeds the threshold (STALL_VALUE) then the DIAG_PIN is set HIGH (pulsed) by stallguard.
From TMC datasheet:
DIAG is pulsed by StallGuard, when SG_RESULT falls below SGTHRS. It is only enabled in StealthChop
mode, and when TCOOLTHRS ≥ TSTEP > TPWMTHRS
The external motion controller should react to a single pulse by stopping the motor if desired. Set
TCOOLTHRS to match the lower velocity threshold where StallGuard delivers a good result.
So when calibrated correctly, in my opinion it would be possible to use the DIAG_PIN as a homing switch.
It's also an option to do it completely in software with:
if(driver.SG_RESULT() < STALL_VALUE)
.>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Stall Guard Test Program
/ * Author Milan Divkovic * You can control the motor with following commands: * 0: Disables the motor * 1: Enables the motor * + or -: Increase or decrease speed in respect to rotation direction
/
include <arduino.h></arduino.h>
include <tmcstepper.h></tmcstepper.h>
define STALL_VALUE 100 // [0... 255]
define TOFF_VALUE 4 // [1... 15]
define DIAG_PIN 12
define EN_PIN 8 // Enable pin
define SW_RX 10 // SoftwareSerial receive pin
define SW_TX 11 // SoftwareSerial transmit pin
//#define SERIAL_PORT Serial2 // HardwareSerial port
define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2
define R_SENSE 0.11f // Match to your driver
// SilentStepStick series use 0.11
// UltiMachine Einsy and Archim2 boards use 0.2
// Panucatt BSD2660 uses 0.1
// Watterott TMC5160 uses 0.075
// Select your stepper driver type
//TMC2209Stepper driver(&SERIAL_PORT, R_SENSE, DRIVER_ADDRESS);
TMC2209Stepper driver(SW_RX, SW_TX, R_SENSE, DRIVER_ADDRESS);
using namespace TMC2208_n;
int32_t speed = 5000;
void setup() {
Serial.begin(115200); // Init serial port and set baudrate
while(!Serial); // Wait for serial port to connect
Serial.println("\nStart...");
// SERIAL_PORT.begin(57600);
//driver.beginSerial(57600);
driver.begin();
// Sets the slow decay time (off time) [1... 15]. This setting also limits
// the maximum chopper frequency. For operation with StealthChop,
// this parameter is not used, but it is required to enable the motor.
// In case of operation with StealthChop only, any setting is OK.
driver.toff(TOFF_VALUE);
// VACTUAL allows moving the motor by UART control.
// It gives the motor velocity in +-(2^23)-1 [μsteps / t]
// 0: Normal operation. Driver reacts to STEP input.
// /=0: Motor moves with the velocity given by VACTUAL.
// Step pulses can be monitored via INDEX output.
// The motor direction is controlled by the sign of VACTUAL.
driver.VACTUAL(speed);
// Comparator blank time. This time needs to safely cover the switching
// event and the duration of the ringing on the sense resistor. For most
// applications, a setting of 16 or 24 is good. For highly capacitive
// loads, a setting of 32 or 40 will be required.
driver.blank_time(24);
driver.rms_current(1000); // mA
driver.microsteps(16);
// Lower threshold velocity for switching on smart energy CoolStep and StallGuard to DIAG output
driver.TCOOLTHRS(0xFFFFF); // 20bit max
// CoolStep lower threshold [0... 15].
// If SG_RESULT goes below this threshold, CoolStep increases the current to both coils.
// 0: disable CoolStep
driver.semin(5);
// CoolStep upper threshold [0... 15].
// If SG is sampled equal to or above this threshold enough times,
// CoolStep decreases the current to both coils.
driver.semax(2);
// Sets the number of StallGuard2 readings above the upper threshold necessary
// for each current decrement of the motor current.
driver.sedn(0b01);
// StallGuard4 threshold [0... 255] level for stall detection. It compensates for
// motor specific characteristics and controls sensitivity. A higher value gives a higher
// sensitivity. A higher value makes StallGuard4 more sensitive and requires less torque to
// indicate a stall. The double of this value is compared to SG_RESULT.
// The stall output becomes active if SG_RESULT fall below this value.
driver.SGTHRS(STALL_VALUE);
Serial.print("\nTesting connection...");
uint8_t result = driver.test_connection();
if (result) {
Serial.println("failed!");
Serial.print("Likely cause: ");
switch(result) {
case 1: Serial.println("loose connection"); break;
case 2: Serial.println("no power"); break;
}
Serial.println("Fix the problem and reset board.");
// We need this delay or messages above don't get fully printed out
delay(100);
abort();
}
Serial.println("OK");
pinMode(DIAG_PIN, INPUT_PULLUP);
pinMode(EN_PIN, OUTPUT);
digitalWrite(EN_PIN, LOW);
}
void loop() {
static uint32_t last_time = 0;
uint32_t ms = millis();
while (Serial.available() > 0) {
int8_t read_byte = Serial.read();
if (read_byte == '0') {
Serial.print("Motor ");
if (driver.toff() == 0) {
Serial.print("already ");
}
Serial.println("disabled.");
driver.toff(0);
} else if (read_byte == '1') {
Serial.print("Motor ");
if (driver.toff() != 0) {
Serial.print("already ");
}
Serial.println("enabled.");
driver.toff(TOFF_VALUE);
} else if (read_byte == '+') {
speed += 1000;
if (speed == 0) {
Serial.println("Hold motor.");
} else {
Serial.println("Increase speed.");
}
driver.VACTUAL(speed);
} else if (read_byte == '-') {
speed -= 1000;
if (speed == 0) {
Serial.println("Hold motor.");
} else {
Serial.println("Decrease speed.");
}
driver.VACTUAL(speed);
}
}
if((ms-last_time) > 100 && driver.toff() != 0 && speed != 0) { // run every 0.1s
last_time = ms;
Serial.print("Status: ");
Serial.print(driver.SG_RESULT(), DEC);
Serial.print(" ");
Serial.print(digitalRead(DIAG_PIN)*150);
Serial.print(" ");
Serial.print((driver.SG_RESULT() < STALL_VALUE), DEC);
Serial.print(" ");
Serial.println(driver.cs2rms(driver.cs_actual()), DEC);
}
}
On Wednesday, May 11, 2022, 02:59:06 AM GMT+12, Pavel Vondricka wanthalf@users.sourceforge.net wrote:
I was also looking for where to put the CS value. There is no call tu irun() anywhere in the code anymore, and no other place to set the value either. (And I also got a low value of 4 for the 17NEMA PG27.) I also did not find any reason to set stepping to 4 instead of just 1: 5370 steps per revolution seems more than enough to me.
In addition, I have a problem with the StallGuard: It gets triggered ALWAYS when I press the PB_IN button, actually also when I try to quickly activate the "-1" movent several times in a row, and lately also quite often when I just trigger just ANY movement in the negative direction. (I am still testing with no load at all, and I tried to play with the threshold values. No improvement.)
TMC2209 firmware questions
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/arduinoascomfocuserpro2diy/discussion/general/
To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/
Hi
There is no call to irun() anywhere in the code
As the firmware 307 was developed further and the code improved, a lot of calls, including irun were found to not be needed for trimac steppers. Hence they were dropped from later firmware.
I attach the spreadsheets and pdf from those who developed/tested/modified the code associated with tmc2209 etc.
because some users struggled with stall guard (not all testers were successful) the fallback to using a Home Position switch was put into the code, as some found stall guard too time consuming to get it right.
I have attached also the archive of the trimac firmware starting at 307.
Please let me know if any of that helps. You will be able to compare each update to the previous and see the evolution of the code.
Regards
Robert
Hi Robert,
thanks for the files. I will try to have a look at them and find any differences or what all the SG versions mean. I am just afraid of a possible hardware problem in my wiring or something similar. It also does look like the signals at the DIAG pin are more complex than just pulling down in the case of stall.
Also, the question is what is the whole point of the Trinamic spreadsheets if the most important value (CS) cannot or should not be entered anywhere in the code anymore. Yes, there are a few other values, but according to my observations, those do not make any significant difference to anything: neither the calculation in the spreadsheet nor in the real usage.
I also have problem with the OLED_GRAPHIC mode: it always just shows "offline", because the ConnectionStatus never changes to "connected". I will also have a look at that - I suppose it might be an unfinished part of the code, right...?
It is sometimes a bit confusing that the documentation contains some inconsistencies or even contradictions. I know that such a complex project with many combinations cannot be easilly maintained by a single person. I wonder whether it might possibly help to move the documentation to some GIT repository as well (like the firmware) and track the changes. But maybe it is a problem as there is a lot of non-textual files.
Anyway, I am trying to add additional buttons for finer control of the focuser. I will publish the results if I come to some satisfactory results.
Best regards,
Pavel
sorry, what??
myFP2 does not have a graphics display or OLED_GRAPHIC mode.
Oh, I am in a wrong place, sorry! I am using the ESP32 version. Google search just lead me to this discussion related to TMC2209 in myFocuserPro, so I did not notice. Should I switch to the other discussion? Some existing thread or start a new one?
Last edit: wanthalf 2022-05-12
... and I got the meaning of the "offline" messsage. It's a feature, not a bug. Sorry for misunderstanding.