Unit B - Rotary Encoders B.1

Similar documents
Rotary Encoder Basics

A 3-SPEED STEPPER MOTOR

CHAPTER 11 INTERRUPTS PROGRAMMING

ENCODER SELECTION (THE BASICS)

Digital pulse sensors

EECS 373 Midterm 2 Fall 2018

These three counters can be programmed for either binary or BCD count.

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

Experiment 4.A. Speed and Position Control. ECEN 2270 Electronics Design Laboratory 1

12.1. Unit 12. Exceptions & Interrupts

4) In response to the the 8259A sets the highest priority ISR, bit and reset the corresponding IRR bit. The 8259A also places

SD17098IX Specifications Networked Stepper Driver & Indexer Revision 0.0

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

Types of Interrupts:

ELCT 912: Advanced Embedded Systems

ATmega Interrupts. Reading. The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

AS58 IB AS58S IB ASC58 IB AM58 IB AM58S IB AMC58 IB

Microprocessors and Microcontrollers (EE-231)

Introduction to Embedded Systems

e-pg Pathshala Subject : Computer Science Paper: Embedded System Module: Interrupt Handling Module No: CS/ES/13 Quadrant 1 e-text

Topics. Interfacing chips

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

Lab 9: On-Board Time Generation and Interrupts

Software debouncing of buttons

Interrupts, timers and counters

8086 Interrupts and Interrupt Responses:

INTERRUPTS in microprocessor systems

Performance & Applications

Use a semaphore to avoid the enqueue and dequeue functions from accessing and modifying count variable at the same time.

PCMSK2 = (1 << PCINT18) (1 << PCINT19);//Matrix "state machine" decode

More Fun with Timer Interrupts

Interrupts L33-1. Interrupts

Embedded Systems and Software

Rotary Measuring Technology Absolute encoders, Multiturn, optional with incremental track

UNIVERSAL MOTION INTERFACE (UMI) ACCESSORY

AMCI NX3A1E Specifications Rev 0.0 Resolver PLS Ethernet Module

CENG-336 Introduction to Embedded Systems Development. Timers

27 December 2016 Pramod Ghimire. Slide 1 of 16

Dynamixel Shield for Arduino Mega2560

CoE3DJ4 Digital Systems Design. Chapter 6: Interrupts

PC Interrupt Structure and 8259 DMA Controllers

COMP2121 Experiment 4

MODBUS Protocol. The ecode Encoders contain both single register (16 bit) and double register (32 bit) values.

RTC 300/RTC 600 Installation instructions scan

Interrupts. by Rahul Patel, Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

EE Embedded Systems Design. Lessons Exceptions - Resets and Interrupts

Interrupts and timers

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz III

USB1. Encoder Data Acquisition USB Device Page 1 of 6. Description. Features

Hands-on Lab: LabVIEW Angle Sensor

Absolute Rotary Encoder with Profibus-DP Interface. User Manual PROCESS FIELD BUS

Input/Output Ports and Interfacing

Magic 8 Ball. Student's name & ID (1): Partner's name & ID (2): Your Section number & TA's name

3601 Module Manual MicroLogix 1500 & CompactLogix Stepper Module

MODEL 801R REMOTE CONTROL MICROPHONE PREAMPLIFIER

SOLUTIONS!! DO NOT DISTRIBUTE PRIOR TO EXAM!!

845G. Description. Features. Specifications

Introduction. Unit 4. Numbers in Other Bases in C/C++ BIT FIDDLING. Microcontrollers (Arduino) Overview Digital I/O

Elevator Controller BRANDON AHO AND JINBO ZHU

Fall 2017 Project Assignment Speed Trap

Chapter 11: Interrupt On Change

Microcontroller and Embedded Systems:

CONTROL MICROSYSTEMS High Speed Counter Input Module. Hardware Manual

Read this chapter to familiarize yourself with this manual. It tells you how to use the manual properly and efficiently.

AVR Timers TIMER0. Based on:

Device manual Profibus encoder. RM30xx RN30xx /00 06/2013


UNIVERSAL MOTION INTERFACE (UMI) ACCESSORY

Interrupts. EE4380 Fall 2001 Class 9. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

Experiment# 8: Photo-Interrupter Control

SSU 4 th Annual Programming Contest, Sponsored by JD Software

AGH University of Science and Technology Cracow Department of Electronics


General Syntax. Operators. Variables. Arithmetic. Comparison. Assignment. Boolean. Types. Syntax int i; float j = 1.35; int k = (int) j;

1 MALP ( ) Unit-1. (1) Draw and explain the internal architecture of 8085.

EC2304-MICROPROCESSOR AND MICROCONROLLERS 2 marks questions and answers UNIT-I

Timers and Interrupts. Mark Neil - Microprocessor Course

Microprocessors B (17.384) Spring Lecture Outline

Topic 11: Interrupts ISMAIL ARIFFIN FKE UTM SKUDAI JOHOR

University of Technology

UNIVERSITY OF CONNECTICUT. ECE 3411 Microprocessor Application Lab: Fall Quiz IV

MHAD 50 - HDmag. Features

Rotary Measuring Technology

DE2Bot User s Manual Georgia Institute of Technology ECE2031

DeviceNet. Manual / Users Guide. Part No , Doc. No Ver. 00

ABSOLUTE ROTARY ENCODER WITH DEVICE NET INTERFACE USER MANUAL

Laboratory Exercise 7

General Purpose Programmable Peripheral Devices. Assistant Professor, EC Dept., Sankalchand Patel College of Engg.,Visnagar

RoHS. Shock / vibration resistant. Short circuit proof. Flexible. . XXXX e. . XXXX e

Interrupts and Timers

Lab 2 Part 3 Assembly Language Programming and 9S12 Ports

Using SimplexMotion integrated motors for simple standalone applications

PARALLEL GENERAL INFORMATION PARALLEL AND PARALLEL PROGRAMMABLE ABSOLUT ENCODERS. BCD Code 2nd decade 1st decade. Dec Binary Code Gray Code

Extending Encoder Button Functionality on your DDS Development Kit

Variations on a Theme

Writing a Basic Quickstep Program

Interrupt is a process where an external device can get the attention of the microprocessor. Interrupts can be classified into two types:

Absolute Encoders Multiturn

INTERFACING INTERFACING. Richa Upadhyay Prabhu. NMIMS s MPSTME February 25, 2016

8051 Microcontrollers

Transcription:

Unit B - Rotary Encoders B.1

B.2 Rotary Encoders Electromechanical devices used to measure the angular position or rotation of a shaft. Two types: Absolute: Output a binary number for the current angular position of the shaft. 0000 = 0, 0001 = 22.5, 0010 = 45, etc. Incremental: Outputs signals that indicate a change in angular position and the direction of rotation. Many uses in controlling mechanical devices Scanners, printers, mice, robots, manufacturing equipment, etc.

B.3 Rotary Encoders Incremental encoders produce quadrature outputs Output is two square waves, 90 out of phase, as the device is rotated By examining the state of the two outputs at the transitions, we can tell which way it s being rotated. Rotating clockwise A B Rotating counter-clockwise

B.4 Rotary Encoders If B = 0 when A Clockwise If B = 0 when A Counter clockwise If A = 1 when B Clockwise If A = 1 when B Counter clockwise Rotating clockwise A B Rotating counter-clockwise

Rotary Encoders B.5 Can implement this as a state machine Rotating clockwise A B State (B,A) 10 CCW B=1 Rotating counter-clockwise 00 01 11 10 A=1 B=1 CW A=0 CW B=0 CW 00 01 11 10 CCW CW A=0 CCW B=0 CCW A=1 00

B.6 Gray Codes The two bit output sequence is a Gray Code. Each adjacent element differs by only one bit. In normal binary codes, multiple bits change from one code to the next (011 100) Impossible for hardware to make sure all the bits change at the same time. Gray codes are used with many electromechanical devices. 3-Bit Binary 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 3-Bit Gray 0 0 0 0 0 1 0 1 1 0 1 0 1 1 0 1 1 1 1 0 1 1 0 0

B.7 Rotary Encoders Encoder has three terminals A, B and common As it rotates the two switches open and close Ones used in our lab have 64 states per revolution Must have pull-up resistors on switch outputs +5 A B µc

B.8 Rotary Encoder Lab Write a program that monitors the two inputs from the encoder and increments or decrements a count value each time the encoder changes state. Display the count value on the LCD, update only when it changes. When the count is a multiple of eight, play one of eight musical tones for one second. Implement a state machine with four states: A and B inputs from encoder cause state transitions. State transitions cause count to go up or down.

B.9 Rotary Encoder Lab Test the program by rotating the encoder and seeing if the count value changes correctly. Problem: When a tone is being played, the program ignores the encoder inputs (try it). Transitions can be lost while the program is in delays and other time-consuming tasks. Solution: Modify the program to use interrupts to handle the encoder inputs. Use Pin Change Interrupts to generate interrupts whenever an input from the encoder changes. Program responds to input transitions regardless of what it is doing, allowing the count value to change properly when tones are being played.

B.10 Pin Change Interrupts All the input pins in Ports B, C and D can trigger a pin change interrupt. When enabled, a 0 1 or 1 0 transition on the pin will cause an interrupt. Separate ISRs for each of the three ports: Port B: PCINT0_vect Port C: PCINT1_vect Port D: PCINT2_vect All the pins in one port must use the same interrupt service routine. Up to the ISR to figure out what to do.

B.11 Pin Change Interrupts Pin change interrupt registers Pin Change Int. Control Register (PCICR) Pin Change Int. Flag Register (PCIFR) Pin Change Mask Register 0 (PCMSK0) for Port B Pin Change Mask Register 1 (PCMSK1) for Port C Pin Change Mask Register 2 (PCMSK2) for Port D PCIE2 PCIE1 PCIE0 PCIF2 PCIF1 PCIF0 PCINT7 PCINT6 PCINT5 PCINT4 PCINT3 PCINT2 PCINT1 PCINT0 PCINT14 PCINT13 PCINT12 PCINT11 PCINT10 PCINT9 PCINT8 PCINT23 PCINT22 PCINT21 PCINT20 PCINT19 PCINT18 PCINT17 PCINT16 To enable a pin change interrupt: Set the PCIEx bit to a one for the port Set the PCINTxx bit in the mask register for the I/O pin Call sei() to enable global interrupts

B.12 Pin Change Interrupts Pin Change Interrupt numbers: (PCMSK0) (PCMSK1) (PCMSK2) PORTB PORTC PORTD 7 (D7) PCINT23 6 (D6) PCINT22 5 (D13) PCINT5 5 (A5) PCINT13 5 (D5) PCINT21 4 (D12) PCINT4 4 (A4) PCINT12 4 (D4) PCINT20 3 (D11) PCINT3 3 (A3) PCINT11 3 (D3) PCINT19 2 (D10) PCINT2 2 (A2) PCINT10 2 (D2) PCINT18 1 (D9) PCINT1 1 (A1) PCINT9 1 (D1) PCINT17 0 (D8) PCINT0 0 (A0) PCINT8 0 (D0) PCINT16 Use the names above to enable interrupts for various pins: PCMSK0 = ((1 << PCINT5) (1 << PCINT1));

B.13 Interrupt-Based Rotary Encoder Lab Start with your polling-based rotary encoder lab and modify it to use interrupts to handle the encoder inputs. Decide what tasks should be done in the ISR and what stays in the main loop. Hint: Don t do anything that requires delays in the ISR. Test the program by continuing to rotate the knob while a tone is being played. Once the tone is finished the new count value should be displayed.