Hall Sensor Demo

In this document

The purpose of this app is showing the use of the Hall Sensor Module with Position Feedback Module. For that, it implements a simple app that reads the output of a Hall sensor and shows over XScope the read velocity and position.

  • Min. Nr. of cores: 2
  • Min. Nr. of tiles: 1

Quick How-to

  1. Assemble your SOMANET device.
  2. Wire up your device. Check how at your specific hardware documentation. Connect your sensor, power supply cable, and XTAG. Power up!
  3. Set up your XMOS development tools.
  4. Download and import in your workspace the SOMANET Motor Control Library and its dependencies.
  5. Open the main.xc within the app. Include the board-support file according to your device. Also set the appropriate target in your Makefile.


Make sure the SOMANET Motor Control Library supports your SOMANET device. For that, check the Hardware compatibility section of the library.

  1. Again in your main.xc, set the configuration for the Position feedback Service and you sensor.

    on tile[IFM_TILE]:
    /* Position feedback service */
        PositionFeedbackConfig position_feedback_config;
        position_feedback_config.sensor_type = HALL_SENSOR;
        position_feedback_config.resolution  = HALL_SENSOR_RESOLUTION;
        position_feedback_config.polarity    = NORMAL_POLARITY;
        position_feedback_config.velocity_compute_period = HALL_SENSOR_VELOCITY_COMPUTE_PERIOD;
        position_feedback_config.pole_pairs  = POLE_PAIRS;
        position_feedback_config.ifm_usec    = IFM_TILE_USEC;
        position_feedback_config.max_ticks   = SENSOR_MAX_TICKS;
        position_feedback_config.offset      = 0;
        position_feedback_config.sensor_function = SENSOR_FUNCTION_COMMUTATION_AND_MOTION_CONTROL;
        position_feedback_config.hall_config.port_number = HALL_SENSOR_PORT_NUMBER;
        position_feedback_service(qei_hall_port_1, qei_hall_port_2, null, null, null, null, null, null,
                position_feedback_config, i_shared_memory[0], i_position_feedback,
                null, null, null);
  2. In parallel, the position/velocity and others status info are displayed with XScope.

    on tile[APP_TILE]:
        int angle = 0;
        int velocity = 0;
        int count = 0;
            /* get position from Hall Sensor */
            { count, void, void } = i_position_feedback.get_position();
            angle = i_position_feedback.get_angle();
            /* get velocity from Hall Sensor */
            velocity = i_position_feedback.get_velocity();
            if (!isnull(i_shared_memory)) {
                UpstreamControlData upstream_control_data = i_shared_memory.read();
                angle = upstream_control_data.angle;
                count = upstream_control_data.position;
                velocity = upstream_control_data.velocity;
            xscope_int(COUNT, count);
            xscope_int(VELOCITY, velocity);
            xscope_int(ANGLE, angle);
  3. Run the application enabling XScope.

See also

Did everything go well? If you need further support please check out our forum.