Multi cogs outa ina problem
Mart1970
Posts: 23
Hello
first cog i have a outa = (0b1 << 17) led;
In second cog i read pin 12 input state u = ina >> 12;
everytime the led flash i can't read port 12 ;
Why is that.
first cog i have a outa = (0b1 << 17) led;
In second cog i read pin 12 input state u = ina >> 12;
everytime the led flash i can't read port 12 ;
Why is that.
Comments
pin 17 = output
second cog DIRA = (0b01101 << 8);
pin 12 = input;
a hexnumber: (should be written as "$B1" in Spin)
a binary number? (should be written as "%1" in Spin)
variable-assignments are coded with ":="
(DirA and OutA are handled like variables)
DirA[12] := 0 zero for Input
DirA[17] := 1 one for Output
or is is just a somehow sloppy stile of writing postings?
maybe it's even C-code?
For a detailed analysis attach your complete code
best regards
Stefan
it's C Simple ide
Yes, theirs a 3.3 vdc plus signal connected to pin 12.
I'd also encourage you to make use of Simple's low(), high(), input() and set_direction() functions if applicable. Since you're doing the bit-shifting anyway, there won't be any performance decrease, but the legibility will increase significantly. The API docs for the functions are available here (and SimpleIDE too now I think?)
the simple ide high or low and set_directions are to slow for the app i have running.
Ah - I see. I forgot those functions did a few extra instructions as well. I know this is off topic, but if you need speed, I'd encourage you to use a bit mask. Something like...
Anyway, would you might posting more of your code so we can get a better context? You might also need pull up/down resistors on your input pin. Fast-changing wires near floating inputs can have weird effects.
What do you mean "can't read port 12". Do you mean "pin 12 reads the wrong value"? If so you
probably have interference between the LED output and the signal you are trying to measure/sense?
I have to try the mask (but it will to monday i can try it).
Anyway when i try it out and test it on the scoop everything is working fine when the led is not flashing.
when the led is flashing once every second i can see on the scoop that i lose the signal at pin 12.
when pin 17 is high
I can tel you that the signal is coming from a bidirectioal mosfet (pin 12)
But i think that's not the problem.
I think it has something to do with making pin 17 high.
I also changed pin 17 to 16 but thats created the same problem.
1. are you sure you run the code in different cogs?
2. are you sure you set dira in the cog(s) executing the code?
are you aware that your value in u will not represent the single bit of pin 12, but the binary value of pin 31 up to pin 12?
so if you test for pin 12 high you can not check for 0/1 but need to mask out all bits above pin 12 to check for pin12 set/unset.
just some common mistakes I did.
Enjoy!
Mike
I think your right, i read u = ina << 12;
afther that i check if (u == 1)
But that is not working becaus i read pin 12 to 31.
Thats why it's not working because when the led is flashing
the value of u will be greater then 1.
How do i have to do it for only read pin 12.
something like this
u = (ina << 12) & 0x01;
That would be exactly it. You can speed things up by treating it like a boolean and, instead of
you can do
I try everything tomorrow.
I let you know.