Part 3: Binary Conversion
This instructable is one part of a larger build for VHDL Motor Speed Control: Decide Direction and Speed, Left and Right Speed Controller
This part give an information about binary conversion "S2US.vhd" and "US2S.vhd", which give direction and speed to PWM module and be checked in Error.vhd.
Function of This Module
S2US.vhd
The program convert a signed bit binary to unsigned bit binary, it also able to resize an 8 bit binary to 9 bit binary which will give speed and direction to the motor.
US2S.vhd
The program convert a unsigned bit binary to signed bit binary, it also able to resize an 9 bit binary to 8 bit binary which will give speed and direction to the motor.
Signals
These are the signals and port which be use for the program:
S2US
Port
- Input
- R_action (Right motor action)
- L_action (Left motor action)
- Output
- RM_DIRECTION (for right motor direction)
- RM_SPEED (for right motor speed)
- LM_DIRECTION (for left motor direction)
- LM_SPEED (for left motor speed)
- Internal Signal
- TempL
- TempR
US2S
Port
- Input
-
RMF_DIRECTION (Feedback from right motor direction)
-
RMF_SPEED (Feedback from right motor speed)
-
LMF_DIRECTION (Feedback from left motor direction)
-
LMF_SPEED (Feedback from left motor Speed)
-
- Ouput
- L_Feedback
- R_Feedback
- Internal Signal
- TempL
- TempR
Block Diagram
These are the block diagram for the program the left side are the block diagram for S2US and as the right side are the block diagram for US2S
S2US Code Explanation
This part is the detailed information regarding S2US.vhd code
When the most significant bit of the binary is ‘1’ it will go to internal signal TempL/R in this signal the 9 bit binary got inversed and two’s complement which translate the negative decimal error to positive decimal.
The motor can be set to rotate clockwise/counter clockwise, the binary for controlling speed converted from 9 but binary to 8 bit binary and the reset to restarting the whole program so it doesn’t keep going.
When the most significant bit is ‘0’ the program will continue as positive decimal and the binary for controlling the speed also got converted from 9 bit binary to 8 bit binary and the reset to restarting the whole program to force the robot to stay in place.
For this program when the most significant bit for motor is ‘1’ it will go to internal signal tempL where the binary will get inversed and two’s complement as for the direction in this case it will rotate counter clockwise and the speed convert it to 8 bit binary, when the most significant bit is ‘0’ it will directly convert the binary as for the direction it will rotate clockwise.
For the right part it’s contrary from the left motor where the most significant bit ‘0’ will go to internal signal tempR to be inversed and two’s complement and the direction going clockwise , and when the most significant bit is ‘1’ it will directly convert it, and for the direction, it will go counter clockwise
US2S Code Explaination
Same function as US2S.vhd this program
will convert a 8 bit unsigned binary to 9 bit signed binary to check for error. when the feedback most significant bit from the left motor is ‘0’ it will directly extend the binary to 9 bit for the speed and the direction of the motor will rotate clockwise. When the most significant bit is ‘1’ it will got to internal signal tempL for the binary to get inversed and two’s complement. The direction of the left motor will rotate counter clockwise and the speed got extended to 9 bit signed binary.
For the Right motor is the other way around when the most significant bit is ‘1’ it will directly convert and extend the binary and the direction of the motor will rotate counter clockwise, as for ‘0’ it will go to tempR where the binary will get inversed and two’s complement and the direction of the motor got will rotate clockwise and the speed extended to 9 bit signed binary.
The program designed for the left and right motor in reverse to make the motor not rotating at the same direction which make the robot circle around or not moving.