cancel
Showing results for 
Search instead for 
Did you mean: 

L9942 Driver IC SPI Programming

siva2
Associate II
Posted on April 01, 2015 at 12:58

Dear Experts,

I am new to L9942 Driver IC.

I am currently working on this IC for a stepper motor control in automotive safety application.

I have attached a 'c' program written for SPI communication with L9942. The controller which I am using is a 8 bit controller. The following are the other details:

  • Controller: PIC 16F877A
  • SPI is used in 8 bit mode (only 8 bit is possible)
  • Mode 0 of SPI communication is used
  • Baud rate for communication is 3Mhz (doubtful about this)
  • The 16 bit register values of L9942 are initialized in two 8bit integer variables
  • Later these variables (two 8bit variables) are sent one after the other keeping the CSN low consecutively. The same is followed for all 8 registers.
The sequence of the program goes like this for programming all 8 registers.

  1. Keep CSN High initially
  2. Pull CSN to Low
  3. Transfer the first 8bit (MSB first) 
  4. Transfer the second 8bit (MSB first)
  5. Push CSN to High
The following are not understood:

  • Sometimes the output voltage waveform (the output to the motors) is smooth and the motor runs properly, but sometimes there is no response from motor and also at times the waveform is irregular.
  • At times when the STEP frequency is increased or decreased the motor starts moving. 
  • Is the SPI communication improper?
  • Can an 8bit Controller properly communicate with L9942 with 8bit SPI mode?
  • What should be the baud rate of communication?
  • I have an understanding that, if once all the 8 register values are loaded, L9942 will take care of driving the motor with a proper STEP input.. is it correct?
  • I have an understanding that, only the first register has to be reloaded when the direction has to be changed, keeping the program counter bits to 0... is it correct?
  • There are 8 bits for Stall threshold setting (D0 to D7). As per the datasheet the interval is 16us. So can it only have 2^8=256, therefore 255X16us which = 4080us. So is 4080us the maximum threshold time that can be set?
  • When does Stall bit set? In my case I am using a Linear actuator. So when it reaches end of position in linear limit, the motor still tries to move but the linear slider does not move. Will this set the stall bit?

Please refer to my attached c program also and help me out.

Regards,

M.Siva

#spi #spi #l9942 #l9942
6 REPLIES 6
Brugus
ST Employee
Posted on April 02, 2015 at 18:30

Dear M.Siva,

A 8-bit microcontroller can drive SPI if it is programmed properly. Check if the CS, CLK, DO and DI are driven properly.

About SPI communication timing in the datasheet are reported information about the timing and levels. A logic analyzer can help you to identify if the communication is managed properly.

Did you program the current profile table?

To set the rotation direction you have to change bit-0 in Register 0

I suggest to check these signals: Motor stepping clock input (STEP) and PWM output (PWM).

Best regars.

Marco.

From: murugesan.siva

Posted: Wednesday, April 01, 2015 1:01 PM

Subject: L9942 Driver IC SPI Programming

Dear Experts,

I am new to L9942 Driver IC.

I am currently working on this IC for a stepper motor control in automotive safety application.

I have attached a 'c' program written for SPI communication with L9942. The controller which I am using is a 8 bit controller. The following are the other details:

  • Controller: PIC 16F877A
  • SPI is used in 8 bit mode (only 8 bit is possible)
  • Mode 0 of SPI communication is used
  • Baud rate for communication is 3Mhz (doubtful about this)
  • The 16 bit register values of L9942 are initialized in two 8bit integer variables
  • Later these variables (two 8bit variables) are sent one after the other keeping the CSN low consecutively. The same is followed for all 8 registers.
The sequence of the program goes like this for programming all 8 registers.

  1. Keep CSN High initially
  2. Pull CSN to Low
  3. Transfer the first 8bit (MSB first) 
  4. Transfer the second 8bit (MSB first)
  5. Push CSN to High
The following are not understood:

  • Sometimes the output voltage waveform (the output to the motors) is smooth and the motor runs properly, but sometimes there is no response from motor and also at times the waveform is irregular.
  • At times when the STEP frequency is increased or decreased the motor starts moving. 
  • Is the SPI communication improper?
  • Can an 8bit Controller properly communicate with L9942 with 8bit SPI mode?
  • What should be the baud rate of communication?
  • I have an understanding that, if once all the 8 register values are loaded, L9942 will take care of driving the motor with a proper STEP input.. is it correct?
  • I have an understanding that, only the first register has to be reloaded when the direction has to be changed, keeping the program counter bits to 0... is it correct?
  • There are 8 bits for Stall threshold setting (D0 to D7). As per the datasheet the interval is 16us. So can it only have 2^8=256, therefore 255X16us which = 4080us. So is 4080us the maximum threshold time that can be set?
  • When does Stall bit set? In my case I am using a Linear actuator. So when it reaches end of position in linear limit, the motor still tries to move but the linear slider does not move. Will this set the stall bit?

Please refer to my attached c program also and help me out.

Regards,

M.Siva
siva2
Associate II
Posted on April 08, 2015 at 16:58

Very thankful for your grateful reply.

  • Currently the stepper motor is trying to move backward and moves forward.
  • No response for the change in direction input at register 0, at times it moves forward and at times it moves backward for the same direction input at register 0.
  • Also I have programmed all the current profile values in the registers respectively, please have a look at my register initialization
0b 000 0000010011001 //register 0

0b 001 1000000000000 //register 1

0b 010 0011000000010 //register 2

0b 011 1000100001100 //register 3

0b 100 1101000010110 //register 4

0b 101 1111000011101 //register 5

0b 110 0000000011111 //register 6

0b 111 0000000000000 //register 7

  • Also what is the proper way to stop the motor at a position? Either to turn OFF PWM input (anyhow current stays in the coil) or turn OFF Enable? 
  • What is the use of fault bit which is received at DO from L9942 IC?
  • I have not programmed threshold time for stall, is this a reason for such behavior of motor?  What unit does the D0 to D7 threshold value take- us or ms or s? 
Please do help me in all my clarifications.

Thanks in advance.

Regards,

M.Siva

Brugus
ST Employee
Posted on April 10, 2015 at 11:15

Dear Mr M.Siva,

The problem could be due tho the SPI communication.

Did you check the SPI signals by using an analyzer? Are the signals and the register values as you programmed?

About the 16bit SPI code by using the same microcontroller you are using, examples and suggestions are collected at this link https://www.ccsinfo.com/forum/viewtopic.php?p=195676

Best regards,

Marco Brugora

siva2
Associate II
Posted on April 10, 2015 at 11:34

Thank You Sir....

Actually I had initiated the same discussion in that forum... 🙂

Now SPI is working fine and the motor is rotating fine 🙂

But please clarify the following:

  1. The use of fault bit from DO
  2. What is the unit of time us or ms of s for programming the STALL threshold in the 4th and 5th register?
  3. Should we initialize the register twice to get the return value from DO of L9942?
  4. When the baud rate goes beyond 1000, the SPI communication is done properly but, the motor spinning is not smooth.
  5. When the STEP frequency goes beyond 500Hz, the motor is not spinning in Full-step mode, but it does with Micro-stepping
Thanks & Regards,

M.Siva

Brugus
ST Employee
Posted on April 14, 2015 at 11:09

Dear Mr. M.Siva.

  1. D0 fault bit: The first three bits of an SPI write frame are the register address. Thus, during this time, it is not clear which register has to be written and read. This time is used at the DO-pin to monitor the or-function of all diagnostic functions. DO-pin will report an internal error flag of the device and it is the the  logical OR of all status bits in the Status Registers (6 and 7).

    The microcontroller can poll the status of

    the device without the need of a full SPI-communication cycle. Check also AN2650 paragraph 3.1.
  2. STALL threshold: please check in the datasheet the paragraph 5.8.3, 7.1 and the table in top of  figure 15. Check the AN2650 chapter 5.
  3. Check paragraph 5.8.2 in the datasheet.
  4. check the waveforms of the signals: PWM output and Step clock input.

Best regards,

Marco Brugora.

siva2
Associate II
Posted on April 16, 2015 at 13:16

Dear Sir,

Thank You for your great support.

  1. Tried to set STALL threshold using the AN2650 procedure, when the STALL threshold value is 00000000 STALL is not set, but when the value is 00000001 the STALL is set. For just a time period of 16us the stall is set.  The frequency of STEP input was 400 HZ and Full-Stepping mode was used. So, is there any other parameter which has to be taken care for proper stall threshold?
  2. Does stall threshold value setting should also consider the STEP input frequency?
  3. For change in STEP input frequency, the motor is not smooth and stops rotating. What is the reason for this? For Full-stepping, the motor is smooth only from 380 to 420 Hz and Micro-stepping does only when there is more than 1 KHz. When referred to the datasheet for STEP input details, only the minimum time period required is given. Is there anything else which should be taken care of?
  4. What is the proper way to stop the motor? Is disabling the EN (Enable Input) is the only way?
Thanks in advance

Regards,

M.Siva