Kart/stepper motor controller

(Difference between revisions)
Jump to: navigation, search
(Hardware)
(Tests)
(10 intermediate revisions by one user not shown)
Line 1: Line 1:
 
{{TOC right}}
 
{{TOC right}}
  
The [[Kart|kart's]] stepper motor controller FPGA generates 4 coil driving signals and receives a ''stepper end'' input.
+
The [[Kart|kart's]] stepper motor controller module generates 4 coil driving signals and receives a ''stepper end'' input.
  
[[File:Kart stepper board.jpg|center|200px|stepper motor board]]
+
[[File:Kart_stepper_module.jpg|center|1400px|stepper motor module]]
  
 
== Stepper motor ==
 
== Stepper motor ==
Line 9: Line 9:
 
=== Hardware ===
 
=== Hardware ===
  
The stepper motor is a [http://en.nanotec.com/ Nanotec]
+
The '''stepper motor''' is a [[Media:SP3575M0906-A.pdf|Nanotec SP3575M0906-A]].
[[Media:SP3575M0906-A.pdf|SP3575M0906-A]].
+
  
 
It has a step angle of 7.5°, and as such 48 steps per turn.
 
It has a step angle of 7.5°, and as such 48 steps per turn.
 
It is attached to a 100:1 reductor, which leads to an output axis with 4800 steps per turn.
 
It is attached to a 100:1 reductor, which leads to an output axis with 4800 steps per turn.
  
The [[Media:Kart stepper motor board.pdf|control board]] hosts a current source
+
The [[Media:Kart_dc_stepper_schematic.pdf|DC/stepper control board]] hosts a dual full H-bridge to control the 4 coils of the stepper motor.
which is directed to one (or more) of the stepper motor's coils.
+
 
 +
The '''end switch''' is connected between one of the FPGAs I/O with an internal pull-up enabled and the GND. The logic is internally reverted (i.e. a '1' is read when the switch is closed).
  
 
=== Connector ===
 
=== Connector ===
Line 37: Line 37:
 
| yellow
 
| yellow
 
|-
 
|-
| power
+
| GND
 
| brown, black
 
| brown, black
 
|}
 
|}
  
 
== FPGA design ==
 
== FPGA design ==
 
+
[[File:Kart_stepper_block.jpg|right|500px|stepper motor module]]
 
The [https://en.wikipedia.org/wiki/Stepper_motor stepper motor] controller has to generate the [https://en.wikipedia.org/wiki/Stepper_motor#Phase_current_waveforms 4 phases] to turn the kart's steering wheels to the desired angle.
 
The [https://en.wikipedia.org/wiki/Stepper_motor stepper motor] controller has to generate the [https://en.wikipedia.org/wiki/Stepper_motor#Phase_current_waveforms 4 phases] to turn the kart's steering wheels to the desired angle.
The kart's <code>target</code> angle is set in the [[Kart/serial_link#SmartPhone_to_Kart|desired steering angle register]].
+
The <code>target angle</code> is set in the [[Kart/serial_link#SmartPhone_to_Kart|desired steering angle register]].
  
 
To begin with, the [[Kart#FPGA_Design|design environment]] has to be downloaded.
 
To begin with, the [[Kart#FPGA_Design|design environment]] has to be downloaded.
It comprises the <code>stepperMotorController</code> block which contains the provided I2C bus interface
+
It comprises the <code>stepperMotorController</code> block which contains the registers and events manager and an empty <code>angleControl</code> block which is to be completed.
and an empty <code>angleControl</code> block which is to be designed.
+
  
 
=== Functionality ===
 
=== Functionality ===
  
The block receives a <code>target</code> unsigned number and has to step the coils at each occurrence of the <code>enStep</code> signal until the desired angle is reached.
+
The block receives a <code>targetAngle</code> unsigned number and has to step the coils at each occurrence of the <code>stepEn</code> signal until the desired angle is reached.
The current in the coils is given by the 4&nbsp;outputs <code>coil1</code> to <code>coil4</code>.
+
The steering angle, <code>actual</code>, is estimated with the help of a counter which increments or decrements each time when when the coil control signals change.
+
  
The block provides the estimated angle, <code>actual</code>, together with a logic signal, <code>reached</code>, telling if the desired angle has been reached.
+
The coils are controlled through the 4&nbsp;outputs <code>coil1</code> to <code>coil4</code>. When a '1' is applied, the corresponding coil is magnetized.
 +
{{WarningBox|content=
 +
To control the stepper, one coil at a time should be magnetized, known as [https://en.wikipedia.org/wiki/Stepper_motor#Wave_drive_(one_phase_on) '''wave drive'''].
 +
 
 +
The switching frequency should also be chosen carefully. A frequency of 285 Hz is near the slip limit of the motor.
 +
The frequency is given by the formula : f = 100k / prescaler.
 +
A prescaler ('''clockDivider''') of '''400''' (i.e. a frequency of 250 Hz) is a great first approach.
 +
}}
 +
The steering angle, <code>actual</code>, is estimated with the help of a counter which increments or decrements each time the coils change.
 +
 
 +
It is joined with a logic signal, <code>reached</code>, telling if the desired angle has been reached.
 
This information is sent back to the [[Kart#Android_App|controlling smartphone]].
 
This information is sent back to the [[Kart#Android_App|controlling smartphone]].
  
Line 62: Line 69:
  
 
A switch contact, providing the signal <code>stepperEnd</code>, has to be mechanically fitted on the kart in order set one end of the wheels' direction movement.
 
A switch contact, providing the signal <code>stepperEnd</code>, has to be mechanically fitted on the kart in order set one end of the wheels' direction movement.
As soon as <code>stepperEnd</code> is activated, the stepper motor is stopped and the <code>actual</code> angle is reset.
+
As soon as <code>stepperEnd</code> is '1', the stepper motor is stopped and the <code>actual</code> angle is reset.
  
 
With this, the steering motor will not try to turn further than what the kart's mechanical structure allows it to do in one of the directions.
 
With this, the steering motor will not try to turn further than what the kart's mechanical structure allows it to do in one of the directions.
Line 68: Line 75:
 
This also means that the angles are always considered as positive numbers, the zero position being given by the <code>stepperEnd</code> switch.
 
This also means that the angles are always considered as positive numbers, the zero position being given by the <code>stepperEnd</code> switch.
  
{{TaskBox|content=
 
Draw the schematics of the <code>angleControl</code> block.
 
}}
 
 
{{WarningBox|content=
 
{{WarningBox|content=
 
* In order to limit the current consumption, turn off the current in all the coils when the stepper motor is not turning any more.
 
* In order to limit the current consumption, turn off the current in all the coils when the stepper motor is not turning any more.
 
* Make sure that both the first and the last pulse of the coil control signals have the same duration as all the others.
 
* Make sure that both the first and the last pulse of the coil control signals have the same duration as all the others.
 +
}}
 +
{{TaskBox|content=
 +
Draw the schematics of the <code>angleControl</code> block.
 
}}
 
}}
  
 
=== Hardware orientation ===
 
=== Hardware orientation ===
 
+
[[File:Kart stepper hw orientation.svg|right|350px|stepper hardware orientation controls]]
The mechanical design allows the following variations:
+
The mechanical design allows for the following variations:
 
* the <code>stepperEnd</code> switch can be placed such as to detect the maximal steering angle either on the left or on the right side
 
* the <code>stepperEnd</code> switch can be placed such as to detect the maximal steering angle either on the left or on the right side
 
* switching the coil controls in the sequence <code>1 - 2 - 3 - 4 - 1 - 2 - …</code> can result in the kart to turn either to the left or to the right
 
* switching the coil controls in the sequence <code>1 - 2 - 3 - 4 - 1 - 2 - …</code> can result in the kart to turn either to the left or to the right
Line 84: Line 91:
 
In order to cope with all possibilities, 2&nbsp;setup signals are provided to the block:  
 
In order to cope with all possibilities, 2&nbsp;setup signals are provided to the block:  
 
* <code>sensorLeft</code> being '1' means that the <code>stepperEnd</code> switch has been placed such as to react when the wheels are oriented to the maximal steering angle on the left side
 
* <code>sensorLeft</code> being '1' means that the <code>stepperEnd</code> switch has been placed such as to react when the wheels are oriented to the maximal steering angle on the left side
* <code>clockWise</code> being '1' means that the sequence <code>1 - 2 - 3 - 4 - 1 - 2 - …</code> lets the steering turn to the right
+
* <code>clockwise</code> being '1' means that the sequence <code>1 - 2 - 3 - 4 - 1 - 2 - …</code> lets the steering turn to the right
  
[[File:Kart stepper hw orientation.svg|center|stepper hardware orientation controls]]
+
The corresponding setup bits are configured in the [[Kart/serial_link#Hardware_control_register|hardware control register]].
  
 
{{TaskBox|content=
 
{{TaskBox|content=
 
Update the schematics of the <code>angleControl</code> block in order to cope for the different mechanical design possibilities.
 
Update the schematics of the <code>angleControl</code> block in order to cope for the different mechanical design possibilities.
 
}}
 
}}
 
The corresponding setup bits are configured in the [[Kart/serial_link#Hardware_control_register|hardware control register]].
 
  
 
=== Initial position ===
 
=== Initial position ===
Line 98: Line 103:
 
The [[Kart/serial_link#Hardware_control_register|hardware control register]] also contains the bit <code>restart</code> allowing to let the stepper motor turn all the way to the angle where the <code>stepperEnd</code> switch is pressed.
 
The [[Kart/serial_link#Hardware_control_register|hardware control register]] also contains the bit <code>restart</code> allowing to let the stepper motor turn all the way to the angle where the <code>stepperEnd</code> switch is pressed.
  
This has to be sent by the [[Kart#Android_App|remote control smartphone]] after a successful Bluetooth pairing, together with the appropriate <code>sensorLeft</code> and <code>clockWise</code> setup bits, in order for the FPGA hardware to discover the zero angle position.
+
This has to be sent by the [[Kart#Android_App|remote control smartphone]] after a successful Bluetooth pairing, together with the appropriate <code>sensorLeft</code> and <code>clockwise</code> setup bits, in order for the FPGA hardware to discover the zero angle position.
 
Obviously, this should only be done after the [[Kart/serial_link#SmartPhone_to_Kart|Stepper motor period register]] has been set to a proper value.
 
Obviously, this should only be done after the [[Kart/serial_link#SmartPhone_to_Kart|Stepper motor period register]] has been set to a proper value.
  
Line 105: Line 110:
 
{{TaskBox|content=
 
{{TaskBox|content=
 
Update the schematics of the <code>angleControl</code> block in order to turn all the way to the <code>stepperEnd</code> position once the input <code>restart</code> has been set.
 
Update the schematics of the <code>angleControl</code> block in order to turn all the way to the <code>stepperEnd</code> position once the input <code>restart</code> has been set.
 +
 +
The stepper motor should wait for the <code>restart</code> signal to be released before acting normally.
 +
 +
It should not turn while a first <code>restart</code> has not been performed, at choice either directly on startup or once requested from the smartphone.
 
}}
 
}}
  
== Test pins ==
+
== Tests ==
 +
The Stepper motor functionality can be tested through the '''StepperMotor_test -> stepperMotorController_tb''' block.
 +
 
 +
[[File:Kart_stepper_tester.jpg|center|600px|Stepper motor tester]]
 +
 
 +
The corresponding simulation layout file for Modelsim is available under '''$SIMULATION_DIR/Stepper/stepperMotorController.do'''.
 +
It will automatically run the simulation if it has not been modified.
 +
 
 +
[[File:Kart_stepper_tester_sim.jpg|right|900px|Stepper motor tester]]
 +
 
 +
* The '''blue''' header shows which test is performed
 +
* The '''yellow''' signals are those generated by the tester
 +
* The '''purple''' signals are the one generated by your implementation
 +
* The '''green''' signals are internal ones
 +
* ''You can add and remove signals at will, they will not interfere with the tests''
 +
 
 +
=== Testing ===
 +
The following tests are performed :
 +
* The '''prescaler''' is set, outputting pulses on '''stepEn'''
 +
* A '''target''' of 250 is set, expecting the '''coils''' to stay at '0'
 +
* The '''restart''' signal pulses (both '''one pulse''' or '''constant '1'''' are valid), expecting the '''coils''' to turn as '''4-3-2-1-4...'''
 +
* The '''endSwitch''' pulses, which should reset '''actual''' to 0 and begin moving '''coils''' to target 250 in order '''1-2-3-4-1...'''
 +
* The '''reached''' signal should be '1' when 250 pulses have been made
 +
* A '''target''' of 500 is set, expecting same behavior as before
 +
* A '''target''' of 1000 is set, expecting same behavior as before
 +
* A '''target''' of 0 is set, expecting same behavior as before but the '''coils''' sequencing as '''4-3-2-1-4...'''
 +
* The '''endSwitch''' creates a pulse a bit after the '''actual''' signal reaches 0, ensuring coils stop moving when target 0 is reached
 +
* A '''target''' of 500 is set, expecting same behavior as before
 +
* The '''restart''' signal pulses, while the '''sensorLeft''' is invertedm expecting the '''coils''' to turn as '''1-2-3-4-1...'''
 +
* '''stepperEnd''' pulses, '''coils''' should stop and '''reached''' should rise
  
The stepper motor design leaves 14 free pins.
+
The '''transcript''' window gives you details on if tests passed or not:
Pins 1 to 12 are foreseen for test purposes.
+
* For the '''Coil1...4''' signals, you get <code>Coil direction OK</code> or <code>Coil direction error</code>.
 +
* For the '''reached''' signal, you get <code>Reached flag OK</code> or <code>Reached flag error</code>.
 +
* For the '''actual''' signal, you get <code>Position readback OK</code> or <code>Position readback error</code>.
  
 
[[Category:Kart]]
 
[[Category:Kart]]

Revision as of 11:31, 4 July 2022

Contents

The kart's stepper motor controller module generates 4 coil driving signals and receives a stepper end input.

stepper motor module

Stepper motor

Hardware

The stepper motor is a Nanotec SP3575M0906-A.

It has a step angle of 7.5°, and as such 48 steps per turn. It is attached to a 100:1 reductor, which leads to an output axis with 4800 steps per turn.

The DC/stepper control board hosts a dual full H-bridge to control the 4 coils of the stepper motor.

The end switch is connected between one of the FPGAs I/O with an internal pull-up enabled and the GND. The logic is internally reverted (i.e. a '1' is read when the switch is closed).

Connector

The cables are connected as follows:

Signal Color
phase 1 white
phase 2 blue
phase 3 red
phase 4 yellow
GND brown, black

FPGA design

stepper motor module

The stepper motor controller has to generate the 4 phases to turn the kart's steering wheels to the desired angle. The target angle is set in the desired steering angle register.

To begin with, the design environment has to be downloaded. It comprises the stepperMotorController block which contains the registers and events manager and an empty angleControl block which is to be completed.

Functionality

The block receives a targetAngle unsigned number and has to step the coils at each occurrence of the stepEn signal until the desired angle is reached.

The coils are controlled through the 4 outputs coil1 to coil4. When a '1' is applied, the corresponding coil is magnetized.

Dialog-warning.png

To control the stepper, one coil at a time should be magnetized, known as wave drive.

The switching frequency should also be chosen carefully. A frequency of 285 Hz is near the slip limit of the motor. The frequency is given by the formula : f = 100k / prescaler. A prescaler (clockDivider) of 400 (i.e. a frequency of 250 Hz) is a great first approach.

The steering angle, actual, is estimated with the help of a counter which increments or decrements each time the coils change.

It is joined with a logic signal, reached, telling if the desired angle has been reached. This information is sent back to the controlling smartphone.

Zero position

A switch contact, providing the signal stepperEnd, has to be mechanically fitted on the kart in order set one end of the wheels' direction movement. As soon as stepperEnd is '1', the stepper motor is stopped and the actual angle is reset.

With this, the steering motor will not try to turn further than what the kart's mechanical structure allows it to do in one of the directions. In the other direction, it is the programmer's task not to request a too large target angle. This also means that the angles are always considered as positive numbers, the zero position being given by the stepperEnd switch.

Dialog-warning.png

  • In order to limit the current consumption, turn off the current in all the coils when the stepper motor is not turning any more.
  • Make sure that both the first and the last pulse of the coil control signals have the same duration as all the others.

View-pim-tasks.png

Draw the schematics of the angleControl block.

Hardware orientation

stepper hardware orientation controls

The mechanical design allows for the following variations:

  • the stepperEnd switch can be placed such as to detect the maximal steering angle either on the left or on the right side
  • switching the coil controls in the sequence 1 - 2 - 3 - 4 - 1 - 2 - … can result in the kart to turn either to the left or to the right

In order to cope with all possibilities, 2 setup signals are provided to the block:

  • sensorLeft being '1' means that the stepperEnd switch has been placed such as to react when the wheels are oriented to the maximal steering angle on the left side
  • clockwise being '1' means that the sequence 1 - 2 - 3 - 4 - 1 - 2 - … lets the steering turn to the right

The corresponding setup bits are configured in the hardware control register.


View-pim-tasks.png

Update the schematics of the angleControl block in order to cope for the different mechanical design possibilities.

Initial position

The hardware control register also contains the bit restart allowing to let the stepper motor turn all the way to the angle where the stepperEnd switch is pressed.

This has to be sent by the remote control smartphone after a successful Bluetooth pairing, together with the appropriate sensorLeft and clockwise setup bits, in order for the FPGA hardware to discover the zero angle position. Obviously, this should only be done after the Stepper motor period register has been set to a proper value.

Restarting to the zero position can also be a help if too much current has been drawn from the batteries and the FPGAs' power has sunk in a way that they have performed a reset.


View-pim-tasks.png

Update the schematics of the angleControl block in order to turn all the way to the stepperEnd position once the input restart has been set.

The stepper motor should wait for the restart signal to be released before acting normally.

It should not turn while a first restart has not been performed, at choice either directly on startup or once requested from the smartphone.

Tests

The Stepper motor functionality can be tested through the StepperMotor_test -> stepperMotorController_tb block.

Stepper motor tester

The corresponding simulation layout file for Modelsim is available under $SIMULATION_DIR/Stepper/stepperMotorController.do. It will automatically run the simulation if it has not been modified.

Stepper motor tester
  • The blue header shows which test is performed
  • The yellow signals are those generated by the tester
  • The purple signals are the one generated by your implementation
  • The green signals are internal ones
  • You can add and remove signals at will, they will not interfere with the tests

Testing

The following tests are performed :

  • The prescaler is set, outputting pulses on stepEn
  • A target of 250 is set, expecting the coils to stay at '0'
  • The restart signal pulses (both one pulse or constant '1' are valid), expecting the coils to turn as 4-3-2-1-4...
  • The endSwitch pulses, which should reset actual to 0 and begin moving coils to target 250 in order 1-2-3-4-1...
  • The reached signal should be '1' when 250 pulses have been made
  • A target of 500 is set, expecting same behavior as before
  • A target of 1000 is set, expecting same behavior as before
  • A target of 0 is set, expecting same behavior as before but the coils sequencing as 4-3-2-1-4...
  • The endSwitch creates a pulse a bit after the actual signal reaches 0, ensuring coils stop moving when target 0 is reached
  • A target of 500 is set, expecting same behavior as before
  • The restart signal pulses, while the sensorLeft is invertedm expecting the coils to turn as 1-2-3-4-1...
  • stepperEnd pulses, coils should stop and reached should rise

The transcript window gives you details on if tests passed or not:

  • For the Coil1...4 signals, you get Coil direction OK or Coil direction error.
  • For the reached signal, you get Reached flag OK or Reached flag error.
  • For the actual signal, you get Position readback OK or Position readback error.
Personal tools
Namespaces
Variants
Actions
Navigation
Modules / Projects
Browse
Toolbox