Step Motor Controller. Application Note. AVR360: Step Motor Controller. Theory of Operation. Features. Introduction



Similar documents
8-bit Microcontroller. Application Note. AVR222: 8-point Moving Average Filter

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

8-bit RISC Microcontroller. Application Note. AVR236: CRC Check of Program Memory

AVR305: Half Duplex Compact Software UART. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit Microcontroller. Application Note. AVR400: Low Cost A/D Converter

AVR034: Mixing C and Assembly Code with IAR Embedded Workbench for AVR. 8-bit Microcontroller. Application Note. Features.

8-bit Microcontroller. Application Note. AVR415: RC5 IR Remote Control Transmitter. Features. Introduction. Figure 1.

8-bit Microcontroller. Application Note. AVR314: DTMF Generator

8-bit RISC Microcontroller. Application Note. AVR182: Zero Cross Detector

8-bit Microcontroller. Application. Note. AVR204: BCD Arithmetics. Features. Introduction. 16-bit Binary to 5-digit BCD Conversion bin2bcd16

AVR106: C functions for reading and writing to Flash memory. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR134: Real Time Clock (RTC) using the Asynchronous Timer. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

General Porting Considerations. Memory EEPROM XRAM

AT89C5131A Starter Kit... Software User Guide

8-bit Microcontroller. Application Note. AVR410: RC5 IR Remote Control Receiver

8-bit Microcontroller. Application Note. AVR201: Using the AVR Hardware Multiplier

How to Calculate the Capacitor of the Reset Input of a C51 Microcontroller 80C51. Application Note. Microcontrollers. Introduction

AVR319: Using the USI module for SPI communication. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR317: Using the Master SPI Mode of the USART module. 8-bit Microcontrollers. Application Note. Features. Introduction

Tag Tuning/RFID. Application Note. Tag Tuning. Introduction. Antenna Equivalent Circuit

AVR033: Getting Started with the CodeVisionAVR C Compiler. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

2-wire Serial EEPROM AT24C512

AT91 ARM Thumb Microcontrollers. Application Note. Interfacing a PC Card to an AT91RM9200-DK. Introduction. Hardware Interface

256K (32K x 8) OTP EPROM AT27C256R 256K EPROM. Features. Description. Pin Configurations

8-bit Microcontroller. Application Note. AVR105: Power Efficient High Endurance Parameter Storage in Flash Memory

Quick Start Guide. CAN Microcontrollers. ATADAPCAN01 - STK501 CAN Extension. Requirements

AVR030: Getting Started with IAR Embedded Workbench for Atmel AVR. 8-bit Microcontrollers. Application Note. Features.

AVR1318: Using the XMEGA built-in AES accelerator. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1600: Using the XMEGA Quadrature Decoder. 8-bit Microcontrollers. Application Note. Features. 1 Introduction. Sensors

AVR1900: Getting started with ATxmega128A1 on STK bit Microcontrollers. Application Note. 1 Introduction

Application Note. C51 Bootloaders. C51 General Information about Bootloader and In System Programming. Overview. Abreviations

AVR1309: Using the XMEGA SPI. 8-bit Microcontrollers. Application Note. Features. 1 Introduction SCK MOSI MISO SS

AVR32701: AVR32AP7 USB Performance. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

USB Test Environment ATUSBTEST- SS7400. Summary

AVR241: Direct driving of LCD display using general IO. 8-bit Microcontrollers. Application Note. Features. Introduction AVR

AVR442: PC Fan Control using ATtiny13. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit. Application Note. Microcontrollers. AVR282: USB Firmware Upgrade for AT90USB

Using CryptoMemory in Full I 2 C Compliant Mode. Using CryptoMemory in Full I 2 C Compliant Mode AT88SC0104CA AT88SC0204CA AT88SC0404CA AT88SC0808CA

8-bit Microcontroller. Application Note. AVR461: Quick Start Guide for the Embedded Internet Toolkit. Introduction. System Requirements

AVR245: Code Lock with 4x4 Keypad and I2C LCD. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR353: Voltage Reference Calibration and Voltage ADC Usage. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1301: Using the XMEGA DAC. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR32110: Using the AVR32 Timer/Counter. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1922: Xplain Board Controller Firmware. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

AVR1510: Xplain training - XMEGA USART. 8-bit Microcontrollers. Application Note. Prerequisites. 1 Introduction

AVR2006: Design and characterization of the Radio Controller Board's 2.4GHz PCB Antenna. Application Note. Features.

AVR120: Characterization and Calibration of the ADC on an AVR. 8-bit Microcontrollers. Application Note. Features. Introduction

AVR32138: How to optimize the ADC usage on AT32UC3A0/1, AT32UC3A3 and AT32UC3B0/1 series. 32-bit Microcontrollers. Application Note.

AT91 ARM Thumb Microcontrollers. AT91SAM CAN Bootloader. AT91SAM CAN Bootloader User Notes. 1. Description. 2. Key Features

ATF15xx Product Family Conversion. Application Note. ATF15xx Product Family Conversion. Introduction

ATF1500AS Device Family. Application Note. In-System Programming of Atmel ATF1500AS Devices on the HP3070. Introduction.

USB 2.0 Full-Speed Host/Function Processor AT43USB370. Summary. Features. Overview

AVR055: Using a 32kHz XTAL for run-time calibration of the internal RC. 8-bit Microcontrollers. Application Note. Features.

AVR1321: Using the Atmel AVR XMEGA 32-bit Real Time Counter and Battery Backup System. 8-bit Microcontrollers. Application Note.

8-bit RISC Microcontroller. Application Note. AVR155: Accessing an I 2 C LCD Display using the AVR 2-wire Serial Interface

Application Note. 8-bit Microcontrollers. AVR270: USB Mouse Demonstration

AVR115: Data Logging with Atmel File System on ATmega32U4. Microcontrollers. Application Note. 1 Introduction. Atmel

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary

Voltage boost and buck circuits using Atmel AVR Tiny13V for driving a white LED.

Table of Contents. Section 1 Introduction Section 2 Getting Started Section 3 Hardware Description

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

Application Note. Migrating from RS-232 to USB Bridge Specification USB Microcontrollers. Doc Control. References. Abbreviations

How To Prevent Power Supply Corruption On An 8Bit Microcontroller From Overheating

AVR32100: Using the AVR32 USART. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

2-Wire Serial EEPROM AT24C32 AT24C64. 2-Wire, 32K Serial E 2 PROM. Features. Description. Pin Configurations. 32K (4096 x 8) 64K (8192 x 8)

2-wire Serial EEPROM AT24C1024. Advance Information

Atmel AVR4920: ASF - USB Device Stack - Compliance and Performance Figures. Atmel Microcontrollers. Application Note. Features.

APPLICATION NOTE. Atmel AVR134: Real Time Clock (RTC) Using the Asynchronous Timer. Atmel AVR 8-bit Microcontroller. Introduction.

AVR32788: AVR 32 How to use the SSC in I2S mode. 32-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR272: USB CDC Demonstration UART to USB Bridge

Two-wire Automotive Serial EEPROM AT24C01A AT24C02 AT24C04 AT24C08 (1) AT24C16 (2)

Application Note. USB Mass Storage Device Implementation. USB Microcontrollers. References. Abbreviations. Supported Controllers

DIP Top View VCC A16 A15 A12 A7 A6 A5 A4 A3 A2 A1 A0 I/O0 I/O1 I/O2 GND A17 A14 A13 A8 A9 A11 A10 I/O7 I/O6 I/O5 I/O4 I/O3. PLCC Top View VCC A17

Application Note. 8-bit Microcontrollers. AVR091: Replacing AT90S2313 by ATtiny2313. Features. Introduction

How to use AVR Studio for Assembler Programming

AVR ONE!... Quick-start Guide. EVK Windows 32104B AVR ONE! 02/10

8051 Flash Microcontroller. Application Note. A Digital Thermometer Using the Atmel AT89LP2052 Microcontroller

Application Note. 8-bit Microcontrollers. AVR293: USB Composite Device

AN974 APPLICATION NOTE

32-bit AVR UC3 Microcontrollers. 32-bit AtmelAVR Application Note. AVR32769: How to Compile the standalone AVR32 Software Framework in AVR32 Studio V2

Atmel AVR4027: Tips and Tricks to Optimize Your C Code for 8-bit AVR Microcontrollers. 8-bit Atmel Microcontrollers. Application Note.

8-bit RISC Microcontroller. Application Note. AVR910: In-System Programming

AVR2004: LC-Balun for AT86RF230. Application Note. Features. 1 Introduction

Atmel AVR4903: ASF - USB Device HID Mouse Application. Atmel Microcontrollers. Application Note. Features. 1 Introduction

3-output Laser Driver for HD-DVD/ Blu-ray/DVD/ CD-ROM ATR0885. Preliminary. Summary. Features. Applications. 1. Description

Atmel AVR4921: ASF - USB Device Stack Differences between ASF V1 and V2. 8-bit Atmel Microcontrollers. Application Note. Features.

AVR287: USB Host HID and Mass Storage Demonstration. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

Application Note. 8-bit Microcontrollers. AVR280: USB Host CDC Demonstration. 1. Introduction

AVR444: Sensorless control of 3-phase brushless DC motors. 8-bit Microcontrollers. Application Note. Features. 1 Introduction

8-bit Microcontroller. Application Note. AVR286: LIN Firmware Base for LIN/UART Controller. LIN Features. 1. Atmel LIN/UART Controller

AVR131: Using the AVR s High-speed PWM. Introduction. Features. AVR 8-bit Microcontrollers APPLICATION NOTE

Flexible Active Shutter Control Interface using the MC1323x

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

256K (32K x 8) Battery-Voltage Parallel EEPROMs AT28BV256

AT91SAM ARM-based Flash MCU. Application Note

Two-wire Serial EEPROM AT24C1024 (1)

Application Note. 8-bit Microcontrollers. AVR307: Half Duplex UART Using the USI Module

Building A RISC Microcontroller in an FPGA

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

tinyavr Microcontrollers White Paper is the registered trademark of Atmel Corporation, 2325 Orchard Parkway, San Jose, CA Rev.

Transcription:

AVR360: Step Motor Controller Features High-Speed Step Motor Controller Interrupt Driven Compact Code (Only 10 Bytes Interrupt Routine) Very High Speed Low Computing Requirement Supports all AVR Devices Introduction This application note describes how to implement a compact size and highspeed interrupt driven step motor controller. Step motors are typically used in applications like camera zoom/film feeder, fax machines, printers, copying machines, paper feeders/sorters and disk drives. The high performance of the AVR controller enables the designer to implement high speed step motor applications with low computing requirements of the controller. Figure 1. Step Motor Step Sequence Theory of Operation A DC step motor translates current pulses into motor rotation. A typical motor contains four winding coils. The coils are often labeled red, yellow/white, red/white and yellow, but may have other colors. Applying voltage to these coils forces the motor to step one step. In normal operation, two winding coils are activated at the same time. The step motor moves clockwise one step per change in winding activated. If the sequence is applied in reverse order, the motor will run counterclockwise. The speed of rotation is controlled by the frequency of the pulses. Every time a pulse is applied to the step motor the motor will rotate a fixed distance. A typical step rotation is 1.8 degrees. With 1.8 degree rotation in each step will a complete rotation of the motor (360 degrees) require 200 steps. By changing the interval of the timer interrupts, the speed of the motor can be regulated, and by counting the number of steps, the rotation angle can be controlled. Step Motor Controller Application Note STEP 0 STEP 1 STEP 2 STEP3 YELLOW RED/WHITE YELLOW/WHITE RED Rev. 1181A 11/98 1

Table 1 shows the hexadecimal values to be output to the step motor to perform each step. Table 1. Step Motor Values Step Yellow Red/ White Software Description Yellow/ White Red Hex Value 0 1 0 0 1 9 1 1 1 0 0 C 2 0 1 1 0 6 3 0 0 1 1 3 The software uses a 16 bits timer with capture function to generate interrupt every 100 ms. When the interrupt is executed, a new step value is output to PORTB. Values for the step motor are stored in flash memory. At startup, the values are copied to SRAM to achieve faster access and maximum speed performance. In this implementation, the interrupt routine takes 7 cycles + 4 cycles to enter and 4 cycles to exit the interrupt. This totals 15 cycles. With a clock speed of 8 MHz, the step motor control takes less than 2ms. If interrupt is required every 100 ms, the step motor handling takes only 2% of the processing power in the CPU. In this example the values for the step motor are stored at RAM address 0100 (hex). The upper byte of the RAM address is constant and only the low nibble of the low byte is used to access the address information. See Figure 2. The lower nibble (4 bits) of the variables is the actual value to control the step motor, the upper nibble holds the address of the next value. Figure 2. Step Motor Addresses and Values ADDRESS (HEX) 0100 0101 0102 0103 0001 1001 0010 1100 0011 0110 0000 0011 VALUE (HEX) 19 By using this method, maximum speed can be achieved, combined with a minimum of processor resources. 2C 36 03 Resources Table 2. CPU and Memory Usage Function Code Size Cycles Register Usage Interrupt Description main 38 words - R16, XL, XH, ZL, ZH - Initialization and example program OC1A 10 words 13 + return R16, XL, XH Timer 1 output compare A Output step motor value and calculate next value TOTAL 48 words - R16, XL, XH, ZL, ZH Table 3. Peripheral Usage Peripheral Description Interrupts Enabled 4 I/O pins Step motor output pins Timer 1 Generate timer interrupt for step motor frequency generation Timer 1 output compare A 2 AVR360

AVR360 Code Listing ***************************************************************** A P P L I C A T I O N N O T E F O R T H E A V R F A M I L Y Number:AVR360 File Name: "stepmot.asm Title :Simple high speed step motor controller Date :98.07.02 Version :1.00 Support telephone :+47 72 88 43 88 (ATMEL Norway) Support fax :+47 72 88 43 99 (ATMEL Norway) Support E-mail :avr@atmel.com Target MCU :All AVR devices **************************************************************.include "..\8515def.inc" ************** Define global registers ************************.def temp = R16 ************** Define constants ******************************.equ c_value = 500 ;Compare value for output compare interrupt ; 500 cycles@5mhz = 100us ************************************************************ PROGRAM START - EXECUTION STARTS HERE ***************************************************************.cseg ;Initialize interrupt vectors.org 0x00 rjmp main.org OC1 Aaddr ;Init Output compare A interrupt vector rjmp OC1A **************************************************************** OC1A- Timer1 Output compare A interrupt routine DESCRIPTION This interrupt routine load new step motor value from the step 3

motor table in SRAM. The values in the table have two functions, the lower nibble contains the value to output to the step motor. The upper nibble holds the address of the next value. First the step value is output to the port, next the address is moved to the XL register. Number of words :6 + return Number of cycles :7 + return Low registers used :None High registers used :3 (temp,xl,xh) ************************************************************** OC1A: in temp,sreg push temp ld temp,x ;Load temp with X pointer value mov XL,temp ;Move value to X pointer andi temp,0x0f ;Mask away upper nibble out PORTB,temp ;Output lower nibble to step motor swap XL ;Swap upper and lower nibble andi XL,0x0F ;Mask away upper nibble, address is ready pop temp out SREG,temp reti ************************************************************ Main Program This program initialize Timer 1 output compare interrupt to occur with a interval defined with the c_value constant. The step motor lookup table is loaded from the flash and stored in SRAM address 0x0100 to achieve maximum speed. ***************************************************************** **** Code main: ldi r16,high(ramend) ;Intialize stackpointer out SPH,r16 ldi r16,low(ramend) out SPL,r16 ldi temp,0x0f ;Set PORTB pin3-0 as output out DDRB,temp ldi temp,0x00 out PORTB,temp ;Write initial value to PORTB ldi temp,high(c_value) ;Load compare high value out OCR1AH,temp ldi temp,low(c_value) ;Load compare low value out OCR1AL,temp ldi temp,0x00 4 AVR360

AVR360 out TCNT1H,temp ;Clear timer high byte out TCNT1L,temp ;Clear timer low byte out TCCR1A,temp ;Clear timer control reg A ldi temp,0x40 out TIFR,temp ;Clear pending timer interrupt out TIMSK,temp ;Enable Timer compare interrupt ldi ZH,high(step*2) ;Init Z pointer to step table in flash ldi ZL,low(step*2) ldi XH,high(0x0100) ;Init X pointer to RAM location ldi XL,low(0x0100) ldi temp,0x04 ;Load counter value load: lpm ;Load step value from flash st X+,R0 ;Store step value in RAM adiw ZL,0x01 ;Increment flash pointer dec temp ;Decrement counter brne load ;Continue until table is loaded ldi XH,high(0x0100) ;Initialize X pointer to RAM location ldi XL,low(0x0100) ldi temp,0x9 out TCCR1B,temp ;Clear timer on compare match,ck/1 sei ;Enble global interrupt loop: rjmp loop ;Do something else step:.db 0x19,0x2C,0x36,0x03 ;Step motor lookup table 5

Atmel Headquarters Corporate Headquarters 2325 Orchard Parkway San Jose, CA 95131 TEL (408) 441-0311 FAX (408) 487-2600 Europe Atmel U.K., Ltd. Coliseum Business Centre Riverside Way Camberley, Surrey GU15 3YL England TEL (44) 1276-686677 FAX (44) 1276-686697 Atmel Operations Atmel Colorado Springs 1150 E. Cheyenne Mtn. Blvd. Colorado Springs, CO 80906 TEL (719) 576-3300 FAX (719) 540-1759 Atmel Rousset Zone Industrielle 13106 Rousset Cedex, France TEL (33) 4 42 53 60 00 FAX (33) 4 42 53 60 01 Asia Atmel Asia, Ltd. Room 1219 Chinachem Golden Plaza 77 Mody Road Tsimshatsui East Kowloon, Hong Kong TEL (852) 27219778 FAX (852) 27221369 Japan Atmel Japan K.K. Tonetsu Shinkawa Bldg., 9F 1-24-8 Shinkawa Chuo-ku, Tokyo 104-0033 Japan TEL (81) 3-3523-3551 FAX (81) 3-3523-7581 Fax-on-Demand North America: 1-(800) 292-8635 International: 1-(408) 441-0732 e-mail literature@atmel.com Web Site http://www.atmel.com BBS 1-(408) 436-4309 Atmel Corporation 1998. Atmel Corporation makes no warranty for the use of its products, other than those expressly contained in the Company s standard warranty which is detailed in Atmel s Terms and Conditions located on the Company s website. The Company assumes no responsibility for any errors which may appear in this document, reserves the right to change devices or specifications detailed herein at any time without notice, and does not make any commitment to update the information contained herein. No licenses to patents or other intellectual property of Atmel are granted by the Company in connection with the sale of Atmel products, expressly or by implication. Atmel s products are not authorized for use as critical components in life support devices or systems. Marks bearing and/or are registered trademarks and trademarks of Atmel Corporation. Terms and product names in this document may be trademarks of others. Printed on recycled paper. 1181A 11/98/xM