Testprogram for TMC2209-Library. Uses Speed-Control via VACTUAL instead of Step/Dir
Dependencies: TMCStepper mRotaryEncoder-os
Diff: main.cpp
- Revision:
- 6:6ad7bc10ac20
- Parent:
- 5:7f250f463aa2
- Child:
- 7:51cb60bf3e2d
--- a/main.cpp Sun Mar 21 13:31:53 2021 +0000
+++ b/main.cpp Mon Mar 22 17:46:39 2021 +0000
@@ -37,9 +37,12 @@
//RX, TX, RS, Addr
TMC2209Stepper stepper(p14, p13, R_SENSE, DRIVER_ADDRESS);
+InterruptIn diag(p21);
+
volatile bool enc_pressed = false; // Button of rotaryencoder was pressed
volatile bool enc_rotated = false; // rotary encoder was totaded left or right
volatile bool enc_action = false; // any change happened
+volatile bool diag_event = false; // DIAG-Pin of TMC
int lastGet;
int thisGet;
@@ -53,6 +56,11 @@
enc_rotated = true; // just set the flag, rest is done outside isr
}
+//interrup-Handler for TMC2209-DIAG-Pin
+void trigger_diag() {
+ diag_event = true; // just set the flag, rest is done outside isr
+}
+
// Assumes little endian
void printBits(size_t const size, void const * const ptr)
{
@@ -79,11 +87,13 @@
// call trigger_rot() when the shaft is rotaded left or right
wheel.attachROT(&trigger_rotated);
lastGet = 0;
- // set encrotated, so startup
+ // set enc_rotated, so startup
enc_rotated = true;
enc_action = true;
ledCW = 1;
ledCCW = 1;
+
+ diag.rise(&trigger_diag);
// Initialize Stepper
printf("connecting to TMC-Module...\r\n");
@@ -98,9 +108,15 @@
stepper.en_spreadCycle(true); // Toggle spreadCycle on TMC2208/2209/2224: default false, true: much faster!!!!
stepper.pwm_autoscale(true); // Needed for stealthChop
+ uint8_t gstat = stepper.GSTAT();
+ printf("GSTAT(): "); printBits(sizeof(gstat),&gstat);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");
+
//bool shaft = false; //direction CW or CCW
while(1) {
@@ -151,6 +167,26 @@
*/
////// Control motor-speed by rotary-encoder
+ // DIAG-PIN showed Error-Condition?
+ if (diag_event) {
+ diag_event = false;
+ printf("DIAG occured!\r\n");
+ gstat = stepper.GSTAT();
+ printf("GSTAT(): "); printBits(sizeof(gstat),&gstat);printf("\r\n");
+ status = stepper.DRV_STATUS();
+ printf("DRV_STATUS(): "); printBits(sizeof(status),&status);printf("\r\n");
+ //safty turn off friver
+ printf("Shutting Down Motordriver...\r\n");
+ 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");
+ printf("stopping programm - manual RESET required!!!!!!\r\n");
+ while (1) {};
+
+ }
+
// shaft has been rotated?
if (enc_rotated) {
enc_rotated = false;