DC motor and PWM Sepehr Naimi www Nicer
- Slides: 25
DC motor and PWM Sepehr Naimi www. Nicer. Land. com
Topics n n Making Robots with Motors DC motor n n n Unidirectional control Bidirectional control PWM modes n n Wave generating using Fast PWM Wave generating using Phase correct PWM 2
Some robots with 2 DC motors 3
DC motor 4
Unidirectional control +12 V M VCC GND Analog Ground AVR TIP 120 Analog Power +5 V Digital Ground 5
Bidirectional control 6
Bidirectional (clock wise) 7
Bidirectional (counter clockwise) 8
Bidirectional 9
L 298 10
Using L 298 N 11
L 298 module 12
PWM and Duty Cycle 13
Timer 0 Review TCCR 0 A OCR 0 A TCCR 0 B TCNT 0 OCR 0 B TOV 0 = = OCF 0 A OCF 0 B 14
Timer Mode (WGM) WGM 02 WGM 01 WGM 00 Comment 0 0 1 1 0 1 0 1 Normal Phase correct PWM CTC (Clear Timer on Compare Match) Fast PWM Reserved Phase correct PWM Reserved Fast PWM 15
Fast PWM mode n Similar to Normal mode but OCR 0 x are buffered. TCNT 0 TOV 0: 0 1 0 x. FF TOV 0 TOV time TCNT 0 TOV 0 = FF OCF 0 x FE 2 OCR 0 x 1 TOV 0 0 TOV 0 = 1 OCR 0 x-BUF 16
Phase Correct PWM mode n n Goes up and down like a yo-yo When TCNT becomes zero, the TOV 0 flag sets. TCNT 0 TOV 0: 0 1 0 x. FF 0 FF TCNT 0 TOV 0 = time TOV FE OCF 0 x 2 OCR 0 x 1 TCNT 0=0 x. FF OCR 0 x-BUF 0 TOV 0 = 1 17
Compare Output Mode (COM) CTC or Normal (Non PWM) Fast PWM Phase Correct PWM COM 0 x 1 COM 0 x 0 Description 0 0 Normal port operation, OC 0 disconnected 0 1 Toggle OC 0 on compare match 1 0 Clear OC 0 on compare match 1 1 Set OC 0 on compare match COM 0 x 1 COM 0 x 0 0 0 Normal port operation, OC 0 disconnected 0 1 Reserved 1 0 Clear OC 0 on compare match, set OC 0 at TOP. 1 1 Set OC 0 on compare match, clear OC 0 at TOP. COM 0 x 1 COM 0 x 0 0 0 Normal port operation, OC 0 disconnected 0 1 Reserved 1 0 Clear OC 0 on compare match when up-counting. Set OC 0 on compare match when down-counting. 1 1 Set OC 0 on compare match when up-counting. Clear OC 0 on compare match when down-counting. Description 18
Fast PWM Calculations Fast PWM Duty cycle = changeable (0% to 100%) Frequency = selectable between limited choices TCNT 0 0 x. FF OCR 0 x 0 0 OC 0 x COM=2 OC 0 x COM=3 FOC 0= fclk N(256) 19
Assuming XTAL = 16 MHz, make the following pulse duty cycle = 75% and frequency = 62. 500 KHz FOC 0= fclk N(256) 62. 500 KHz= 16 MHz N(256) N= 16 MHz 62. 500 K*256 =1 75/100 = (OCR 0 x+1)/256 OCR 0 x+1 = 192 OCR 0 x = 191 DDRD |= (1<<6); //PD 6 as output OCR 0 A = 191; TCCR 0 A = (1<<COM 0 A 1)|(1<<WGM 00); TCCR 0 B = 0 x 01; //N = 1 (no prescaler) 20
Compare Output Mode (COM) CTC or Normal (Non PWM) Fast PWM Phase Correct PWM COM 0 x 1 COM 0 x 0 Description 0 0 Normal port operation, OC 0 disconnected 0 1 Toggle OC 0 on compare match 1 0 Clear OC 0 on compare match 1 1 Set OC 0 on compare match COM 0 x 1 COM 0 x 0 0 0 Normal port operation, OC 0 disconnected 0 1 Reserved 1 0 Clear OC 0 on compare match, set OC 0 at TOP. 1 1 Set OC 0 on compare match, clear OC 0 at TOP. COM 0 x 1 COM 0 x 0 0 0 Normal port operation, OC 0 disconnected 0 1 Reserved 1 0 Clear OC 0 on compare match when up-counting. Set OC 0 on compare match when down-counting. 1 1 Set OC 0 on compare match when up-counting. Clear OC 0 on compare match when down-counting. Description 21
Phase Correct PWM Calculations Phase Correct PWM Duty cycle = changeable (0% to 100%) Frequency = selectable between limited choices TCNT 0 0 x. FF OCR 0 x 0 0 OC 0 x COM=2 OC 0 x COM=3 FOC 0= fclk N(510) 22
Assuming XTAL = 16 MHz, make the following wave: duty cycle = 75% and frequency = 31. 372 KHz FOC 0= fclk N(510) 31. 372 KHz= 16 MHz N(510) N= 16 MHz 31. 372 K*510 =1 75/100 = OCR 0 x / 255 OCR 0 x = 191 DDRD |= (1<<6); //PD 6 as output OCR 0 A = 191; TCCR 0 A = (1<<COM 0 A 1)|(1<<WGM 00); TCCR 0 B = 0 x 01; //N = 1 (no prescaler) 23
Unidirectional Speed Control +12 V M VCC GND Analog Ground OC 0 A AVROC 0 A TIP 120 Analog Power +5 V Digital Ground 24
Bidirectional Speed Control 25
- Sepehr naimi
- Sepehr naimi
- Nicerland
- Sepehr sani
- Sarah naimi
- Superlative adjective for nice
- Nicer land
- Nicer land
- Nicer globe
- Nicer
- Timercounter
- Nicer land
- Motor neuron
- Svm pwm
- Pwm sinyali nedir
- 555 timer pwm
- Space vector pwm
- Advantages of pwm
- Pwm in embedded system
- Pwm in embedded system
- Teorema de shanon
- Edge aligned pwm
- Contoh aplikasi pwm
- Analogwrite komutu nedir
- Arduino multi task
- Arduino timer1 pwm example