Warum blinkt's nicht?

Fragen zu Programmiersprachen und Software für den Hive und die Propellerchips
Antworten
NJO
Beiträge: 68
Registriert: So 23. Feb 2014, 14:09
Wohnort: Aachen

Warum blinkt's nicht?

Beitrag von NJO »

Hallo, bin gerade aus dem Urlaub zurück und habe mir vorgenommen, mich mit SPIN auseinandersetzen. Da stellt sich auch gleich die erste Frage. Unter den Testprogrammen für Bellatrix gibt es das start-blinky.spin:

CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000
LED = 24 'HBeat-LED ist an Port 24
PUB blinky
dira[LED] := 1 'LED-Port auf Ausgabe schalten

repeat
outa[LED] := 1 'LED ON
waitcnt(cnt + CLKFREQ) '1 Sekunde warten
outa[LED] := 0 'LED OFF
waitcnt(cnt + CLKFREQ) '1 Sekunde warten

Die Funktionsweise ist mir klar. Im Buch 'Programming the propeller with spin' finde ich folgendes Listing:

{{12 Sep 09 Harprit Sandhu BlinkLED.spin Propeller Tool Ver. 1.2.6 Chapter 13 Program 1
This program turns an LED ON and OFF, with a programmable set delay. It demonstrates the use of methods in an absolutely minimal way. The clock is running at 10 MHz. Define the constants we will use. There are no variables in this program.
}}
CON
_CLKMODE=XTAL1 + PLL2X 'The system clock spec
_XINFREQ = 5_000_000 'the crystal frequency
inv_high =0 'define the inverted High state
inv_low =1 'define the inverted Low state
waitPeriod =5_000_000 'about 1/2 sec switch cycle
output_pin =27 ' habe ich auf 24 gesetzt
'High is defined as 0 and low is defined as a 1 because we are using an
'inverting buffer on the Propeller output.
PUB Go
dira [output_pin]~~ 'sets pin to an output line with ~~
outa [output_pin]~~ 'makes the pin high
repeat 'repeat forever, no number after repeat
turnOff_LED 'method call
wait 'method call
turnOn_LED 'method call
wait 'method call
PRI turnOn_LED 'method to set the LED line high
outa[output_pin] :=inv_high 'line that actually sets the LED high
PRI turnOff_LED 'method to set the LED line low
outa[output_pin] :=inv_low 'line that actually sets the LED low
PRI wait 'delay method
waitCnt(waitPeriod + cnt) 'delay is specified by the waitPeriod

Zur Anpassung habe ich den output_pin =24 gesetzt und das Progrämmchen in den Bellatrix-RAM geladen.
Warum blinkt die HBeatLED nicht so wie ich es eigentlich erwarte, sondern geht nur genau 1x an und wieder aus?

Gruß Norbert
Drohne 400
Benutzeravatar
PIC18F2550
Beiträge: 2831
Registriert: Fr 30. Sep 2011, 13:08

Re: Warum blinkt's nicht?

Beitrag von PIC18F2550 »

Verwende bitte mal die Formatierung für Code.
Sonst ist der Code nicht lesbar.
Die einrückungen sind wichtig.
Gruß
PIC18F2550

drone265/278
Barbarus hic ergo sum, quia non intellegor ulli.
Ein Barbar bin ich hier, da ich von keinem verstanden werde.
ʎɐqǝ ıǝq ɹnʇɐʇsɐʇ ǝuıǝ ɹǝpǝıʍ ǝıu ǝɟnɐʞ ɥɔı ´uuɐɯ ɥo
Benutzeravatar
zille9
Beiträge: 399
Registriert: Do 4. Okt 2012, 21:56
Wohnort: Berlin

Re: Warum blinkt's nicht?

Beitrag von zille9 »

NJO hat geschrieben: repeat
outa[LED] := 1 'LED ON
waitcnt(cnt + CLKFREQ) '1 Sekunde warten
outa[LED] := 0 'LED OFF
waitcnt(cnt + CLKFREQ) '1 Sekunde warten
versuche mal mit Einrücken

Code: Alles auswählen

repeat
           outa[LED] := 1 'LED ON 
           waitcnt(cnt + CLKFREQ) '1 Sekunde warten
           outa[LED] := 0 'LED OFF
          waitcnt(cnt + CLKFREQ) '1 Sekunde warten
Computer lösen die Probleme, die man ohne sie gar nicht hätte!
NJO
Beiträge: 68
Registriert: So 23. Feb 2014, 14:09
Wohnort: Aachen

Re: Warum blinkt's nicht?

Beitrag von NJO »

Sorry, die Formatierung ging leider beim Kopieren verloren, hier korrekt:

Code: Alles auswählen

{{12 Sep 09 Harprit Sandhu BlinkLED.spin Propeller Tool Ver. 1.2.6 Chapter 13 Program 1
This program turns an LED ON and OFF, with a programmable set delay. It demonstrates the use of methods in an absolutely minimal way. The clock is running at 10 MHz. Define the constants we will use. There are no variables in this program. 

}}
CON
    _CLKMODE=XTAL1 + PLL2X 'The system clock spec
    _XINFREQ = 5_000_000 'the crystal frequency

    inv_high =0 'define the inverted High state
    inv_low =1 'define the inverted Low state
    waitPeriod =5_000_000 'about 1/2 sec switch cycle
    output_pin =27 ' habe ich auf 24 gesetzt

'High is defined as 0 and low is defined as a 1 because we are using an
'inverting buffer on the Propeller output.

PUB Go
    dira [output_pin]~~ 'sets pin to an output line with ~~
    outa [output_pin]~~ 'makes the pin high
    repeat 'repeat forever, no number after repeat
         turnOff_LED 'method call
         wait 'method call
         turnOn_LED 'method call
         wait 'method call

PRI turnOn_LED 'method to set the LED line high
    outa[output_pin] :=inv_high 'line that actually sets the LED high
PRI turnOff_LED 'method to set the LED line low
    outa[output_pin] :=inv_low 'line that actually sets the LED low
PRI wait 'delay method
    waitCnt(waitPeriod + cnt) 'delay is specified by the waitPeriod
Drohne 400
Benutzeravatar
drohne235
Administrator
Beiträge: 2284
Registriert: So 24. Mai 2009, 10:35
Wohnort: Lutherstadt Wittenberg
Kontaktdaten:

Re: Warum blinkt's nicht?

Beitrag von drohne235 »

Bei mir blinkt es. Die Einstellungen zur Taktfrequenz (_CLKMODE = XTAL1 + PLL16X) sind zwar falsch, aber es blinkt.
"Ob Sie denken, dass Sie es können, oder ob Sie denken, dass Sie es nicht können - in beiden Fällen haben Sie recht." Henry Ford
NJO
Beiträge: 68
Registriert: So 23. Feb 2014, 14:09
Wohnort: Aachen

Re: Warum blinkt's nicht?

Beitrag von NJO »

Ich habe das obere Listing noch mal ohne Einrückungen versucht, ohne Erfolg. Die Einrückungen bringen es scheinbar. Ich bin vermutlich etwas durchs SQL verdorben, da ist die Formatierung ziemlich wurscht, wenn man mal was auf die Schnelle schreibt. Muss ich demnächst beachten.
Drohne 400
Benutzeravatar
Micha
Beiträge: 812
Registriert: Sa 24. Mär 2012, 21:45
Wohnort: Merseburg
Kontaktdaten:

Re: Warum blinkt's nicht?

Beitrag von Micha »

in SPIN hat die Einrückung syntaktische Bedeutung.
Das ist sehr ungewöhnlich (ich persönlich mag den Ansatz nicht), aber daran muss man sich eben halten wenn man was mit SPIN machen möchte.
Also vonder Sache här tätch jetz ma behaupten "Mischn ägomplischd" un so...
Benutzeravatar
zille9
Beiträge: 399
Registriert: Do 4. Okt 2012, 21:56
Wohnort: Berlin

Re: Warum blinkt's nicht?

Beitrag von zille9 »

Ich finde die Einrückungs-Pflicht eigentlich sehr vorteilhaft, zwingt sie einem doch ein Mindestmass an Struktur im Programm auf.
Gerade Schleifen oder Abfragen werden sehr schnell unübersichtlich, wenn die Bereiche, auf die sich die Schleife oder Abfrage bezieht optisch nicht erkennbar ist.
Computer lösen die Probleme, die man ohne sie gar nicht hätte!
Antworten