Herzlich Willkommen im einzigen (deutschsprachigem) Picaxe-Forum.

Der Ursprung dieses Forum reicht bis in das Jahr 2008 zurück


Shift Register an der Picaxe

#1 von BoomBoomMagic , 26.01.2019 19:16

Ein Shift Register an einer Picaxe kann viele Vorteile bringen.
Mit nur 3 Pins ist es möglich 8 Ausgänge schalten zu können.

Das macht es besonders bei kleineren Picaxe interessant , die von Haus aus wenig Pins zu bieten haben.

Es gibt viele Typen an Shift Registern , jedoch empfehle ich das CD4094.
1. es hat eine breite Spanne an möglicher Versorgungsspannung
2. es bietet ein STROBE
3. es hat eine Latch-Funktion


Strobe :

Der
Vorteil bei einer STROBE-Funktion ist es, das man "in Ruhe" die
einzelnen Bits an Shift Register senden kann , ohne das diese gleich
ausgeführt werden .
Erst nachdem die STROBE-Leitung einen Impuls
erhalten hat, werden die aktuellen Bitzustände übernommen und sind an
den Ausgängen sichtbar - quasi eine Quittierung.

Latch:

Die
Latch-Funktion hat den Vorteil , das der letzte Zustand gehalten wird,
egal was derzeitig an die aktuellen Bits gesendet wurde.
Erst nach dem Strobe wird der neue Zustand angezeigt und weiter gehalten.
Damit ist es also nicht nötig ständig den Zustand senden zu müssen , sondern nur bei einer Änderung.


Zunächst hier einmal der Schaltplan :


Auf Lochraster könnte es z.B. so aussehen :



Jetzt kann man das Shift Register ja zu vielen Zwecken benutzen.
Also Beispiel habe ich hier einmal ein paar Arten von Lauflichtern programiert.

Beispiel 1 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 

' ############################################
' # Lauflicht => 1 LED von Links nach Rechts #
' ############################################
 

symbol Clock = c.0
symbol Data_ = pinc.1
symbol Strobe = c.2
 

let dirsc=%00000111
b0=1
 

do
 
gosub Senden
pause 100
 
if b0<128 then
b0=b0*2
else
b0=1
endif
 
loop
end
 

Senden:
 
Data_=bit0:pulsout Clock,1
Data_=bit1:pulsout Clock,1
Data_=bit2:pulsout Clock,1
Data_=bit3:pulsout Clock,1
Data_=bit4:pulsout Clock,1
Data_=bit5:pulsout Clock,1
Data_=bit6:pulsout Clock,1
Data_=bit7:pulsout Clock,1
pulsout Strobe,1
 
return
 
 




Beispiel 2 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 

' ##################################
' # Lauflicht => 1 LED hin und her #
' ##################################
 

symbol Clock = c.0
symbol Data_ = pinc.1
symbol Strobe = c.2
symbol Richtung = b1
 
let dirsc=%00000111
b0=1
 

do
 
gosub Senden
pause 100
 
if b0<128 and Richtung =0 then
b0=b0*2
else
Richtung=1
endif
 
if b0>1 and Richtung=1 then
b0=b0/2
else
Richtung=0
endif
 
loop
end
 

Senden:
 
Data_=bit0:pulsout Clock,1
Data_=bit1:pulsout Clock,1
Data_=bit2:pulsout Clock,1
Data_=bit3:pulsout Clock,1
Data_=bit4:pulsout Clock,1
Data_=bit5:pulsout Clock,1
Data_=bit6:pulsout Clock,1
Data_=bit7:pulsout Clock,1
pulsout Strobe,1
 
return
 
 




Beispiel 3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 

' ##################################
' # Lauflicht => 2 LED hin und her #
' ##################################
 

symbol Clock = c.0
symbol Data_ = pinc.1
symbol Strobe = c.2
symbol Richtung = b1
 
let dirsc=%00000111
b0=3
 

do
 
gosub Senden
pause 100
 
if b0<128 and Richtung =0 then
b0=b0*2
else
Richtung=1
endif
 
if b0>0 and Richtung=1 then
b0=b0/2
endif
 
if b0=0 and Richtung=1 then
Richtung=0
b0=3
endif
 
loop
end
 

Senden:
 
Data_=bit0:pulsout Clock,1
Data_=bit1:pulsout Clock,1
Data_=bit2:pulsout Clock,1
Data_=bit3:pulsout Clock,1
Data_=bit4:pulsout Clock,1
Data_=bit5:pulsout Clock,1
Data_=bit6:pulsout Clock,1
Data_=bit7:pulsout Clock,1
pulsout Strobe,1
 
return
 
 




Das wichtigste ist eigentlich , das man sich eine Routine fertig macht ,
die das Senden übernimmt , in der die einzelnen Bits des Bytes rückwärts
an das Shift Register gesendet werden.
Alles andere ist dann nur noch "Spielerei" und simple Programierung.

Bei etwas komplexeren Mustern , empfiehlt es sich den Befehl : Lookup zu nutzen

Beispiel:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 

' ###################################
' # Lauflicht => 2 LED kreuzen sich #
' ###################################
 

symbol Clock = c.0
symbol Data_ = pinc.1
symbol Strobe = c.2
 
let dirsc=%00000111
 
do
 
for b1=0 to 43
lookup b1,(0,0,128,128,1,1,64,64,2,2,32,32,4,4,16,16,8,8,16,16,4,4,32,32,2,2,64,64,1,1,128,128,0,0),b0
gosub Senden
pause 4
next b1
 
loop
end
 

Senden:
 
Data_=bit0:pulsout Clock,1
Data_=bit1:pulsout Clock,1
Data_=bit2:pulsout Clock,1
Data_=bit3:pulsout Clock,1
Data_=bit4:pulsout Clock,1
Data_=bit5:pulsout Clock,1
Data_=bit6:pulsout Clock,1
Data_=bit7:pulsout Clock,1
pulsout Strobe,1
 
return
 

 




Wichtig wäre noch zu erwähnen :

Der Befehl : GOSUB ist zwar ein netter Befehl , macht das System allerdings sehr sehr langsam !!
Wenn man also Muster hat , die so schnell als möglich ablaufen sollen , empfiehlt es sich immer GOTO einzusetzen !

Im Vergleich zum vorherigen Code hier das Beispiel mit GOTO :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 

' ###################################
' # Lauflicht => 2 LED kreuzen sich #
' ###################################
 

symbol Clock = c.0
symbol Data_ = pinc.1
symbol Strobe = c.2
 
let dirsc=%00000111
 
do
 
for b1=0 to 43
lookup b1,(0,0,128,128,1,1,64,64,2,2,32,32,4,4,16,16,8,8,16,16,4,4,32,32,2,2,64,64,1,1,128,128,0,0),b0
goto Senden
weiter:
pause 4
next b1
 
loop
end
 

Senden:
 
Data_=bit0:pulsout Clock,1
Data_=bit1:pulsout Clock,1
Data_=bit2:pulsout Clock,1
Data_=bit3:pulsout Clock,1
Data_=bit4:pulsout Clock,1
Data_=bit5:pulsout Clock,1
Data_=bit6:pulsout Clock,1
Data_=bit7:pulsout Clock,1
pulsout Strobe,1
 
goto weiter
 
 



In diesem kleinen Beispiel ist die Steigerung mit GOTO relativ gering , jedoch schon erkennbar.
Bei längeren Mustern oder komplexeren Aufgaben würde sich das wesentlich deutlicher zeigen.

Gosub ist programmiertechnisch eleganter , jedoch kann Eleganz niemals = Schnelligkeit heißen - ein Widerspruch ins sich selbst !
Also aufpassen was so in anderen Foren evtl. für Blödsinn verzapft wird.
Anstelle von lookup könnte man auch Read und Write nehmen , aber auch diese Eleganz geht auf Kosten des Tempos.
Die Funktion(en) table / tablecopy sind das tötlichste an Tempo schlechthin.
Erst in die Variablen kopieren , dann erst zum Senden schicken ist mind. 1 Schritt unnötig zu viel und kostet Zeit.

Meist gilt hier eh , doing by learning ..... selber testen und entscheiden |addpics|nqa-5-b541.jpg,nqa-6-76f4.jpg|/addpics|

 
BoomBoomMagic
Beiträge: 879
Registriert am: 24.01.2019


   

Grundschaltung
Servo per ADC steuern

Picaxe Editor 5.5.5 Download
Update auf Picaxe Editor 5.5.6 Download
Picaxe Editor 6.x.x.x Download
Manual1.pdf        -      Grundwissen Download
Manual2.pdf        -      Befehle Download
Manual3.pdf        -      Beispiele Download


Press [Backspace] for back to Menu


Counter
Xobor Forum Software ©Xobor.de | Forum erstellen
Datenschutz