endail / hx711-pico-c

Implementation of single and multiple HX711 use via RP2040's state machine
https://endail.github.io/hx711-pico-c/
MIT License
35 stars 7 forks source link

Possible side-set optimisation when setting gain #21

Closed endail closed 2 years ago

endail commented 2 years ago

The nature of the HX711 is that it requires at least one clock pulse each time a read takes place to set the gain. It may be possible to side-set the clock pin for at least one clock pulse on the pull, out, or mov instructions to avoid looping.

https://github.com/endail/hx711-pico-c/blob/e0fe5bc2b11b1f14b6ad9226d9e9f8881925f44a/src/hx711_noblock.pio#L97-L115

endail commented 2 years ago
pull noblock side 1     ; clk high
out x, 2                ; use as T3 delay
mov y, x side 0         ; clk low
jmp !y wrap_target      ; jump back to start (wrap_target is a label here) if y is 0

gainloop:
  set pins, 1 [T3 - 1]     ; clk high + delay
  jmp y-- gainloop side 0  ; loop if postdec y > 0 and also set clk low

If I've done this correctly, the only downside is an extra cycle when the gain is not 128 (0 in the pio program).

endail commented 2 years ago

Implemented in https://github.com/endail/hx711-pico-c/commit/9f49e0a6f92954125f4307f2315b851f927fff56