> For the complete documentation index, see [llms.txt](https://wiki.purduesigbots.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wiki.purduesigbots.com/software/general/stall-detection.md).

# Stall Detection

Stall detection aims to prevent VEX Motors from overheating or tripping a Resettable Fuse by detecting high-current stall conditions in software.

## Methods of operation

### Current sensing

#### Current sense resistor -

**Current sensing** is the industry-standard method of detecting abnormal motor conditions. By inserting a small-valued resistor (typically 10-100 milliohms) in series with the motor and measuring the differential voltage across it, the current through the motor can be measured. High currents indicate a large power draw that will eventually trip a fuse or overheating sensor. Neither the [VEX Cortex](/vex-electronics/legacy/vex-cortex.md) FETs nor the [VEX Motor Controller](/vex-electronics/legacy/motor-controller.md) modules have current sensing resistors available, so this method is generally infeasible for use in the VEX Robotics Challenge.

#### Hall-effect sensing -

A less invasive way of measuring current stems from the fact that a current-carrying wire produces a magnetic field. By passing the motor wire in close proximity to a sensor which can detect small changes in magnetic field direction (a Hall-effect sensor), the current flow can be determined. This method measures current indirectly, so it does not influence the power delivered to the motor and should be legal for use in an actual competition; however, the magnetic fields generated by running motors can also influence the reading.

### Rotation rate sensing

Perhaps the most logical method of detecting a stall would be to monitor the shaft rotation rate and detect when it is not rotating using a [VEX Shaft Encoder](/vex-electronics/vex-sensors/3-pin-adi-sensors/encoder.md). While simple, possible problems emerge, as the level of rotation that constitutes a stall is not well-defined. In addition, when running a motor at a low PWM duty cycle or using active braking, periods of slow to no rotation are expected. Therefore, code using this method generally cannot trip instantaneously and must adjust the definition of a stall according to the current output PWM duty cycle.

Since VEX motors have a relatively consistent power curve due to the internal gearing, an attached encoder could be used to infer the current draw, given the current output speed and PWM level.

### Back-EMF sensing

An interesting alternative for stall detection comes from the use of the backwards electromotive force, or **Back-EMF**, generated by the motor while it is not being powered. This method briefly disconnects motors from power a few times per second and measures the voltage across the motor terminals; as the motor coasts on inertia, it generates a voltage corresponding to its rotation rate. Stalled motors will have little to no Back EMF voltage, while fast-spinning free run motors or motors on heavy mechanical assemblies will generate more. As this method provides approximate odometry information as well, it can be used in the same way as the rotation rate sensing method to detect stalls.

Voltage sensing is passive and is connected in parallel with the motor, so it may be legal for use as an external sensing device.

#### Contributing Teams to this Article:

* [BLRS](https://purduesigbots.com/) (Purdue SIGBots)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://wiki.purduesigbots.com/software/general/stall-detection.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
