Seite 1 von 1

Warum blinkt's nicht?

Verfasst: Sa 12. Jul 2014, 13:55
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

Re: Warum blinkt's nicht?

Verfasst: Sa 12. Jul 2014, 14:03
von PIC18F2550
Verwende bitte mal die Formatierung für Code.
Sonst ist der Code nicht lesbar.
Die einrückungen sind wichtig.

Re: Warum blinkt's nicht?

Verfasst: Sa 12. Jul 2014, 14:04
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

Re: Warum blinkt's nicht?

Verfasst: Sa 12. Jul 2014, 14:33
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

Re: Warum blinkt's nicht?

Verfasst: Sa 12. Jul 2014, 15:39
von drohne235
Bei mir blinkt es. Die Einstellungen zur Taktfrequenz (_CLKMODE = XTAL1 + PLL16X) sind zwar falsch, aber es blinkt.

Re: Warum blinkt's nicht?

Verfasst: Sa 12. Jul 2014, 15:59
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.

Re: Warum blinkt's nicht?

Verfasst: Sa 12. Jul 2014, 17:52
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.

Re: Warum blinkt's nicht?

Verfasst: Sa 12. Jul 2014, 20:37
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.