Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Scott Beasley - 2020
- This is a test program for the cheap knockoff TB67S109AFTG
- stepper driver boards that pose as TB6600 drivers. These drivers
- have an issue with losing or gaining steps. The ones I have tested
- have step issues whilst changing direction. The move following the
- direction change will lose/gain steps. I have noticed as well that
- the pulse delay needs to change as the current is set to a higher
- selection on the driver. The driver also will only output no more
- than 1.2amps per my testing. Your mileage may vary.
- UPDATE:
- The issue may be with the ENA function of the chip being slow to change
- state. If I enable the driver and leave it that way, no steps seem to be
- lost.
- */
- // Direct io macros.
- #define SET_BIT(p,n) ((p) |= (1 << (n)))
- #define CLR_BIT(p,n) ((p) &= (~(1) << (n)))
- #define TOGGLE_BIT(p,n) ((p) ^= ((1) << (n)))
- // Arduino pins
- #define STEPPIN 12 // Connected to the PUL + on driver
- #define DIRPIN 6 // Connected to the DIR + on the driver
- #define ENAPIN 10 // Connected to the ENA + on the driver
- // DIR -, PUL - and ENA - are connected to the Arduino GND
- // 328p ports
- #define STEP_OUT PB4
- #define DIR_OUT PD6
- #define ENA_OUT PB2
- // Globals
- //const int PULSEDELAY = 750; // Delay for 0.5-0.7a
- const int PULSEDELAY = 850; // Delay for 1-1.2a
- //const int PULSEDELAY = 450; // Pulse delay for current setting of 1.5-1.7a
- void setup() {
- // put your setup code here, to run once:
- pinMode(STEPPIN,OUTPUT);
- pinMode(DIRPIN,OUTPUT);
- pinMode(ENAPIN,OUTPUT);
- SET_BIT (PORTB, ENA_OUT);
- }
- void loop() {
- forward(200);
- delay(500);
- forward(200);
- delay(500);
- TOGGLE_BIT (PORTD, DIR_OUT); //SET DIRECTION
- reverse(400);
- delay(1000);
- TOGGLE_BIT (PORTD, DIR_OUT); //REVERSE DIRECTION
- }
- void pulse (void) {
- SET_BIT (PORTB, STEP_OUT);
- delayMicroseconds(PULSEDELAY);
- CLR_BIT (PORTB, STEP_OUT);
- delayMicroseconds(PULSEDELAY);
- }
- void forward(int steps){
- for(int i=0;i<steps;i++){
- pulse ();
- }
- }
- void reverse(int steps){
- for(int i=0;i<steps;i++){
- pulse ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment