Part 3: Binary Conversion

by felix.wiguna12 in Circuits > Robots

211 Views, 2 Favorites, 0 Comments

Part 3: Binary Conversion

Us2s S2uS.JPG

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
    1. R_action (Right motor action)
    2. L_action (Left motor action)
  • Output
    1. RM_DIRECTION (for right motor direction)
    2. RM_SPEED (for right motor speed)
    3. LM_DIRECTION (for left motor direction)
    4. LM_SPEED (for left motor speed)
  • Internal Signal
    1. TempL
    2. TempR

US2S

Port

  • Input
    1. RMF_DIRECTION (Feedback from right motor direction)

    2. RMF_SPEED (Feedback from right motor speed)

    3. LMF_DIRECTION (Feedback from left motor direction)

    4. LMF_SPEED (Feedback from left motor Speed)

  • Ouput
    1. L_Feedback
    2. R_Feedback
  • Internal Signal
    1. TempL
    2. TempR

Block Diagram

S2US Block Diagram.png
US2S Block Diagram.png

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

S2US Coding.png

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

US2S Coding.png

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.

The Code

This is the part is the detailed version of the code provided into a link below which the module translated into VHDL code.

This code designed using ISE Design Suite 14.7 software, the code can be tested using testbench.

US2S.vhd

S2US.vhd