Giter Club home page Giter Club logo

xcore_ping's Introduction

##Ultrasonic Distance Sensing for xCore This repository provides an xCore driver module for the HC-SR04 ultrasonic sensor / range finder. An example app is included that uses an XMOS xCore startKIT with this sensor and a serial display.

###Introduction The HC-SR04 devices, often called ping sensors, use sonar to determine distance to an object.

The sensor has 4 connections:

  • VCC, Power supply input, +5 Volts.
  • Trig, Trigger input, 10 microsecond high-going pulse.
  • Echo, Data output, high pulse with width representing distance.
  • GND, Power supply common.

Note: The sensor is 5V and the XCore part on the startKIT not 5V tolerant. A voltage divider was used between the Echo signal and the input port to avoid damage to the CPU from over-voltage.

The startKIT begins a sensor reading by first generating a narrow trigger pulse on an xCore output port. This is connected to the sensor trigger input. Ultrasonic pulses are then produced by the sensor to determine distance to an obstacle - something within range that causes the ultrasound ping to bounce back. This bounce time is signaled by controlling the Echo output pulse width. The xCore measures this width to determine the distance.

###Driver API The driver source is organized as an xCore module. It uses the the xC interface mechanism for task communication, which provides the API.

  • getDistance(), Get optionally filtered distance reading in millimeters.
  • setFilter(range, rate, samples, toss), Optionally adjust the driver filter settings.

Filter parameters:

  • range - in millimeters, the maximum distance to accept as valid. Default 3000.
  • rate - in milliseconds, the sample rate, >= 10. Default 60.
  • samples - the number of samples to average, between 1 and 8. Default 1.
  • toss - the number of samples to discard when recovering from a bad reading. Must be > 0. Default 2.

The driver task runs concurrently, using a select statement to watch for events. These events come from the API interface, a sample rate timer, and input port transitions from the Echo signal. The main task of the driver is to measure the width of the sensor output pulse. Readings are taken continually at the requested sample rate.

###Measurement Distance is determined based on the speed of sound: distance = (Echo pulse width * speed of sound) / 2. Timing on the xCore is microseconds*100 resolution (100MHz) giving a formula:

  • Millimeters = width / 581

The driver uses logic to reject the crazy values and provide filtering. The sensor data sheet recommends that readings be taken at intervals >= 60 milliseconds to avoid unwanted echo signals. The optional filtering (which defaults to off) is an average of the most recent in-range samples. If a value is out of range, it is replaced in the calculation by the prior valid raw reading. Filter setting is adjusted by the driver API setFilter().

xcore_ping's People

Contributors

teachop avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.