Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik...

21
Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors

Transcript of Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik...

Page 1: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

1

MikrocomputertechnikJürgen Walter

„PWM-SERVO-Quickie“Ansteuerung eines Servomotors

Page 2: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

2

Lernziele:

· Ansteuerung eines Servomotors· Zusammenhang: Pulsweite – Winkelstellung· Kalibration eines Systems mit Servo· Belastung der CPU minimieren

Page 3: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

3

Voraussetzungen

· IDE-Quickie

· PWM-LED-Quickie

Page 4: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

4

Wiederholung 1

· PWM-Programm: L_25_50_75· Es werden 3 LEDs mit verschiedenem Duty-Cycle

angesteuert – 25% - 50% - 75%

Page 5: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

5

Wiederholung 2 – Vergleich PCA0 - CPx

Page 6: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

6

Funktion des Servos

· Die Pulsbreite zwischen 900µs und 2100µs für den Servo entspricht der Winkelstellung zwischen 0° und 180°

Page 7: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

7

Aus Datenblatt des Servos HITEC HS-311 Elektr.

· Servoimpuls – Alle HiTEC-Servos benötigen Impulse zwischen 3-5V und einer Länge von 0,9 bis 2,1 ms. Die Neutralposition liegt bei 1,5 ms. Die Wiederholrate beträgt 50 Hz (20 ms).

· Betriebsspannung - Sie liegt zwischen 4,8 und 6V.· Farbcodierung der Kabel - SCHWARZ für Minus,

ROT für Plus, GELB für Impuls-Signal· Drehrichtung - Alle HiTEC Servos arbeiten im

Uhrzeigersinn (CW).

Page 8: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

8

Aus Datenblatt Servo HITEC HS-311-Mechanik

· Getriebe: Nylon   · Kugellager: 0 · Geschwindigkeit bei 4,8 V: 0,19 sec/60° · Geschwindigkeit bei 6,0 V: 0,15 sec/60° · Drehmoment bei 4,8 V: 30 Ncm · Drehmoment bei 6,0 V: 35 Ncm · Abmessungen: ca. 40 x 20 x 36,5 mm · Gewicht: ca. 43 g· Irun 180mA – Imax bei 6V: blockieren 800mA

Page 9: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

9

Kleine Berechnung Servomotor (Excel)

SYSCLK/Hz T_PWM Neutralposition/s Halbe Impulsbreite/s3000000 =65536/A2 0,0015 0,0006

PW/s Schritte Compare in Hex

links=Neutralposition_s-Halbe_Impulsbreite_s =RUNDEN(B5*A2;0) =RUNDEN(65536-C5;0) =DEZINHEX(D5)

Mitte =Neutralposition_s =RUNDEN(B6*A2;0) =RUNDEN(65536-C6;0) =DEZINHEX(D6)

rechts=Neutralposition_s+Halbe_Impulsbreite_s =RUNDEN(B7*A2;0) =65536-C7 =DEZINHEX(D7)

1° =(C5-C7)/180 Schritten120 =A10*B9 Schritten =D5+B10 =DEZINHEX(D10)

SYSCLK/Hz T_PWM Neutralposition/s Halbe Impulsbreite/s3,00E+06 0,021845333 0,0015 0,0006

PW/s Schritte Compare in Hexlinks 0,90E-03 2700,00 62836 F574Mitte 1,50E-03 4500,00 61036 EE6Crechts 2,10E-03 6300,00 59236 E764

Page 10: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

10

PWM Pulsweitenmodulation von 90° auf 0°

T=21,845msFFFFh

EE6Ch F574hE764h

0PWM

Vcc Gnd180°

90°

t

0

=PCA0CPn

-//-

-//-

Servo

Page 11: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

11

PWM Pulsweitenmodulation 90° auf180°

T=21,845msFFFFh

EE6Ch F574hE764h

0PWM

Vcc Gnd180°

90°

t

0-//-

-//-

Page 12: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

12

T=20msU

t

Servo – Datenblatt - Übersetzung

• Wiederholrate 50Hz 20ms• 0,9ms – 2.1ms• Neutralposition: 1,5ms

0,9ms1,5ms2,1ms

Page 13: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

13

T=21,84ms

U

t

Servo – PCA0 - Übersetzung

• Wiederholrate 45,77Hz 21,84ms• 0,9ms = 62835 – 2.1ms = 59234• Neutralposition: 1,5ms = 61035

0,9ms1,5ms2,1ms

Sysclk 300000021,84 65536

0,9 62835 F5731,5 61035 EE6B2,1 59234 E762

Page 14: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

14

Programm: SERVO_LR

· Servo fährt in Mittenstellung· T2 – Servo fährt im Uhrzeiger· T3 – Servo fährt gegen Uhrzeiger

· Idee: Nach ca. n*21,84ms entsteht Interrupt der Inhalt von PCA0CPx wird geändert die Servostellung ändert sich.

Page 15: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

15

Interrupt PCA0 – Vector / ISR

;ORG ORG 05Bh ;Interrupt Vector PCAclr CF ;Interrupt bestaetigtcall ISR_PCA0 ;RETI

ISR_PCA0:djnz R2,ISR_PCA_ENDE ;Sind bereits n Interrupts

;aufgetreten?mov R2,#PCA0_INT ;Wiederladen des Zaehlregisters

Page 16: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

16

Programmteil: PCA0CPx addieren

jb P1.2,C_AB ;T2? Abfrage AUF?mov A,PCA0CPL0 ;Compare 0 Low Byte in Akkuclr C ;Carry loeschenadd A,#C_ADDmov PCA0CPL0,A ;Low Byte wieder zurücksch.mov A,PCA0CPH0 ;High Byte Compare holenjnc KEINUEBERTRAG_1inc AKEINUEBERTRAG_1:mov PCA0CPH0,A ;HB Compare schreiben

Page 17: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

17

Programmteil: PCA0CPx subtrahierenC_AB:jb P1.3,ISR_PCA_ENDE ;T3 betaetigt?mov A,PCA0CPL0 ;Compare 0 Low Byte in Akkuclr C ;Carry loeschensubb A,#C_ADDmov PCA0CPL0,A ;Wieder zurueckschreibenmov A,PCA0CPH0 ;High Byte Compare holenjnc KEINUEBERTRAG_2dec AKEINUEBERTRAG_2:mov PCA0CPH0,A ;High Byte Compare schreibenISR_PCA_ENDE:ret

Page 18: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

18

ÜBUNGEN:

• Ü01 Kalibrieren Sie ihren Servo auf 0°; 90°; 180°Ermitteln Sie die dazugehörigen Werte von PCA0CPx

• Ü02 Variieren Sie die Schrittweite• Ü03 Variieren Sie die Geschwindigkeit durch

Veränderung der „Interruptanzahl zur Änderung“• Ü04 Ermitteln Sie die maximale Geschwindigkeit °/s,

indem Sie zwischen T2: 0° und T3: 180° fahren und über 10 Messungen mitteln.

• Ü05 Bauen Sie jetzt einen Scheibenwischer der zwischen 0° und 180° wischt.

Page 19: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

19

Quickies – schnell und intensiv lernen

· Ziel erreicht!

Page 20: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

20

Metaphern

Page 21: Mikrocomputertechnik PWM-SERVO-Quickie Prof. J. Walter Stand Dezember 2014 1 Mikrocomputertechnik Jürgen Walter „PWM-SERVO-Quickie“ Ansteuerung eines Servomotors.

Mik

roco

mpu

tert

echn

ikPW

M-S

ERVO

-Qui

ckie

Prof

. J. W

alte

r St

and

Dez

embe

r 20

14

21