DC motor and PWM.

Slides:



Advertisements
Similar presentations
More fun with Timer/Counters
Advertisements

3 Phase Wave Generation 3 Phase waveform generation using Timer/Counter1 and 3 on atmega128.
Timers in Hardware ECE152. Overview Why are timers important – Watchdog – Task switching – Accurate time of day Can use polling or interrupts.
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
ATtiny2313 Timers/Counters CS-423 Dick Steflik. What Do You Use Timers For? Timing of events (internal or external)‏ Scheduling Events Measuring the width.
Timers and Interrupts Shivendu Bhushan Summer Camp ‘13.
Pulse Width Modulation modes
Robotics Research Laboratory Louisiana State University.
The Use of Microcontrollers
16-Bit Timer/Counter 1 and 3 Counter/Timer 1,3 (TCNT1, TCNT3) are identical in function. Three separate comparison registers exist. Thus, three separate.
1 Timing System Timing System Applications. 2 Timing System components Counting mechanisms Input capture mechanisms Output capture mechanisms.
7/23 Timers in Coldfire Processor Computer Science & Engineering Department Arizona State University Tempe, AZ Dr. Yann-Hang Lee (480)
Slides created by: Professor Ian G. Harris Interrupts  Embedded systems often perform some tasks which are infrequent and possibly unpredictable Hang.
Timer/counter Chapter 12
Lab 1 - Microcontrollers Complete the program template below being sure to select the correct parameters to meet the requirements (see the Microcontroller.
A Few Words From Dilbert
Timers ELEC 330 Digital Systems Engineering Dr. Ron Hayne
Unit 10.2 Timer Examples. Example – Music Generation Channel 6 – Set up as a timer Output to Generate Square Waves Channel 4 – Set up as a timer Output.
Robotics Research Laboratory Louisiana State University.
Advanced uC Session Speaker : Chiraag Juvekar Jan 13, 2011 Speaker : Chiraag Juvekar Jan 13, 2011.
ELE22MIC Lecture 18 The AVR Sleep Modes The ATMEGA128’s Timer System
Counter/Timer/PWM. incoming Lab. Counter counter is a device which stores the number of times a particular event or process has occurred synchronous/asynchronous.
CS-280 Dr. Mark L. Hornick 1 Atmel Timer/Counter System Most microcontrollers include some type of timer system Facilitates real-time monitoring and control.
Timers and Scheduled Interrupts
Interrupt On a very basic level, an interrupt is a signal that interrupts the current processor activity. It may be triggered by an external event (change.
Application of Interrupt and Timer : Motor Position Control.
The AVR microcontroller and embedded systems using assembly and c AVR Microcontroller and Embedded System Using Assembly and C Mazidi, Naimi, and Naimi.
충북인력개발원 전자과 공학박사 강원찬 3. Timer & Counter &PWM. uP AVR (Atmega128) PWM1=OC1A(PB5) PWM2=OC1B(PB6) T0=T1(PD6) T1=T2(PD7)
#1 of 10 Tutorial Introduction PURPOSE -To explain how to configure and use the Timer Interface Module in common applications OBJECTIVES: -Identify the.
C Examples 6. Download Links MPLAB IDE dsPIC30F4011/4012 Data Sheet dsPIC30F Family Reference Manual MikroC MikroC Manual MikroC Quick Reference.
1 68HC11 Timer. 2 68HC11 Timer Subsystem Several timing functions: Basic timing Basic timing Real time interrupts Real time interrupts Output compare.
Seth Schwiethale James Crosetto James Ellison.  square pulse of ms, repeats every 20 ms  It is the same for both steering and acceleration 
Atmega328p Introduction for Digital and PWM Output Brion L Fuller II Robotics Club.
Microcontroller basics Embedded systems for mortals.
Team 7 Chaofan Chen Dhruvmin Gandhi Larry Gerhardt Pulse-width Modulation with the TIVA C.
16-Bit Timer/Counter 1 and 3
Timers and Scheduled Interrupts
Why are Timer Functions Important?
MICROCONTROLLER AND INTERFACING
Servos Elementary Robotics with Servos
Outline Introduction to Arduino UNO Programming environment setup GPIO
V.V.P. ENGINEERING COLLEGE,RAJKOT
ECE 3430 – Intro to Microcomputer Systems
PWM and DC Motor Control
BITS EDU. CAMPUS , VARNAMA
Programmable Interval Timer
COMP2121: Microprocessors and Interfacing
AVR Addressing Modes Subject: Microcontoller & Interfacing
Oct 30 Announcements Code Marked and on Blackboard
RX 8-Bit Timer (TMR) 4/20/2011 Rev. 1.00
8-Bit Timer/Counter 0 Counter/Timer 0 and 2 (TCNT0, TCNT2) are nearly identical. Differences: -TCNT0 can run off an external 32Khz clock (Tosc) or the.
COMP2121: Microprocessors and Interfacing
Timer/Counter Modified from Dr. Lam Phung’s Slides.
16-bit Timer/Counter1 Features
8-bit Timer/Counter0 with PWM
ATmega103 Timer0 and Interrupts
I/O Ports in AVR Sepehr Naimi
8-bit Timer/Counter2 with PWM and Asynchronous Operation
I/O Ports in AVR Sepehr Naimi
UNIT 19 PWM 로봇 SW 교육원 조용수.
Lecture 12 Multi-Function Timer Pulse Unit 2 (MTU2a)
Timers/Counters.
Wave Generation and Input Capturing
Interrupt Chapter 10.
MCO556 Timer System Exercise.
Timer/Counter Timer/Counter 0 Timer/Counter 1 Timer/Counter 2 8 bit
Timers Chapter 2.
Presentation transcript:

DC motor and PWM

Topics Making Robots with Motors DC motor PWM modes Unidirectional control Bidirectional control PWM modes Wave generating using Fast PWM Wave generating using Phase correct PWM 2

Some robots with 2 DC motors

DC motor

Unidirectional control +12V Analog Ground Analog Power AVR M VCC GND TIP120 +5V Digital Ground

Bidirectional control

Bidirectional (clock wise)

Bidirectional (counter clockwise)

Bidirectional

L298

Using L298N

L298 module

PWM and Duty Cycle

Timer0 Review TCCR0A TCCR0B OCR0A TCNT0 OCR0B TOV0 = = OCF0A OCF0B 14

0 1 0 CTC (Clear Timer on Compare Match) 0 1 1 Fast PWM 1 0 0 Reserved WGM02 WGM01 WGM00 Comment 0 0 0 Normal 0 0 1 Phase correct PWM 0 1 0 CTC (Clear Timer on Compare Match) 0 1 1 Fast PWM 1 0 0 Reserved 1 0 1 Phase correct PWM 1 1 0 Reserved 1 1 1 Fast PWM Timer Mode (WGM)

Fast PWM mode Similar to Normal mode but OCR0x are buffered. 1 TOV0: 1 TCNT0 TOV0: 0xFF TOV TOV TOV time TCNT0 FF TOV0 FE = OCF0x 2 OCR0x 1 TOV0 TOV0 = 1 OCR0x-BUF 16

Phase Correct PWM mode Goes up and down like a yo-yo When TCNT becomes zero, the TOV0 flag sets. 1 TCNT0 TOV0: 0xFF time TOV FF TCNT0 TOV0 OCR0x = OCF0x OCR0x-BUF TCNT0=0xFF FE 2 1 TOV0 = 1 17

Compare Output Mode (COM) COM0x1 COM0x0 Description Normal port operation, OC0 disconnected 1 Toggle OC0 on compare match Clear OC0 on compare match Set OC0 on compare match CTC or Normal (Non PWM) COM0x1 COM0x0 Description Normal port operation, OC0 disconnected 1 Reserved Clear OC0 on compare match, set OC0 at TOP. Set OC0 on compare match, clear OC0 at TOP. Fast PWM COM0x1 COM0x0 Description Normal port operation, OC0 disconnected 1 Reserved Clear OC0 on compare match when up-counting. Set OC0 on compare match when down-counting. Set OC0 on compare match when up-counting. Clear OC0 on compare match when down-counting. Phase Correct PWM 18

Fast PWM Calculations fclk FOC0= N(256) Fast PWM Duty cycle = changeable (0% to 100%) Frequency = selectable between limited choices TCNT0 TCNT0 0xFF 0xFF OCR0x OCR0x OC0x OC0x COM=2 COM=2 COM=2 OC0x OC0x COM=3 COM=3 COM=3 N(256) fclk FOC0= 19

Assuming XTAL = 16 MHz, make the following pulse duty cycle = 75% and frequency = 62.500KHz fclk N(256) FOC0= 16MHz 16MHz 62.500KHz= N = =1 N(256) 62.500K*256 75/100 = (OCR0x+1)/256  OCR0x+1 = 192  OCR0x = 191 SBI DDRD, 6 LDI R20,191 OUT OCR0A,R20 LDI R20, (1<<COM0A1)|(1<<WGM01)|(1<<WGM00) OUT TCCR0A,R20 LDI R20,0x01 OUT TCCR0B,R20 DDRD |= (1<<6); //PD6 as output OCR0A = 191; TCCR0A = (1<<COM0A1)|(1<<WGM01)|(1<<WGM00); TCCR0B = 0x01; //N = 1 (no prescaler) 20

Compare Output Mode (COM) COM0x1 COM0x0 Description Normal port operation, OC0 disconnected 1 Toggle OC0 on compare match Clear OC0 on compare match Set OC0 on compare match CTC or Normal (Non PWM) COM0x1 COM0x0 Description Normal port operation, OC0 disconnected 1 Reserved Clear OC0 on compare match, set OC0 at TOP. Set OC0 on compare match, clear OC0 at TOP. Fast PWM COM0x1 COM0x0 Description Normal port operation, OC0 disconnected 1 Reserved Clear OC0 on compare match when up-counting. Set OC0 on compare match when down-counting. Set OC0 on compare match when up-counting. Clear OC0 on compare match when down-counting. Phase Correct PWM

Phase Correct PWM Calculations Duty cycle = changeable (0% to 100%) Frequency = selectable between limited choices TCNT0 TCNT0 0xFF 0xFF OCR0x OCR0x OC0x OC0x COM=2 OC0x OC0x COM=3 N(510) fclk FOC0= 22

Assuming XTAL = 16 MHz, make the following wave: duty cycle = 75% and frequency = 31.372KHz fclk N(510) FOC0= 16MHz 16MHz 31.372KHz= N = =1 N(510) 31.372K*510 75/100 = OCR0x / 255  OCR0x = 191 DDRD |= (1<<6); //PD6 as output OCR0A = 191; TCCR0A = (1<<COM0A1)|(1<<WGM00); TCCR0B = 0x01; //N = 1 (no prescaler) 23

Unidirectional Speed Control +12V Analog Ground Analog Power AVR AVR M VCC VCC GND GND OC0A OC0A TIP120 +5V Digital Ground

Bidirectional Speed Control