High output from propeller
anita1984
Posts: 23
Hi forum,
How i can make a pin 3·output high in Spin?
is true like this ? or their is more inteligent way .
Thank you in advance,
Anita
How i can make a pin 3·output high in Spin?
is true like this ? or their is more inteligent way .
PUB PinHigh dira[noparse][[/noparse]3]~~ repeat !outa[noparse][[/noparse]3] waitcnt(cnt)
Thank you in advance,
Anita
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
This program will make pin 3 high, wait for ~54 seconds and then make pin 3 low. After another 54 seconds it will repeat itself.
This is all you need to make and keep a pin high, where x is your pin:
also be aware that if you want to do something after setting PinHigh, it will not return, as it has a infinite repeat loop in there
Hope this helps,
Baggers.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
http://www.propgfx.co.uk/forum/·home of the PropGFX Lite
·
Of course your demo code would have a repeat somewhere otherwise the cog will go to sleep and the pin will float.
P.S. substitute your pin number for x
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
Would not waitcnt(cnt) stall the program for about 54 seconds assuming a clock frequency of 80MHz?
My understanding is that cnt, at some arbitrary value, would have to come full circle before the same value showed up. There are 2^32 cnt values. The propeller, running at 80MHz, would take just under 54 seconds to run through these values.
After approximately 54 seconds, the value of cnt is equal to the value stored in waitcnt(cnt) and the loop continues.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
*Peter*
Pub Pin3High
dira[noparse][[/noparse] 3 ]:= 1 'Set pin 3 to be an output
outa[noparse][[/noparse] 3 ]:= 1 ' set pin 3 to logic high
repeat ' just repeat so prop does not go to sleep
Is this ok and why would I want to make it more fancy ????
Thanks
Post Edited (mikediv) : 10/14/2009 5:44:53 PM GMT
this forum-software eats up square-brackets as change fontsize of you don't insert spaces after each opening squarebracket
and please use the (code) (/code) commands (with square-brackets instead of round braclets to create this style
that's OK and that way that is easiest to understand
best regards
Stefan
Of course if I had to turn on more than 1 output high or low I would use the [noparse][[/noparse] 1..8 ] or even the ~~ but for very basic stuff is it ok to use the most basic method?
I watch how you pros are doing it even the simple stuff and to be honest its far more complex than I would have thought to use so in progressing to learn Spin should I adapt the way you guys are programing I notice that a lot of you
would use somehting like
Pub Pin
dira[noparse][[/noparse] pin ]
then use the Pin var instead of the actual pin number is it the proper way I/We should be learning?
.
Thanks again
Yes of course use the basic method. It is easier to read and understand. Once you have practised coding outa [noparse][[/noparse] 3 ]~~ some hundred times it will be easy for YOU to understand it
but not for other newbees.
The special methods are only needed if you need maximum speed or maybe squeezing some bytes of RAM out of the code if you run out of RAM
in all other cases it's a personal decision to use outa [noparse][[/noparse] 3]~~ or something like that.
One rule about using methods is every PUB should do ONE thing and have a SELF-EXPLAINING name.
For setting up a few IO-pins I would say it is personal taste if you write it is own method for it.
The sense of methods is to save codelines if you need code in multiple places with only slight changes and these changes can be handled by parameters
Example start a serial driver
ser.start(Rx-Pin, Tx-Pin, mode, baudrate)
serial connections are often needed but for different Tx/Tx-pins, and baudrate. So Rx/Tx-pin baudrate are PARAMETERS
or
ser.str(@MyString1)
ser.str(@MyString5) etc. etc.
some professionals like to code by the maxime "save as much time as possible and type as less keystrokes as possible "
I would like to add "and loose lot's of time for decoding your super-compact-encrypted code a half year later !"
SPIN is a structured language and my opinion about REAL professionalism is: "code it as clear and easy to understand as possible".
Let's assume you have some special kind of LCDisplay which needs a seven-byte sequence to set the cursor to line x columm y
by direct coding you would have to code
So with direct coding you would have to code ALL these seven lines again and again
That is a case where coding a method would be good
then at all places where you want to set the cursor you code just ONE single line with a self-explaining command
If you have additional questions about how coding - whatever - can be done elegant AND easy to understand ask it ! That's what this forum is for
best regards
Stefan
-Phil
but still you have to code three lines of code and they are not self-explaining. (half a year later you scratch your head asking what the heck was the bytesequence 27,104,248,21,254 ???
was it clearing the display ? or cursor-blink-mode ? ... hm or overwrite mode ? ...
You could add a comment but I prefer a Pub with a name that is self-commenting self-explaining
SetCursorXY(2,10) says it all without an additional comment which might be left out because of lazyness
best regards
Stefan