SX Pin numbering
Hi,· I have a question on SX/B.· When using the Basic stamp I could use
IN3 to·use pin 3 as an input.· How do I do the same thing in SX/B?
Thanks
Post Edited By Moderator (Bean (Hitt Consulting)) : 2/22/2007 8:52:37 PM GMT
IN3 to·use pin 3 as an input.· How do I do the same thing in SX/B?
Thanks
Post Edited By Moderator (Bean (Hitt Consulting)) : 2/22/2007 8:52:37 PM GMT
Comments
On the SX pins are labeled by their port and position on that port.
For example: RB.0, RB.7, etc.
If you wanted to use pin RB.0 as an input you would do:
INPUT RB.0
IF RB.0 = 1 THEN
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
·
This will define pin RC.0 as "LED" and make it an output (saving you the trouble) so your program can do this:
Better yet, define constants for on and off like this:
... and then do this:
See how much easier that is to read/debug -- especially when giving your programs to others?
That's so well presented -- that even a hard-core "magic number" like me1 can get it.
Update --
·1·However unrepentant.·
Post Edited (PJ Allen) : 2/23/2007 2:58:05 AM GMT
Post Edited (SailerMan) : 3/2/2007 12:14:51 PM GMT
Is this what you're trying to do?
Update -- Forgot to add that this much compiles.· It's disallowing combining an array and Pin Numbering.· I think that you'll need to add input/output after the Pin Number, too [noparse]/noparse]i.e. [i]Sensor Pin RC.3 INPUT[/i
Post Edited (PJ Allen) : 3/2/2007 3:07:33 AM GMT
I will look into the crashing, it should cause an error.
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Coming soon! Propeller based OSD module www.hittconsulting.com
·
Is there a good way to do what I'm trying to do in the above code?
I need to iterate through non sequential pins.
Regards,
Eric
You can use a bit mask.
It would be alot easier if you connected all the sensors to one port (either RB or RC).
Will the order change at runtime ? If not then just change the connections so they are in order.
Assuming you are using the RB port for all sensors, and the array bitPos holds the bit position of the sensor to pulse, you would do:
FOR temp = 0 TO 7
· mask = 1 << bitPos(temp)
· RB = RB XOR mask ' Invert bit
· PAUSE 25 ' PULSOUT x, 100, 25 = 25 mSec
· RB = RB XOR mask ' invert bit
NEXT
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Coming soon! Propeller based OSD module www.hittconsulting.com
·
I guess that I will have to spend some more time re-routing my board and just use Port RB. It seems the most Logical course of action... Thanks for your code snipet.
Regards,
Eric
· If you want to use both RB and RC then you just need to make "mask" a Word variable and use RBC.
· bitPos() elements can be from 0 (RB.0) to 15 (RC.7)
FOR temp = 0 TO 7
· mask = 1 << bitPos(temp) ' mask is a WORD variable
· RBC = RBC XOR mask ' Invert bit
· PAUSE 25 ' PULSOUT x, 100, 25 = 25 mSec
· RBC = RBC XOR mask ' invert bit
NEXT
· I always optimize my layouts and adjust the software to work. It's much easier to make a software mod, then a hardware mod.
· The drafting dept as work loves me because I don't show what pin a connection is to on the SX. I just say "It can be connected to any of these pins". It really freaks them out, they are not used to being able to do that. Then I always find lots of ways to simplify the layout after they do it, by using a different pin for something.
· Just don't forget about I2C pins, they must be in a specific order. I've got them backwards a couple times then the SX/B I2C commands don't work.
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Coming soon! Propeller based OSD module www.hittconsulting.com
Post Edited (Bean (Hitt Consulting)) : 3/2/2007 3:10:16 PM GMT
·So I should define an Array of Bit Positions.
What is the Best Way to load the Array with Bit Position info.
Am I thinking of this in the right way? I'd test it but I 'm not at home.
Regards,
Eric
Post Edited (SailerMan) : 3/2/2007 3:59:47 PM GMT
maybe, this is a bit off-topic here as I'll show examples in ASM here, and not in SX/B...
In general, I agree with Bean that assigning SX I/O pins to specific signals can be arbirtrary in most cases. Nevertheless, sometimes, it makes software design easier, or more compact when you use specific pins. For example, in a serial receiver code, you will often find the instruction
movb C, RxD
where RxD can be any port pin used as serial input. The movb instruction is a compound instruction, i.e. expanded to
sb RxD
clrb C
snb RxD
setb C
so it takes four program words, and four clock cycles for execution.
If you were using RB.7 as RxD input pin, for example, you could move the status of RxD into the C flag with just one instruction:
mov w, <<RB
This moves the left-rotated contents of RB into w but also rotates bit 7 of RB into the C flag.
You can also use RB.0, for example, together with
mov w, >>RB
Besides this, keep in mind that only the port B inputs allow for wake-up, and interrupts, and the RA pins can't be configured as Schmitt-Trigger but they have symmetric source/sink characteristics when configured as outputs.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
No, you just want to put the bit position VALUE into the array.
0 to 7 = RB.0 to B.7 ; 8 to 15 = RC.0 to RC.7
So:
PUT bitpos, 11, 10, 9, 8, 3, 2, 1, 0
Bean.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap used 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
SX-Video Display Modules www.sxvm.com
Coming soon! Propeller based OSD module www.hittconsulting.com
·
That was way over my head but thanks. [noparse]:)[/noparse]
Bean,
Great thanks for clarifying that for me.
Regards,
ERic
Post Edited (SailerMan) : 3/2/2007 4:38:52 PM GMT