Imported from GitHub: AlexDom513/autoDistance · commit a3c984a · license MIT
Description
FPGA project to automatically control the position of a cart on a ramp
README
autoDistance
The goal of this project is to implement a simple PID controller using a FPGA. (1) and (2) served as the inspiration for this project. Note that a FPGA is being used as an exercise. It is much more convenient to use a microcontroller for this application.
PID Algorithm
Before starting to implement the PID controller in hardware, a Python script was used to understand the algorithm and the system it would be used in. The script was set up in such a way that the user can specify variables like the set-point, the PID gains, and the cart mass.
A simulation then shows how the cart position is affected by the changing angle of a ramp:
FPGA Modules
PulseController
The PulseController module is responsible for interacting with the ultrasonic sensor. According to the datasheet, the FPGA must send a 10 microsecond trigger pulse. The sensor the sends eight 40 kHz pulses and detects whether there is a returned pulse. If there is a returned pulse, the time of high output from the sensor is proportional to the distance detected.
PIDController
After obtaining the cart distance in the PulseController module, the PIDController module is used to compute an appropriate ramp angle so that the cart will be directed towards the ramp's center. Proportional gain (P) is a function of where the cart is located along the ramp. Integral gain (I) continues to increase while the cart's observed position is different from the target position. Derivative gain (D) is dependent on how quickly the cart is approaching the target position. A state machine is used to jump between states that contain different computations (error, gains, ramp angle, scaling/saturation).
StepperController
Whenever a new ramp angle is computed, it is passed to the StepperController module. This module translates the value into physical movement by the stepper motor attached to the ramp. Two state machines are used to implement this functionality (Stepper State Machine & Pulse State Machine). The Stepper State Machine has a counter that is used to track the position of the stepper motor. The counter is set to 0 during startup. We then monitor whether the output from PIDController is greater than or less than the current value of the counter. Depending on the condition, we will either have the stepper motor increment or decrement from its current position. A signal that controls the motor's direction is set low/high and the Pulse State Machine is used to send trigger pulses to a A4988 motor controller. The stepper motor finally increments or decrements in the desired direction.
Circuit Schematics
Note: toggled controlled signals (via switches) are NOT shown
Sensor Circuit
Converts the +3.3V Trig_Pulse signal to +5V logic. Signal is connected to ultrasonic sensor (HC-SR04). The sensor outputs a +5V signal which is converted back to +3.3V before being passed to the FPGA.
Stepper Circuit
Connects control signals (Step_Pulse, Dir_Sel) from the FPGA to the stepper control board (A4988). Since the design is using 1/8 microstepping, MS1 and MS2 are also tied to +5V.
CAD
This was my first serious attempt at creating a 3D model! All parts were printed using PLA on a PRUSA MK3.
No comments yet. Be the first to ask about this board.