Post Go back to editing

XACTUAL only increments

Category: Hardware
Product Number: TMC4361A

I am using a TMC4361A for a new design and after resetting XACTUAL to a predetermined amount, I need to read via SPI to know location. I've noticed XACTUAL increments in both directions. Is it possible (or is there another register) that increments in one direction and decrements in the other?

Parents
  • Hi, 

    XACTUAL counts up in right direction (positive velocity) and counts down in left direction. Please be sure to interprete the number as a 2's complement signed integer. 

  • BTW, just looked at your background. Pretty impressive. I love this chip.

  • Thank you :-)

    I guess, that then probably not the counting is wrong, but motion command is just in one direction. BTW, normally, you would not change XACTUAL, except for a single time, when homing. You then instead would modify XTARGET and command the motion controller to move to it. When changing XACTUAL, motion would try to move to XTARGET again.

  • I made a little progress and learned a few things. I did write a small test program and realized XACTUAL does increment and decrement in forward and worse for target mode. Where I'm having the issue is in velocity mode. Does velocity increment and decrement depending on direction? In case it matters, I'm using a TMC4361A-BOB. I've include code snippets for my test program as well as the output.

    For some reason, I can insert the .h files and output files but not the .c files.

    #include <gtk/gtk.h>
    #include <stdio.h>
    #include <wiringPi.h>
    #include <stdlib.h>
    #include "bcm2835.h"
    #include <linux/i2c-dev.h>
    #include <i2c/smbus.h>
    #include <fcntl.h>
    #include <sys/ioctl.h>
    #include <unistd.h>
    #include <linux/i2c.h>
    #include <signal.h>
    #include "tmc4361spi.h"
    //#include "SPI_TMC.h"
    #include <stdint.h>
    #include <sys/stat.h>
    #include <sys/types.h>
    #include <linux/spi/spidev.h>
    #include <pigpiod_if2.h>
    #include "TMC-API/tmc/ic/TMC4361A/TMC4361A_Register.h"
    #include "TMC-API/tmc/ic/TMC4361A/TMC4361A.h"
    #include "TMC-API/tmc/helpers/API_Header.h"
    //#include "Mcp23017.h"
    
    #define PRIMARY_CLOCK_SPEED   (4800000)
    
    #define OK                    (1)
    
    #define MOTOR0			         (0) // Motor 0
    #define CW                    (0)
    #define VELOCITY              (0)
    #define FORWARD               (1)
    #define REVERSE               (0)
    
    #define MOTION_ENABLE         (1)
    
    #define RESET_GPIO_PIN 17
    
    #define STOP                  (0)
    
    static int spiFdY = -1; // Standard Linux SPI file descriptor
    
    float yCommandedPos;
    
    gboolean yTrajectory;
    
    uint8_t buffer[2];                              // Initialize a buffer for two bytes to write to the device
    
    void resetMotorDrivers();
    
    void signal_callback_handler(int signum);

    #include "TMC-API/tmc/ic/TMC4361A/TMC4361A_Register.h"
    #include "TMC-API/tmc/ic/TMC4361A/TMC4361A.h"
    #include "TMC-API/tmc/helpers/API_Header.h"
    #include <stdint.h>
    
    static float yAxisPos = 0.0;
    
    void tmc4361A_writeDatagram(int fileD, uint8 address, uint8 x1, uint8 x2, uint8 x3, uint8 x4);
    void tmc4361A_writeInt(int fileD, uint8 address, int value);
    int tmc4361A_readInt(int fileD, uint8 address);
    unsigned char tmc4361A_cover(int fileD, unsigned char data, unsigned char lastTransfer);
    void tmc40bit_writeInt(int fileD, uint8 address, int value);
    int tmc40bit_readInt(int fileD, uint8 address);
    
    int tmc4361A_init(const char *spiDevice);
    int tmc4366A_initiailze(int fileD, const char *displayName);
    void tmc4361A_load_position(int fileD, int position);
    int tmc4361A_read_position(int fileD);
    
    void tmc4361A_targ(int fileD, 
                       int targ, 
                       int vel,
                       int aMax,
                       int dMax, 
                       int bow1, 
                       int bow2, 
                       int bow3, 
                       int bow4);
                       
    void tmc4361A_vel(int fileD,  
                      int vel,
                      uint8_t dir,
                      int aMax,
                      int dMax, 
                      int bow1, 
                      int bow2, 
                      int bow3, 
                      int bow4);
                      
    void tmc4361A_close(int fileD);
    

    Resetting
    Smoketest passed for TMC-Y
    trgt=1000,vel=2,aMax=100,dMax=100,bow1=200,bow2=200,bow3=200,bow4=200
    Actual position = 1000
    Forward position = 1000
    Actual position = 1
    Forward position = 1
    Actual position = 53
    Forward position = 53
    Actual position = 106
    Forward position = 106
    Actual position = 158
    Forward position = 158
    Actual position = 210
    Forward position = 210
    Actual position = 262
    Forward position = 262
    Actual position = 314
    Forward position = 314
    Actual position = 366
    Forward position = 366
    Actual position = 418
    Forward position = 418
    Actual position = 470
    Forward position = 470
    Actual position = 522
    Forward position = 522
    Actual position = 574
    Forward position = 574
    Actual position = 626
    Forward position = 626
    Actual position = 678
    Forward position = 678
    Actual position = 730
    Forward position = 730
    Actual position = 782
    Forward position = 782
    Actual position = 835
    Forward position = 835
    Actual position = 887
    Forward position = 887
    Actual position = 939
    Forward position = 939
    Actual position = 991
    Forward position = 991
    Actual position = 1000
    Forward position = 1000
    Actual position = 1000
    Forward position = 1000
    Actual position = 1000
    Forward position = 1000
    Actual position = 1000
    Forward position = 1000
    trgt=100,vel=2,aMax=100,dMax=100,bow1=200,bow2=200,bow3=200,bow4=200
    Actual position = 100
    Reverse position = 100
    Actual position = 999
    Reverse position = 999
    Actual position = 947
    Reverse position = 947
    Actual position = 894
    Reverse position = 894
    Actual position = 842
    Reverse position = 842
    Actual position = 790
    Reverse position = 790
    Actual position = 738
    Reverse position = 738
    Actual position = 686
    Reverse position = 686
    Actual position = 634
    Reverse position = 634
    Actual position = 582
    Reverse position = 582
    Actual position = 530
    Reverse position = 530
    Actual position = 478
    Reverse position = 478
    Actual position = 426
    Reverse position = 426
    Actual position = 374
    Reverse position = 374
    Actual position = 322
    Reverse position = 322
    Actual position = 270
    Reverse position = 270
    Actual position = 218
    Reverse position = 218
    Actual position = 166
    Reverse position = 166
    Actual position = 113
    Reverse position = 113
    Actual position = 100
    Reverse position = 100
    Actual position = 100
    Reverse position = 100
    Actual position = 100
    Reverse position = 100
    Actual position = 100
    Reverse position = 100
    Actual position = 100
    Reverse position = 100
    Actual position = 100
    Reverse position = 100
     at the end 
    Stopping motors
    Closing SPI devices
    Closing pigpio
    

    vel=10,dir=1,aMax=100,dMax=100,bow1=200,bow2=200,bow3=200,bow4=200Actual position = 0
    Forward position = 0
    Actual position = 0
    Forward position = 0
    Actual position = 99
    Forward position = 99
    Actual position = 343
    Forward position = 343
    Actual position = 603
    Forward position = 603
    Actual position = 864
    Forward position = 864
    Actual position = 1124
    Forward position = 1124
    Actual position = 1384
    Forward position = 1384
    Actual position = 1645
    Forward position = 1645
    Actual position = 1905
    Forward position = 1905
    Actual position = 2165
    Forward position = 2165
    Actual position = 2425
    Forward position = 2425
    Actual position = 2686
    Forward position = 2686
    Actual position = 2946
    Forward position = 2946
    Actual position = 3206
    Forward position = 3206
    Actual position = 3467
    Forward position = 3467
    Actual position = 3727
    Forward position = 3727
    Actual position = 3987
    Forward position = 3987
    Actual position = 4247
    Forward position = 4247
    Actual position = 4508
    Forward position = 4508
    Actual position = 4768
    Forward position = 4768
    Actual position = 5028
    Forward position = 5028
    Actual position = 5288
    Forward position = 5288
    Actual position = 5549
    Forward position = 5549
    Actual position = 5809
    Forward position = 5809
    vel=0,dir=1,aMax=100,dMax=100,bow1=200,bow2=200,bow3=200,bow4=200vel=10,dir=0,aMax=100,dMax=100,bow1=200,bow2=200,bow3=200,bow4=200Actual position = 0
    Reverse position = 0
    Actual position = 6581
    Reverse position = 6581
    Actual position = 6680
    Reverse position = 6680
    Actual position = 6923
    Reverse position = 6923
    Actual position = 7184
    Reverse position = 7184
    Actual position = 7444
    Reverse position = 7444
    Actual position = 7704
    Reverse position = 7704
    Actual position = 7964
    Reverse position = 7964
    Actual position = 8225
    Reverse position = 8225
    Actual position = 8485
    Reverse position = 8485
    Actual position = 8745
    Reverse position = 8745
    Actual position = 9006
    Reverse position = 9006
    Actual position = 9266
    Reverse position = 9266
    Actual position = 9526
    Reverse position = 9526
    Actual position = 9786
    Reverse position = 9786
    Actual position = 10047
    Reverse position = 10047
    Actual position = 10307
    Reverse position = 10307
    Actual position = 10567
    Reverse position = 10567
    Actual position = 10827
    Reverse position = 10827
    Actual position = 11089
    Reverse position = 11089
    Actual position = 11350
    Reverse position = 11350
    Actual position = 11611
    Reverse position = 11611
    Actual position = 11871
    Reverse position = 11871
    Actual position = 12132
    Reverse position = 12132
    Actual position = 12393
    Reverse position = 12393
    vel=0,dir=0,aMax=100,dMax=100,bow1=200,bow2=200,bow3=200,bow4=200 at the end 
    Stopping motors
    Closing SPI devices
    Closing pigpio
    

  • It also appears that XACTUAL returns the target position or velocity on hte first read.

  • Good to hear that you made progress! If you see XACTUAL only counting up, I guess that you did not yet successfully start velocity mode in negative direction. Please be sure to set a negative velocity for VMAX to move in negative direction. Inverting direction using the polarity flag is only for adaptation purpose.

  • If you see different response with read access to the same register, probably the read procedure misses the dummy read required to transfer the register address, first. The read access is pipelined: The next read access reads data from the previously transmitted address.

Reply Children
No Data