Testprogram for TMC2209-Library. Uses Speed-Control via VACTUAL instead of Step/Dir
Dependencies: TMCStepper mRotaryEncoder-os
Diff: main.cpp
- Revision:
- 8:f44d70665051
- Parent:
- 7:51cb60bf3e2d
- Child:
- 9:babbfb61d347
--- a/main.cpp Mon Mar 22 21:38:03 2021 +0000
+++ b/main.cpp Thu Apr 22 18:11:49 2021 +0000
@@ -12,7 +12,7 @@
*/
-DigitalOut ledCW(LED1); // Show totation clockwise
+DigitalOut ledCW(LED1); // Show rotation clockwise
DigitalOut ledCCW(LED2); // Show rotation counterclockwise
//Virtual serial port over USB with 15200 baud 8N1
@@ -29,15 +29,16 @@
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f // R-Sense in OHM. Match to your driver
-#define MICROSTEPS 128 // # of microsteps
-#define RMSCURRENT 800 // RMS current of Stepper Coil in mA
-#define MAXSPEED 5000 // Maximaum speed (5000 with RMS800 @12V/06Amax)
+#define MICROSTEPS 256 // # of microsteps
+#define RMSCURRENT 1000 // RMS current of Stepper Coil in mA
+#define MAXSPEED 5000 // Maximaum speed (5000 with RMS800 @12V/0.6Amax)
// A TMCStepper-object with UART and given address and R-Sense
//RX, TX, RS, Addr
TMC2209Stepper stepper(p14, p13, R_SENSE, DRIVER_ADDRESS);
InterruptIn diag(p21);
+DigitalOut enn(p22);
volatile bool enc_pressed = false; // Button of rotaryencoder was pressed
volatile bool enc_rotated = false; // rotary encoder was totaded left or right
@@ -93,6 +94,8 @@
ledCW = 1;
ledCCW = 1;
+ // disable Driver
+ enn=1;
// Initialize Stepper
printf("connecting to TMC-Module...\r\n");
@@ -109,15 +112,44 @@
stepper.en_spreadCycle(true); // Toggle spreadCycle on TMC2208/2209/2224: default false, true: much faster!!!!
stepper.pwm_autoscale(true); // Needed for stealthChop
+ // enable driver
+ enn = 0;
+
uint8_t gstat = stepper.GSTAT();
printf("GSTAT(): "); printBits(sizeof(gstat),&gstat);printf("\r\n");
+ uint32_t gconf = stepper.GCONF();
+ printf("GCONF(): "); printBits(sizeof(gconf),&gconf);printf("\r\n");
+
uint32_t status = stepper.DRV_STATUS();
printf("DRV_STATUS(): "); printBits(sizeof(status),&status);printf("\r\n");
uint32_t ioin = stepper.IOIN();
printf("IOIN(): "); printBits(sizeof(ioin),&ioin);printf("\r\n");
+ uint8_t ihold = stepper.ihold();
+ printf("IHOLD(): "); printBits(sizeof(ihold),&ihold);printf("\r\n");
+
+ uint8_t irun = stepper.irun();
+ printf("IRUN(): "); printBits(sizeof(irun),&irun);printf("\r\n");
+
+ uint8_t iholddelay = stepper.iholddelay();
+ printf("IHOLDDELAY(): "); printBits(sizeof(iholddelay),&iholddelay);printf("\r\n");
+
+ // do a peep by setting vactual to a too high speed
+
+ stepper.VACTUAL(50000*MICROSTEPS);
+ ThisThread::sleep_for(1s);
+
+ // initialize Automatic tunig (Chap 6.1)
+ stepper.VACTUAL(1);
+ stepper.VACTUAL(0);
+ ThisThread::sleep_for(100ms);
+ stepper.VACTUAL(500*MICROSTEPS);
+ ThisThread::sleep_for(2s);
+ stepper.VACTUAL(0);
+
+
diag.rise(&trigger_diag);
//bool shaft = false; //direction CW or CCW
@@ -180,13 +212,27 @@
printf("DRV_STATUS(): "); printBits(sizeof(status),&status);printf("\r\n");
//safty turn off friver
printf("Shutting Down Motordriver...\r\n");
+ enn=1;
stepper.toff(0);
status = stepper.DRV_STATUS();
printf("DRV_STATUS(): "); printBits(sizeof(status),&status);printf("\r\n");
ioin = stepper.IOIN();
printf("IOIN(): "); printBits(sizeof(ioin),&ioin);printf("\r\n");
+ ihold = stepper.ihold();
+ printf("IHOLD(): "); printBits(sizeof(ihold),&ihold);printf("\r\n");
+ irun = stepper.irun();
+ printf("IRUN(): "); printBits(sizeof(irun),&irun);printf("\r\n");
+ iholddelay = stepper.iholddelay();
+ printf("IHOLDDELAY(): "); printBits(sizeof(iholddelay),&iholddelay);printf("\r\n");
printf("stopping programm - manual RESET required!!!!!!\r\n");
- while (1) {};
+ while (1) {
+ ledCW = 1;
+ ledCCW = 1;
+ ThisThread::sleep_for(200ms);
+ ledCW = 0;
+ ledCCW = 0;
+ ThisThread::sleep_for(200ms);
+ };
}
@@ -218,10 +264,18 @@
gstat = stepper.GSTAT();
printf("GSTAT(): "); printBits(sizeof(gstat),&gstat);printf("\r\n");
+ gconf = stepper.GCONF();
+ printf("GCONF(): "); printBits(sizeof(gconf),&gconf);printf("\r\n");
status = stepper.DRV_STATUS();
printf("DRV_STATUS(): "); printBits(sizeof(status),&status);printf("\r\n");
ioin = stepper.IOIN();
printf("IOIN(): "); printBits(sizeof(ioin),&ioin);printf("\r\n");
+ ihold = stepper.ihold();
+ printf("IHOLD(): "); printBits(sizeof(ihold),&ihold);printf("\r\n");
+ irun = stepper.irun();
+ printf("IRUN(): "); printBits(sizeof(irun),&irun);printf("\r\n");
+ iholddelay = stepper.iholddelay();
+ printf("IHOLDDELAY(): "); printBits(sizeof(iholddelay),&iholddelay);printf("\r\n");
}
// anything changed?