SPI to configure A4992 Motor not working

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

 

I am trying to configure a motor control IC using SPI, but it seems to fail. I have a function that waits for the chip to acknowledge it changed to SPI mode but this always timeouts. This text below is from the datasheet saying how to enter serial mode. My code is supposed to follow that. Can anyone see my error?

 

I call MotorSerialInit, then WaitSerialChanged. STEP is set high before the call, then low after the Wait. It always times out in the first while loop.

 

The A4992 powers-up in the default step and direction control mode. The serial mode is only available following a specific sequence on the DIR and MS pins when STEP is high (see figure 3). The sequence starts when STEP is high and MS is held high and DIR is held low for longer than the Sequence Minimum Hold Time, tSSH . MS must then be held low and DIR high for longer than tSSH , followed by holding MS high and DIR low for longer than tSSH . The final step is to hold DIR high for tSSH , at which time the A4992 will enter the serial control mode. If STEP is taken low at any time during the sequence then the sequence is reset and the sequence of MS and DIR must be repeated. When the sequence is accepted by the A4992, the DIAG output will change state for the Serial Mode Acknowledge Pulse duration, tSAP , to indicate that the switch was successful. For example if a fault is present when switching between modes, DIAG will be low during the sequence and will first go high, to acknowledge the mode change, then go low after tSAP . If no fault is present DIAG will be high during the sequence and will first go low to acknowledge the mode change, then go high after tSAP . 

void MotorSerialInit() {
	// Initialize Serial Mode
	_delay_us(75);			// Initial delay for previous input changes
	digitalWrite(MS,HIGH);
	digitalWrite(DIR,LOW);
	_delay_us(75);			// Hold for tssh
	digitalWrite(MS,LOW);
	digitalWrite(DIR,HIGH);
	_delay_us(75);
	digitalWrite(MS,HIGH);
	digitalWrite(DIR,LOW);
	_delay_us(75);
	digitalWrite(DIR,HIGH);
	_delay_us(75);
}

/ Wait for diag pin to toggle to indicate changed to or from serial mode
void WaitSerialChanged(uint8_t motorNo, uint8_t faultState)
{
    int timeout = 1200; // Timeout value in us
    int timeoutFlag = 0;
    
    // Wait here until DIAG changes from initial state (or timeout occurs) NB: timeout timer depends on how long display writes take
    while (MotorDiagState(motorNo) == faultState && timeout>0) {
        timeout--;                                    // count down timer
        delayMicroseconds(1);
        if (timeout <1) timeoutFlag = 1;
    }
    timeout = 1200;                                // Reset timer
    // DIAG has been inverted, so wait here until it returns to original state
    while (MotorDiagState(motorNo) != faultState && timeout>0) {
        timeout--;
        delayMicroseconds(1);                                    // count down timer
        if (timeout <1) timeoutFlag = 2;
    }
}

 

Attachment(s): 

Last Edited: Thu. Oct 18, 2018 - 02:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RichMo wrote:
is held low for longer than the Sequence Minimum Hold Time, tSSH

Your timeouts in the init() look like they are longer then the min, but just barely, I did not see a max time so try extending the time a bit and see what happens...

Try 100us or even 200us

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Min is 921us, max is 1127us. I set my timeout to 1200, but have tried a range of higher and lower values. I wondered if I was perhaps misreading the sequence they describe.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

RichMo wrote:

Min is 921us, max is 1127us. I set my timeout to 1200, but have tried a range of higher and lower values. I wondered if I was perhaps misreading the sequence they describe.

 

The 75us is "Sequence minimum hold time" which is specified as 58 to 72 us. I have tried higher and lower values for this too

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your sequence looks right to me, you may have to contact the support rep for example init code.

I don't see anything online, usually if you google "arduino" + whatever chip, you will find something, but not this time.

I guess your on the bleeding edge with this one.

 

Jim

 

Click Link: Get Free Stock: Retire early!

share.robinhood.com/jamesc3274