Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continuous reading #5

Open
tomjoro opened this issue Apr 10, 2022 · 1 comment
Open

Continuous reading #5

tomjoro opened this issue Apr 10, 2022 · 1 comment

Comments

@tomjoro
Copy link
Collaborator

tomjoro commented Apr 10, 2022

The ADS1X15 chips have two modes: single-shot and continuous. Single-shot powers down between reads, so the maximum read rate is around 33 times per second (not verified). Reading at a higher rate requires continuous mode.

In continuous mode the inputs must be selected and enabled. After that the fsr can be read at anytime and up to the maximum rate in the spec sheet.

Currently the code doesn't show how to do this.

@tomjoro
Copy link
Collaborator Author

tomjoro commented Apr 10, 2022

This seems to work.

def continuous_read_enable(bus, addr, comparison, gain \\ 2048) do
    config = %Config{
      performing_conversion: false,
      mode: :continuous,
      mux: comparison,
      gain: gain
    }
    set_config(bus, addr, config)
  end

In continuous mode only the selected inputs can be read.

  def continuous_read(bus, addr) do
    with {:ok, <<val::signed-size(16)>>} <- I2C.write_read(bus, addr, @sensor_register, 2) do
      val = val / 16 # equivalent to val >> 4
      if val > 2047 do   # 0x7FF
        {:ok, val - 4096}  # double 2048
      else
        {:ok, val}
      end
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant