DC Motor

Creating your project

In this tutorial, you will learn how to implement position and speed control of a DC motor on an FPGA using the ChipInventor platform. We will use several preconfigured blocks (Verilog modules) to build a feedback system based on an encoder (measuring the motor shaft position) and pulse counters for defining position/velocity setpoints. Then, a controller generates a PWM signal to adjust the motor speed and rotation direction.

Steps to get started:

4. Click Create to create the project.

Project Assembly Steps

2.1 System Inputs

In this step, we identify the essential input signals that enable the motor control system’s operation.

a) Synchronization Clock (clk)

b) Encoder Inputs (IO57 and IO56)

c) Setpoint Increment Button (key)

d) Reset Button (rst)

 

2.2 Input Signal Processing (Debouncers)

Ensuring signal integrity is fundamental for system stability. In this step, we eliminate noise and interference from the physical buttons.

a) Debouncer for the key Button

b) Debouncer for the rst Button

 

2.3 Defining Setpoint and Reset

In this step, reference values are defined and managed to guide the motor’s position control.

a) Setpoint Counter (pulse_count16)

b) Reset Counter (pulse_count16)

 

2.4 Reading the Current Position (Encoder)

a) encoder Block

 

2.5 Position Error Calculation

a) Subtractor (subtractor16signed)

 

2.6 Proportional Gain Application

a) Proportional Gain (gain16signed)

 

2.7 Summing with Additional Corrections (Optional)

 

2.8 Determining the Rotation Direction

a) Comparator (greater16signed)

 

2.9 PWM Duty Cycle Calculation

a) Absolute Module (number_module16)

b) Additional Gain (gain16signed)

c) Saturation (saturation16)

 

2.10 PWM Signal Generation

a) PWM Control (pwm_control8)

 

2.11 Direction Control and PWM Application

a) Demux (demux2)

 

And, at the end, your project should be something like this:

 

Simulation Stage

Before programming the FPGA, it's essential to verify that your project behaves as expected in the simulation environment. This step helps catch potential logic or connection errors, saving time and avoiding issues in the physical implementation.

3.1 Accessing the Simulation Environment
  1. Go to the Simulate tab in the top menu of ChipInventor.

  2. Choose the simulation type based on your analysis needs:

3.2 Running the Simulation

3.3 Signals to Monitor

Focus on analyzing the key signals that represent the critical functionalities of your system. Here are the main ones you should observe during simulation (especially when generating a VCD file for waveform analysis):

Signal

Description

encoder counter (w_7)

Should increment or decrement based on changes in quadA and quadB.

setpoint (w_3)

Should increment with each press of the key button.

error (w_5)

Difference between setpoint and encoder position; check if it makes sense.

gain outputs (w_6, w_13)

Scaled values of the error and control signals; verify proportionality.

control result (w_8)

Combined control output used to define motor behavior.

duty cycle (w_14)

8-bit signal defining PWM intensity (0-255 range).

PWM signal (w_11)

The actual pulse-width modulated signal controlling motor speed.

motor direction (w_10)

Binary signal indicating rotation direction (forward/reverse).

Outputs (IO69, IO68)

PWM signals routed according to direction (one active at a time).


3.4 Interpreting the Results
3.5 Troubleshooting

Run the simulation as many times as necessary until the system performs as expected.

 

Synthesis and FPGA Programming

After confirming that everything works in simulation:

 

Hardware Validation

After programming, perform practical validation:

If you see undesired behavior:
- Check if the encoder direction is inverted;
- Adjust the controller gains (the constants used in gain16signed);
- Confirm that the PWM and motor speed are not saturating (very high values might keep the motor at high speed continuously).

And at the end, your circuit should look like this:

image.png

DC Motor Circuit


DC Motor Testing

Wrapping Up

Congratulations! You have developed a DC motor speed and position control system in ChipInventor. This project covered creating, simulating, synthesizing, and testing in hardware. You used pulse counters, an encoder, arithmetic operations, PWM generation, and direction selection via a demultiplexer.

From here, you can:

Keep exploring ChipInventor, and take on progressively more complex digital design and control projects!