OCDAC #
Brief #
ocdac sets the F3 hardware overcurrent comparator threshold hv0.dac from a trip current in A peak, using a linear map fitted per board. It runs on the F4 board and is loaded by conf/template/ocdac.txt with hv0.dac = ocdac0.dac and ocdac0.cur = 20. Use iddac (id_dac template) to find the dac for one current on a given board.
Component Explanation #
- Dac map (nrt):
k = MAX(k, 0.1);
dac = CLAMP(roundf(dac0 + k * MAX(cur, 0)), dac_min, dac_max);
cur_out = (dac - dac0) / k;
cur_outshows whendac_minordac_maxlimited the result.
- Calibration:
- The comparators see the raw shunt node (2.9 mV/A, about 3.6 counts/A in theory); the measured slope and offset depend on the TIM8 break filter, because the shorter filters trip on switching ringing on top of the current.
- Measured with filter 0xC (the default, periph.c), highest trip of the 60/180/300 deg angles:
| Board | Map | Range |
|---|---|---|
| X, IKCM30F60GD, 1 Oct 2026 | dac0 115, k 6.7 | dac 215..255, 15..21 A |
| spindle, IM06B50GC1, 6 Oct 2026 | dac0 128, k 6.48 | dac 200..340, 11.3..32.3 A measured id, 0.12 s d pulses |
| Y, IKCM30F60GD, filter 0xF only | dac0 140, k 3.5 |
- The defaults are X’s. Fit
dac0andkper board from a few trips (iddacfinds the dac for one current directly) and save them in the config.
The map is a bench fit for one board and break filter setting; check it on your hardware before relying on it as overcurrent protection.
Pins #
| Name | Description |
|---|---|
| cur | input, wanted trip current (A peak), default 20 |
| dac0 | parameter, dac at 0 A from the fit, default 115 |
| k | parameter, dac counts per A, at least 0.1, default 6.7 |
| dac_min | parameter, floor: lowest dac with no ringing trip at 0 A, default 150 |
| dac_max | parameter, ceiling, default 4095 |
| dac | output, comparator dac value (0..4095), to hv0.dac |
| cur_out | output, trip current the clamped dac stands for (A peak) |
References #
Source: .c File