![](/media/cache/profiles/15ae3b9d6286f1b2a489ea4f3f4abaed.50x50_q85.jpg)
Testprogram for TMC2209-Library. Uses Speed-Control via VACTUAL instead of Step/Dir
Dependencies: TMCStepper mRotaryEncoder-os
Diff: main.cpp
- Revision:
- 2:94c5b3f09463
- Parent:
- 1:60419aa0c030
- Child:
- 3:209a9c414f54
--- a/main.cpp Thu Feb 04 21:35:45 2021 +0000 +++ b/main.cpp Sat Feb 06 20:00:31 2021 +0000 @@ -1,31 +1,32 @@ -/* mbed Microcontroller Library - * Copyright (c) 2019 ARM Limited - * SPDX-License-Identifier: Apache-2.0 - */ - #include "mbed.h" #include "platform/mbed_thread.h" +#include "TMCStepper.h" + +/* + Testprogram for TMCStepper-Library + TMCStepper based on https://github.com/teemuatlut/TMCStepper for Arduino + by https://github.com/teemuatlut + +++++ + Tested with https://github.com/bigtreetech/BIGTREETECH-TMC2209-V1.2 +*/ DigitalOut ledDir(LED2); //Virtual serial port over USB with 15200 baud 8N1 static BufferedSerial host(USBTX, USBRX,115200); - -// apply number of steps, direction, speed and -// a linear acceleration/deceleration to a Stepper Motor Controller - -#include "TMCStepper.h" - +// hardware parameters: // MOTOR Steps per Revolution ( 1/8 Microsteps, 200Steps per Rev / 1.8 degrees per FullStep) #define MSPR 1600 // Gear Ratio #define GR 288 #define DRIVER_ADDRESS 0b00 // TMC2209 Driver address according to MS1 and MS2 -#define R_SENSE 0.11f // Match to your driver -#define MICROSTEPS 32 +#define R_SENSE 0.11f // R-Sense in OHM .Match to your driver +#define MICROSTEPS 128 // # of microsteps +#define RMSCURRENT 500 // RMS current of Stepper Coil in mA +// A TMCStepper-object with UART and given address and R-Sense //RX, TX, RS, Addr TMC2209Stepper stepper(p14, p13, R_SENSE, DRIVER_ADDRESS); @@ -48,9 +49,9 @@ int main() { printf("\r\nConnected to mbed\r\n"); - stepper.begin(); // UART: Init SW UART (if selected) with default baudrate - stepper.toff(3); // Enables driver in software - 3, 5 ???? - stepper.rms_current(800); // Set motor RMS current in mA + stepper.begin(); // UART: Init SW UART (if selected) with default baudrate + stepper.toff(3); // Enables driver in software - 3, 5 ???? + stepper.rms_current(RMSCURRENT); // Set motor RMS current in mA / min 500 for 24V/speed:3000 // 1110, 800 stepper.microsteps(MICROSTEPS); // Set microsteps to 1:Fullstep ... 256: 1/256th stepper.en_spreadCycle(true); // Toggle spreadCycle on TMC2208/2209/2224: default false, true: much faster!!!! @@ -100,6 +101,8 @@ // inverse direction shaft = !shaft; stepper.shaft(shaft); + // Read Interace-Count + printf("IFCNT(): %zu \r\n",stepper.IFCNT()); printf("...\r\n"); } } \ No newline at end of file