Ocdac

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 #

  1. 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_out shows when dac_min or dac_max limited the result.
  1. 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:
BoardMapRange
X, IKCM30F60GD, 1 Oct 2026dac0 115, k 6.7dac 215..255, 15..21 A
spindle, IM06B50GC1, 6 Oct 2026dac0 128, k 6.48dac 200..340, 11.3..32.3 A measured id, 0.12 s d pulses
Y, IKCM30F60GD, filter 0xF onlydac0 140, k 3.5
  • The defaults are X’s. Fit dac0 and k per board from a few trips (iddac finds 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 #

NameDescription
curinput, wanted trip current (A peak), default 20
dac0parameter, dac at 0 A from the fit, default 115
kparameter, dac counts per A, at least 0.1, default 6.7
dac_minparameter, floor: lowest dac with no ringing trip at 0 A, default 150
dac_maxparameter, ceiling, default 4095
dacoutput, comparator dac value (0..4095), to hv0.dac
cur_outoutput, trip current the clamped dac stands for (A peak)

References #

Source: .c File