Testprogram for TMC2209-Library. Uses Speed-Control via VACTUAL instead of Step/Dir
Dependencies: TMCStepper mRotaryEncoder-os
Diff: main.cpp
- Revision:
- 1:60419aa0c030
- Parent:
- 0:3f4cfbeda9d3
- Child:
- 2:94c5b3f09463
--- a/main.cpp Thu Feb 04 19:46:56 2021 +0000
+++ b/main.cpp Thu Feb 04 21:35:45 2021 +0000
@@ -24,7 +24,7 @@
#define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2
#define R_SENSE 0.11f // Match to your driver
-#define MICROSTEPS 64
+#define MICROSTEPS 32
//RX, TX, RS, Addr
TMC2209Stepper stepper(p14, p13, R_SENSE, DRIVER_ADDRESS);
@@ -49,13 +49,16 @@
{
printf("\r\nConnected to mbed\r\n");
stepper.begin(); // UART: Init SW UART (if selected) with default baudrate
- stepper.toff(5); // Enables driver in software
- stepper.rms_current(600); // Set motor RMS current in mA
+ stepper.toff(3); // Enables driver in software - 3, 5 ????
+ stepper.rms_current(800); // Set motor RMS current in mA
+ // 1110, 800
stepper.microsteps(MICROSTEPS); // Set microsteps to 1:Fullstep ... 256: 1/256th
- stepper.en_spreadCycle(false); // Toggle spreadCycle on TMC2208/2209/2224
+ stepper.en_spreadCycle(true); // Toggle spreadCycle on TMC2208/2209/2224: default false, true: much faster!!!!
stepper.pwm_autoscale(true); // Needed for stealthChop
printf("TMC-Version: %02X\r\n",stepper.version());
+ bool shaft = false; //direction CW or CCW
+
while(1) {
// printf("TSTEP(): %i\r\n", stepper.TSTEP());
uint32_t status = stepper.DRV_STATUS();
@@ -65,29 +68,38 @@
// uint32_t otp = stepper.OTP_READ();
// printf("OTP_READ(): ");printBits(sizeof(otp),&otp);printf("\r\n");
-/* printf("VACTUAL(): %zu \r\n", stepper.VACTUAL());
+ printf("VACTUAL(): %zu \r\n", stepper.VACTUAL());
// increase
- int maxspeed = 1600;
- int actspeed = 0;
+ uint32_t maxspeed = 3000; //max 3400 or 3000
+ uint32_t actspeed = 0;
while (actspeed < maxspeed) {
actspeed += 200;
- printf("actspeed: %i",actspeed);
+ if (actspeed > maxspeed) {
+ actspeed = maxspeed;
+ }
+ //printf("actspeed: %i",actspeed);
stepper.VACTUAL(actspeed*MICROSTEPS);// Set Speed to value
- ThisThread::sleep_for(20ms); //wait
+ ThisThread::sleep_for(25ms); //wait
}
printf("VACTUAL(): %zu \r\n", stepper.VACTUAL());
- ThisThread::sleep_for(10s);
+ ThisThread::sleep_for(60s);
// decrease
maxspeed = 0;
while (actspeed > maxspeed) {
actspeed -= 200;
- printf("actspeed: %i",actspeed);
+ if (actspeed < 0) {
+ actspeed = 0;
+ }
+ //printf("actspeed: %i",actspeed);
stepper.VACTUAL(actspeed*MICROSTEPS);// Set Speed to value
- ThisThread::sleep_for(20ms); //wait
+ ThisThread::sleep_for(25ms); //wait
}
-*/
- stepper.VACTUAL(400*MICROSTEPS);// Set Speed to value
+
+// stepper.VACTUAL(400*MICROSTEPS);// Set Speed to value
ThisThread::sleep_for(5s); //wait
- printf("loop...\r\n");
+ // inverse direction
+ shaft = !shaft;
+ stepper.shaft(shaft);
+ printf("...\r\n");
}
}
\ No newline at end of file