Giter Site home page Giter Site logo

luni64 / encsim Goto Github PK

View Code? Open in Web Editor NEW
16.0 4.0 4.0 835 KB

Quadrature signal generator for testing encoder software. Requires a PJRC Teensy board. Generates quadrature signals with adjustable frequency, phase and bouncing

License: MIT License

C++ 100.00%
teensy arduino encoder quadrature index-signal chatter bounce

encsim's Introduction

EncSim

Library Description

EncSim is a library for the PJRC Teensy ARM boards (T3.0 - T3.6, T4.0, T4.1). It can be used for testing the performance of encoder libraries and/or hardware in a manual or automated test environment. It generates a quadrature signal which simulates optical or mechanical incremental encoders. You can adjust the direction, count rate and the phase of the generated signal. For simulating mechanical encoders you can add random contact bouncing (aka chatter) peaks to the signal. EncSym uses the TeensyTimerTool for generation of the quadrature signal and the random bounce peaks.

Key Features

  • Easy to use interface to control signal generation with a serial terminal.
  • Count frequency adjustable.
  • Signal phase adjustable from 90° (standard) to 10°.
  • Generates index pulses with settable distance for e.g., simulating rotary encoders with index signal.
  • Bouncing:
    • Total bounce time adjustable.
    • Minimum width of random bounce peaks adjustable.
    • Maximum width of random bouce peaks adjustable.
  • Programming API for use in own sketches, automated tests or simular applications.

Precompiled Firmware If you just want to use EncSym for testing your encoder library you do not need to install EncSim. You can download precompiled hex files for various Teensy boards instead. Just upload the firmware, open a serial terminal (arduinos serial monitor, TyCommander, PuTTY, ...) and start testing. Precompiled firmware for various boards can be downloaded from here.

Examples of generated signals

Bouncing: The follwing two images show the simulation of a mechanical encoder. The pulse rate was set to 50Hz and a total bounce time of 5 ms was choosen. The min and max duration of the bounce pulses was set to 20µs and 500µs respectively. The first image shows an overview, the second show the same data zoomed in.

50Hz with enabled bouncing 50Hz with enabled bouncing

Phase Adjustment:
Below the generated signal for a pulse rate of 100kHz and a signal phase of 45° is shown.

100kHz, 45deg

Maximum Pulse Rate:

The last example shows a signal with the maximum possible pulsrate of 1.4 MHz. You'll need a T3.6 @240MHz with F_BUS=120MHz to be able to get such high pulse rates.

100kHz, 45deg


Serial Interface

The signal generation can be controlled by an easy to use serial interface. You can use the Aduino serial monitor, TyCommander or any other serial terminal to send commands to the library. Internally the serial inteface uses Kroimons SerialCommand lib for communication with the terminal.

Commands:

Typing in help or ? in the terminal shows a list of all available commands:

help output

Command description

  • The up and down commands generate a continous quadrature signal until you send the stop command. The current counter value is printed during the 'movement'.
  • mva and mvr 'move' to a given absolute or relative position respectively. Current counter value is printed during amd after the move.
  • Each move command can be intercepted by stop or other move commands. E.g., sending up followed by down will change the direction of the signal immediately. Sending up followed by mva 0 will change direction and move back to position 0.
  • getpos and setpos get and set the current counter value
  • freq, phase, btot, bmin, bmax and period set pulse rate, phase, total bounce time, minimal and maximal bounce pulse width and index pulse period respectively.
  • print shows the current settings. Please note: the library clips the frequency and phase settings if the requested signal can not be generated with the given board. It is a good idea to check the actual settings with print if you use high frequencies and/or small phases settings.

API

Using EncSim from your sketches without the serial interface is easy:

#include <TeensyDelay.h>
#include <EncSim.h>

EncSim<0,1> simulator;       // use pin 0 and pin 1 as output (any two digital pins can be used)

void setup() {
  simulator.begin();

  simulator                   // settings can be done by a "fluent interface"
  .setFrequency(150)          // 150Hz count rate
  .setPhase(90)               // normal 90° phase shift
  .setTotalBounceDuration(0); // no bouncing
  
  simulator.moveRel(100);     // generate 100 counts
}

The following settings are available

setFrequency(Hz)            // pulse rate in Hz (1-f_max), f_max depends on board and F_BUS settings
setPhase(deg)               // signal phase in deg (10-90)
setTotalBounceDuration(µs)  // total duration of bouncing phase in µs
setBounceDurationMin(µs)    // minimum peak width of a bouncing peak
setBounceDurationMax(µs)    // maximum peak width of a bouncing peak
setPeriod(steps)            // distance in steps between the index pulses (-1 disables index pulses)

The following commands handle signal generation

moveAbsAsync(pos)           // moves (generates pulses) to absolute position, returns after starting the move
moveRelAsync(delta)         // moves relative to current position
moveAbs(pos)                // moves to absolute position, blocks until movement is done
moveRes(delta)              // moves relative to current position, blocks until movement is done
stop()                      // stops movement immediately
bool isRunning()            // true if simulator is currently moving

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.