Koduino
Public Member Functions | List of all members
Encoder Class Reference

Quadrature encoder library. More...

#include <Encoder.h>

Detailed Description

Quadrature encoder library.

Copyright (C) Ghost Robotics - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential Written by Avik De avik@.nosp@m.ghos.nosp@m.trobo.nosp@m.tics.nosp@m..io

Usage

  1. (Optionally) call pinRemap() to map the A/B pins to channels 1 and 2 of timer 2, 3, 4, 5, or 19.
  2. Call init() to configure the pins and start the encoder
  3. (Optionally) call write() at any time to set the count to a desired value
  4. Call read() to read the current count

Example

#include <Encoder.h>
// Connect encoder signals B and A to PA0 and PA1
Encoder encoder;
void setup() {
pinRemap(PA0, 2, TIMER5, 1);
pinRemap(PA1, 2, TIMER5, 2);
Serial1.begin(115200);
// Assuming a 12-bit encoder
encoder.init(PA0, PA1, 4095);
}
void loop() {
Serial1 << encoder.read() << "\n";
delay(10);
}

Public Member Functions

void init (uint8_t pin1, uint8_t pin2, uint16_t maxCount)
 Initialize the quadrature encoder. More...
 
uint16_t read (void)
 Read the current encoder count. More...
 
void write (uint16_t val)
 Set the current encoder count. More...
 

Member Function Documentation

void Encoder::init ( uint8_t  pin1,
uint8_t  pin2,
uint16_t  maxCount 
)

Initialize the quadrature encoder.

This function configures the pins, and starts the timer connected to them. NOTE: pin1 and pin2 must be channels 1 and 2 of hardware timer 2, 3, 4, 5, or 19 on the F373. To check this, you have to look at the datasheet. Additionally, if not using the default pin mapping, you will have to call pinRemap() before calling this function (see example above).

Parameters
pin1Pin connected to signal A or B
pin2Pin connected to signal B or A
maxCountThe max number of ticks (set according to encoder chip specification). Caution: Counting starts at 0, so for example for a 12-bit encoder set to 4095.

Copyright (C) Ghost Robotics - All Rights Reserved Unauthorized copying of this file, via any medium is strictly prohibited Proprietary and confidential Written by Avik De avik@.nosp@m.ghos.nosp@m.trobo.nosp@m.tics.nosp@m..io

uint16_t Encoder::read ( void  )
inline

Read the current encoder count.

Returns
void Encoder::write ( uint16_t  val)
inline

Set the current encoder count.

Used to (for example) set the "zero" point

Parameters
val

The documentation for this class was generated from the following files: