Skip to content

SLS 1322-3

This page was last updated: September 3, 2024

Details

Sensor Datasheet

SLS 1322-3

  • Sensor: SLS 1322-3 Linear Potentiometer by Active Sensors.
  • Frequency: 3 to 4 Hz.
  • Communication: Analog.
  • Max Rod Length: 3 inches.
  • Linear Function of Kilo-Ohm to Distance: \(25 \ k\Omega + 100\).
    • Increases by 1 Kilo-Ohm every 25 millimeters.
    • \(125 \ mm \approx 1 \ k\Omega\)
    • \(450 \ mm \approx 14 \ k\Omega\)

Pinout

Sensor MCU
VCC 3.3V
GND GND
Signal Analog Input

Mounting

Firmware

Library API Docs

Source Code

Implementation Details

This library allows for polling the ADC1. This consists of performing the following steps:

  • Starting the ADC peripheral.
  • Polling for an analog-to-digital conversion. A timeout waiting value can be specified.
  • Retrieving the output from the ADC.

The accuracy of the output is dependent on the resolution of the ADC and is represented as an integer after quantization. In other words, the Quantized Count2 of the analog signal is in the range of \([0, 2^{resolution} - 1]\).

Example

The STM32 Nucleo-F429ZI microcontroller has ADCs with a resolution of 12-bits. So, the range of the integer value of the measured analog signal is \([0, 4095]\).

The ADC's resolution is a known constant defined by the hardware. This is used to compute ratios between the measured Quantized Count and the resolution. The value of the ratio varies between \([0.0, 1.0]\) depending on the retraction/displacement of the linear potentiometer.

\[ Retraction \ Ratio = Quantized \ Count / Resolution \]
\[ Displacement \ Ratio = 1 - Retraction \ Ratio \]

Finally, the displacement ratio is multiplied with the linear potentiometer's maximum length in inches or millimeters. The length of the sensor's rod at full extension is about \(3\) inches.

CubeMX Settings

Per analog pin:

  • Enable the anlog channel, such as IN0 (channel 0)
  • Continuous conversion: Enabled

How to Use

classDiagram

namespace SensorLayer {
    class ILinearPotentiometer {
        <<interface>> 
        +DisplacementInches()* float
        +DisplacementMillimeters()* float
    }

    class SLS1322 {
        -kMaxResolution: uint16_t = 0x0FFF
        -kMaxLengthInches: uint8_t = 3

        +DisplacementInches()* float
        +DisplacementMillimeters()* float

        -ReadQuantizedInput()
        -DisplacementRatio()
    }
}

namespace Platform Layer {
    class IAdc {
        <<interface>>
    }
}

ILinearPotentiometer <-- SLS1322
SLS1322 ..> IAdc

end

Example

How to initialize the SLS1322 object and read the analog signal by interacting with the ILinearPotentiometer interface.

// Standard Libraries
#include <memory>

// ST HAL Dependencies
#include "adc.h"
extern ADC_HandleTypeDef hadc1;

// DFR Custom Dependencies
#include "app.hpp"
#include "Sensor/LinearPotentiometer/ilinear_potentiometer.hpp"
#include "Sensor/LinearPotentiometer/sls1322.hpp"

void cppMain() {
    std::unique_ptr<sensor::ILinearPotentiometer> lin_pot(nullptr);
    lin_pot = std::make_unique<sensor::SLS1322>(hadc1);

    float displacement_inches = 0.0f;
    displacement_inches = lin_pot->DisplacementInches();
}

  1. STM32F4 HAL User Manual, page 60, section Polling mode IO operation

  2. More information on analog signal quantization