Kart/DC motor controller
Axel.amand (Talk | contribs) (→FPGA design) |
Axel.amand (Talk | contribs) |
||
Line 87: | Line 87: | ||
Update the schematics of the <code>dcMotorPwm</code> block in order to stop the motor on connection loss. | Update the schematics of the <code>dcMotorPwm</code> block in order to stop the motor on connection loss. | ||
}} | }} | ||
+ | |||
+ | == Tests == | ||
+ | The DC motor functionality can be tested through the '''DCMotor_test -> dcMotorController_tb''' block. | ||
+ | |||
+ | [[File:Kart_dc_tester.jpg|center|600px|DC motor tester]] | ||
+ | |||
+ | The corresponding simulation layout file for Modelsim is available under '''$SIMULATION_DIR/DCMotor/dcMotorController.do'''. | ||
+ | It will automatically run the simulation if it has not been modified. | ||
+ | |||
+ | [[File:Kart_dc_tester_sim.jpg|right|1000px|DC 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 | ||
+ | * ''You can add and remove signals at will, they will not interfere with the tests'' | ||
+ | |||
+ | === Tests === | ||
+ | The following tests are performed : | ||
+ | * The '''prescaler''' signal is set to 10 | ||
+ | * Positive speed of 33, 66 and 100% are tested, expecting correct '''PWM''' and '''forwards''' = '1' | ||
+ | * Negative speed of 33, 66 and 100% are tested, expecting correct '''PWM''' and '''forwards''' = '0' | ||
+ | * The '''normalDirection''' is inverted | ||
+ | * Positive speed of 50 and 100% are tested, expecting correct '''PWM''' and '''forwards''' = '0' | ||
+ | * Negative speed of 50 and 100% are tested, expecting correct '''PWM''' and '''forwards''' = '1' | ||
+ | * '''Restart''' is held at '1' while '''normalDirection''' is inverted again, expecting '''PWM = '0'''' and '''forwards''' = '1' | ||
+ | * '''Restart''' is released, expecting correct '''PWM''' and '''forwards''' = '1' | ||
+ | * The '''BT Connection''' is lost, expecting '''PWM = '0'''' and '''forwards''' = '1' | ||
+ | |||
+ | The '''transcript''' window gives you details on if tests passed or not. | ||
+ | |||
+ | For the '''PWM''' signal, you get <code>PWM OK</code> or <code>PWM Error</code>. | ||
+ | |||
+ | For the '''forwards''' signal, you get <code>Direction OK</code> or <code>Direction Error</code>. | ||
[[Category:Kart]] | [[Category:Kart]] |
Revision as of 11:10, 4 July 2022
|
DC motor
The DC motor is a Modelcraft RB350018-2A723R.
It is powered in 12 V and draws a maximal current of 0.7 A.
The control board hosts a dual full-bridge and a circuitry to create the switching dead-times and the direction of the current.
FPGA design
The DC motor controller has to control the Kart's propulsion both in forward and reverse.
For this, two signals are generated :
- A
pwm
with a controllable frequency whose duty-cycle is modified to control the speed - A
forwards
signal to drive either forward or backward.
The speed
is set in the DC motor speed register, ranging from -15 to 15
.
The frequency is given by the prescaler
in the DC motor prescaler register with the
formula f = fclk / (PWMsteps * prescaler) = 10M / (16 * prescaler).
To begin with, the design environment has to be downloaded,
which contains the registers and events manager and an empty dcMotorPwm
block which is to be completed.
Functionality
The block receives a speed
signed number and has to drive the DC motor with a pwm
and a forwards
signal.
These signals are internally converted to two driving signals to control an H-bridge (they take into account the dead-times to avoid short-circuiting the motor while switching).
The mean amplitude of the DC motor's voltage is controlled by a Pulse Width Modulation (PWM):
- The
forwards
signal is derived from the sign of thespeed
control. - The
pwm
signal is derived from the absolute value ofspeed
.
The PWM signal is implemented with the help of a free-running counter and a comparator. However:
- the power transistors cannot switch at too high frequencies
- there is a need for a dead time where all power transistors are open between the PWM transitions
Because of this, the PWM period is limited to a certain value. This is achieved with the help of an en signal generated by a counter dividing the clock frequency. The counter only increments when this signal is '1'.
The minimal value of the PWM signal is studied in another part of the project.
The period of the en
pulse train is set in the DC motor PWM period register
and given by the formula f = fclk / (PWMsteps * prescaler) = 10M / (16 * prescaler).
Hardware orientation
The mechanical design can either lead the Kart to drive forwards or backwards when a positive voltage is applied to the DC motor.
In order to cope with this, a setup signal, normalDirection
, is provided to the block.
normalDirection
being '1' means that a positive voltage applied to the DC motor lets the kart drive forwards.
The setup bit is configured in the hardware control register.
Bluetooth connection
When the Bluetooth connection is lost, the DC motor should not turn.
In order to cope with this, a control signal, btConnected
, is provided to the block.
When btConnected
is '0', the DC motor must stop.
The BT connection bit is configured in the hardware control register.
Tests
The DC motor functionality can be tested through the DCMotor_test -> dcMotorController_tb block.
The corresponding simulation layout file for Modelsim is available under $SIMULATION_DIR/DCMotor/dcMotorController.do. It will automatically run the simulation if it has not been modified.
- 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
- You can add and remove signals at will, they will not interfere with the tests
Tests
The following tests are performed :
- The prescaler signal is set to 10
- Positive speed of 33, 66 and 100% are tested, expecting correct PWM and forwards = '1'
- Negative speed of 33, 66 and 100% are tested, expecting correct PWM and forwards = '0'
- The normalDirection is inverted
- Positive speed of 50 and 100% are tested, expecting correct PWM and forwards = '0'
- Negative speed of 50 and 100% are tested, expecting correct PWM and forwards = '1'
- Restart is held at '1' while normalDirection is inverted again, expecting PWM = '0' and forwards = '1'
- Restart is released, expecting correct PWM and forwards = '1'
- The BT Connection is lost, expecting PWM = '0' and forwards = '1'
The transcript window gives you details on if tests passed or not.
For the PWM signal, you get PWM OK
or PWM Error
.
For the forwards signal, you get Direction OK
or Direction Error
.