Returning more than one value from method
stevovee
Posts: 18
To give a little background on my project. I already have a PCB made so I can't really go change the schematic much and I'm pretty much out of IO pins. I'm interfacing with two max6675 thermocouple chips. In my schematic to save pins I have the CS and SCK pins connected together and then each chip has a separate IO pin for the SO pin. Individually they both work fine, i'm using this object http://obex.parallax.com/object/566
But I want to get to where I can pull out temp information from both thermocouples. I'm using the shiftin command from that object.
the CS and SCK pins should stay the same. I can add a Dpin2 to the inputs for this function and write in a value2 into the function but I can't figure out how to pass 2 values out of this function. Anyone have any ideas?
But I want to get to where I can pull out temp information from both thermocouples. I'm using the shiftin command from that object.
PUB SHIFTIN(Dpin, Cpin, Mode, Bits)|Value dira[Dpin]~ ' make dpin input outa[Cpin] := ClockState ' set initial clock state dira[Cpin]~~ ' make cpin output Value~ ' clear output if Mode == 0 'MSBPRE repeat Bits value := (Value << 1) | ina[Dpin] PostClock(Cpin) if Mode == 1 'LSBPRE repeat Bits +1 Value := (Value >> 1) | (ina[Dpin] << 31) PostClock(Cpin) value >>= (32 - Bits) if Mode == 2 'MSBPOST repeat Bits PreClock(Cpin) Value := (Value << 1) | ina[Dpin] if Mode == 3 'LSBPOST repeat Bits + 1 PreClock(Cpin) Value := (Value >> 1) | (ina[Dpin] << 31) Value >>= (32 - Bits) return Value
the CS and SCK pins should stay the same. I can add a Dpin2 to the inputs for this function and write in a value2 into the function but I can't figure out how to pass 2 values out of this function. Anyone have any ideas?
Comments
Duane J
You could do it the way you've wired it but then you need to come up with your own driver. Doing it the way you've wired it wouldn't be too hard but I'm not sure if you have the experience to do it that way yet.
As Mike said, it doesn't work that way. Only one value is returned.
what If i shift both into one 32bit number and then split it up in my code?
this is basically the code I'm calling to bring in the temperature now using the spi object mentioned above
and then i'm in mode zero so this is the section of the object that i'm referring to
what if i made it so I shift in both 16 bit values, then change the object to combine them and output onen 32bit number which I can split up in code
What is the operator for doing this? I was just going to shift one of them 16 bits one direction and then the other 16 bits the other direction
-Phil
and then in my main code I did this to get two separate temps which are othertemp and celsius
Great minds think alike! -- I do that, too!
If your temperatures are in twos complement form you will want to do an arithmetic right shift (~> instead of >>) on your results to propagate the sign for negative values.
-Phil