Question regarding Dira and in/outa selecting pins
frank freedman
Posts: 1,983
in Propeller 1
Yeah, the subject line is rather lumpy, hard to say it in a short blurb.
In the Prop Ed manual and the Prop manual v1.2, there are examples of DIRA[3] or DIRA[9..11] etc, but there does not seem to be a way to set the pin range as a constant or otherwise in the Con block of the code. So, down in some object, there ends up being a line like
DIRA[0..3]~ ' set input pins for partx
but it would be nice to be able to have a Con block entry like
...
PartX_inp = something
and down in some part of the code a line like
DIRA[PartX_inp]~
INA[PartX_inp]
...
So, the question is did I miss something or is this not possible to do with the Prop1
Thanks
In the Prop Ed manual and the Prop manual v1.2, there are examples of DIRA[3] or DIRA[9..11] etc, but there does not seem to be a way to set the pin range as a constant or otherwise in the Con block of the code. So, down in some object, there ends up being a line like
DIRA[0..3]~ ' set input pins for partx
but it would be nice to be able to have a Con block entry like
...
PartX_inp = something
and down in some part of the code a line like
DIRA[PartX_inp]~
INA[PartX_inp]
...
So, the question is did I miss something or is this not possible to do with the Prop1
Thanks
Comments
Remember, too, that when writing to a group of outputs there is a binary transfer so it's usually best to be obvious. For example, if you have three pins that correspond to an RGB LED.
The first line makes the red LED output high when the second line sets the RGB pins to output mode.
Pin fields and bit fields exist in the P2 which simplify (in many cases) some of this stuff.
Bit 0 11110000
Bit 1 11101100
Bit 2 11011111
Bit 3 10001010
Bit 4 10001010
Bit 5 10001010 <====== from 8 MCP3201s into pins 1-8
Bit 6 10001010
Bit 7 10001010
Bit 8 10001010
Bit 9 10101010
Bit 10 11101010
Bit 11 11111110
Channel 0 0200 631mV
Channel 1 03FF 1261mV
Channel 2 0601 1894mV
Channel 3 07FF 2523mV
Channel 4 0A01 3157mV <======== Bit Array rotated into channels results of hex values match values on AD2 SPI capture
Channel 5 0C07 3796mV
Channel 6 0E03 4422mV
Channel 7 0FFF 5048mV
Clock Counts = 608656 <== ballpark PC counts. ~7ms, AD2 shows conversion time of ~1.5ms CS* pulse width
Assumptions
-- you're accessing all ADCs at the same time (i.e., CS and CLK are tied to all devices)
-- you have 8 MISO pins connected to the Propeller
If that's the case, I think you can simplify your code. As we say in Hollywood.... for your consideration:
Notes:
-- The CS and CLK pins should be defined using constants, and set to outputs (CLK low, CS high) at start-up
-- The LAST_CH constant is the index of your last channel.
-- ADCs are connected as a contiguous group in ascending order
Advice:
-- Don't use the ~~ and ~ operators; they are confusing and slower than straight assignments.
-- You're adding delays that are probably not necessary; that device can run 800kHz and you'll never hit that with bytecode Spin
Thank you Jon, that is some nice work. Difference between master and (probably) apprentice. Hence my doing a bit more brute force coding and refinement once working. Still more to learn. Will try this. Did not think of reading all the bits in the clock period. Also didn't know that ~ and ~~ was slower.
Your assumptions are spot on, I had a handful of this part to play with and even though this is on a mini, pin count isn't yet a problem.