Shop OBEX P1 Docs P2 Docs Learn Events
dira, and outa — Parallax Forums

dira, and outa

blind_botblind_bot Posts: 22
edited 2010-02-16 11:19 in Propeller 1
Hello, everyone.
·I recived my education propeller kit last week, and got it up and running fine. Today I started working threw lab 4. It explains how to use dira, and outa. Pretty easy stuff, still I have a question.
·In the text it shows how you can do the following:
········ dira[noparse][[/noparse]4] := 1, and the same goes for outa. It latter shows how you can use more than one pin in the same line by doing the following.
·········· dira[noparse][[/noparse]4..6] :=1, what I would like to know is if it is possible to do more than one pin in this way, say··· dira[noparse][[/noparse]4..6..8]?? When I tryed it I got a error, so I had to use only two pins in this way and then add a second line containg the dira command for the remaing pin.

·· I am very sorry to be asking for something so simple. Thank you very much, Duane
·······

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
00100000

Comments

  • Bill HenningBill Henning Posts: 6,445
    edited 2010-02-16 02:19
    dira[noparse][[/noparse]4..6] actually mins 4,5,6 - the .. indicates a range

    you could do

    dira := %10101000 ' make pins P4, P6, P8 outputs
    blind_bot said...
    Hello, everyone.
    I recived my education propeller kit last week, and got it up and running fine. Today I started working threw lab 4. It explains how to use dira, and outa. Pretty easy stuff, still I have a question.

    In the text it shows how you can do the following:

    dira := 1, and the same goes for outa. It latter shows how you can use more than one pin in the same line by doing the following.

    dira[noparse][[/noparse]4..6] :=1, what I would like to know is if it is possible to do more than one pin in this way, say dira[noparse][[/noparse]4..6..8]?? When I tryed it I got a error, so I had to use only two pins in this way and then add a second line containg the dira command for the remaing pin.



    I am very sorry to be asking for something so simple. Thank you very much, Duane
    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    www.mikronauts.com E-mail: mikronauts _at_ gmail _dot_ com 5.0" VGA LCD in stock!
    Morpheus dual Prop SBC w/ 512KB kit $119.95, Mem+2MB memory/IO kit $89.95, both kits $189.95 SerPlug $9.95
    Propteus and Proteus for Propeller prototyping 6.250MHz custom Crystals run Propellers at 100MHz
    Las - Large model assembler Largos - upcoming nano operating system
  • Mike GreenMike Green Posts: 23,101
    edited 2010-02-16 02:24
    The "4..6" is a range of pins (in that order). Think of it as "four through six". You can't have more than one range of pins, but you can have other ranges. OUTA[noparse][[/noparse] 4..8 ] is bits four through eight of the OUTA register. If you write it the other way, the order of the bits is reversed like OUTA[noparse][[/noparse] 8..4 ] is bits eight through four of the OUTA register.

    Writing OUTA[noparse][[/noparse] 1..2 ] := %01 sets bit 1 of OUTA to zero and bit 2 of OUTA to one. Writing OUTA[noparse][[/noparse] 2..1 ] := %01 sets bit 2 of OUTA to zero and bit 1 of OUTA to one.
  • blind_botblind_bot Posts: 22
    edited 2010-02-16 02:24
    Thanks I'll try that..

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    00100000
  • blind_botblind_bot Posts: 22
    edited 2010-02-16 02:47
    Would it be possible to havew a range of say [noparse][[/noparse]4..8] hAVEING PINS 4,6,8 high? I tryed dira[noparse][[/noparse]4..8] := %10101 however instead of having pins 4,6,8 high... ended up with 4,5,6

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    00100000
  • nohabnohab Posts: 96
    edited 2010-02-16 09:45
    To have 4,6,8 high you need two statements, this should work
    dira[noparse][[/noparse]4..8]:=%10101
    outa[noparse][[/noparse]4..8]:=%10101
    In the example above, pin 5 and 7 will be inputs.·If you want these to be·output low, use this instead
    dira[noparse][[/noparse]4..8]:=%11111
    outa[noparse][[/noparse]4..8]:=%10101



    Post Edited (nohab) : 2/16/2010 9:51:31 AM GMT
  • JRetSapDoogJRetSapDoog Posts: 954
    edited 2010-02-16 11:19
    Right, make sure to use outa after configuring the pin with dira.· Remember that dira will just configure the type=mode=behavior for the pin, either as a so-called high-impedence input or as an output "capable" of either 0 or 3.3 volts (but only one of those two modes (input or output)·at any one time, though it may be subsequently changed if desired).· However,·dira does not set the actual output voltage level (0V/3.3V), just the pin capability.· That is, if you configure a pin for output with dira, that doesn't at all automatically make it high (it's low by default), but just gives it the ability to go/be high if told to do so, or to go/be low if told to do that (as opposed to high-impedence for an input, which is kind of like a third logic state, neither low nor high but capable of receiving an incoming signal).· Anyway, to actually go high on the pin, you'd still need to use outa to set it high (in addition to configuring it as an output with dira at some point prior). Afterwhich, you could set the pin to low or high at will or repeatedly toggle it (such as to flash an LED) using outa as many times as needed, but, you'd only configure it once with dira·(though you could later re-configure it with dira if needed, such as to an input).·

    So, yeah, having such a range that you mentioned should be no problem at all.· You can have any combination that you want.· I presume you can have multiple such statements scattered throughout your code (though I'm a newbie as well so another can set us straight).· With assembler, you'd need to configure/set the behavior of all 32 configuration bits/output pins at once (though still configuring first·and later setting at will as desired).· But SPIN lets you configure/set them individually or in groups, and break things up into multiple statements if desired, hiding the necessity of configuring/setting all 32 bits/pins at once.· So, firstly, make sure you are following up your dira direction configuration with an outa statement somewhere, as nohab said.· You probably learned that in the labs, but may have forgotten or neglected to do so along the way.· For simple applications, you'll likely just configure the pins once with dira (as you probably won't need to "turn the pin directions" around), but you'll probably need to execute outa statements multiple times, such as to blink·one or more·LEDs or to show the status of something (otherwise, you'd just plug in a light and call it a day and not need a microcontroller).·

    So configure once with dira then set as many times as needed with outa.· Then, if you're still not seeing what you expect, you might want to check again to see if those results that you observed/reported are what you are "really" getting.· Also, perhaps other code is "overriding" your configurations or settings later on.· That is, perhaps other code subsequently has changed things, so check·all the code.· So, if you've configured the pins with dira AND you've used an outa statement...but things still don't seem to be working, then there's either something else at play or you're "wrong about being wrong" (something that often happens).· Remember to test that your tests are being conducted properly...or you'll think something isn't working when, in fact, it is working (or would be if not for something else getting in the way), or vice-versa.· You might even have pins cross- or mis-wired, such that what you think you're seeing is not really what's happening.· So, check your wiring.· Check everything!· Hopefully, you've just temporarily forgotten to use outa (after configuration with dira), but it could be something else.· Have confidence!· You're on the right track in continuing to experiment and to ask here.· Figure out the problem and get back to us with an update (for newbies like me), or let us know what you've tried and someone will point you in the right direction sooner or later (usually sooner than later, too).· Good luck.· Actually, "luck" is just a matter of continuing to try things.· Just be careful not to connect a high output to a low output...as that could/would blow your Propeller (something I expect I will do at some point), and that kind of luck you don't need.·
Sign In or Register to comment.