Shop OBEX P1 Docs P2 Docs Learn Events
Multi cogs outa ina problem — Parallax Forums

Multi cogs outa ina problem

Mart1970Mart1970 Posts: 23
edited 2015-03-18 02:40 in Propeller 1
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.

Comments

  • ksltdksltd Posts: 163
    edited 2015-03-14 03:24
    To what values are you setting the dira register in each thread?
  • Mart1970Mart1970 Posts: 23
    edited 2015-03-14 03:35
    first cog DIRA = (0b1 << 17);
    pin 17 = output

    second cog DIRA = (0b01101 << 8);
    pin 12 = input;
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-03-14 03:59
    Is there anything connected to pin 12?
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-14 04:42
    I'm not sure what you mean by "0b1" ist this

    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
  • Mart1970Mart1970 Posts: 23
    edited 2015-03-14 07:14
    StefanL38 wrote: »
    I'm not sure what you mean by "0b1" ist this

    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
  • Mart1970Mart1970 Posts: 23
    edited 2015-03-14 07:15
    mindrobots wrote: »
    Is there anything connected to pin 12?

    Yes, theirs a 3.3 vdc plus signal connected to pin 12.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-03-14 07:27
    It looks like you're writing comments next to your code, but not using comment marks (like // or /* */). It does make it a little harder to read and therefore help you when we can't see the actual code that you're talking about.

    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?)
  • Mart1970Mart1970 Posts: 23
    edited 2015-03-14 07:35
    It looks like you're writing comments next to your code, but not using comment marks (like // or /* */). It does make it a little harder to read and therefore help you when we can't see the actual code that you're talking about.

    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.
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-03-14 07:46
    Mart1970 wrote: »
    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...
    const unsigned int LED_MASK = 1 << 17;
    
    void myFunc() {
      // Do stuff...
      OUTA = LED_MASK;
      // Do more stuff....
    }
    

    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.
  • Mark_TMark_T Posts: 1,981
    edited 2015-03-14 08:54
    Mart1970 wrote: »
    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.

    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?
  • Mart1970Mart1970 Posts: 23
    edited 2015-03-14 12:36
    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...
    const unsigned int LED_MASK = 1 << 17;
    
    void myFunc() {
      // Do stuff...
      OUTA = LED_MASK;
      // Do more stuff....
    }
    

    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.

    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.
  • msrobotsmsrobots Posts: 3,709
    edited 2015-03-14 17:16
    2 questions.

    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?
    In second cog i read pin 12 input state u = ina >> 12;

    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
  • Mart1970Mart1970 Posts: 23
    edited 2015-03-15 02:46
    msrobots wrote: »
    2 questions.

    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;
  • DavidZemonDavidZemon Posts: 2,973
    edited 2015-03-15 06:44
    Mart1970 wrote: »
    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
    u = (ina << 12) & 0x01;
    if (u == 1) {
      // do stuff
    }
    

    you can do
    u = ina & 0x1000;
    if (u) /* or if you prefer, if (u != 0) */ {
      // do stuff
    }
    
  • Mart1970Mart1970 Posts: 23
    edited 2015-03-15 11:02
    thanks SwimDude

    I try everything tomorrow.

    I let you know.
  • ozpropdevozpropdev Posts: 2,792
    edited 2015-03-15 18:09
    One small detail
    u = (ina [color=red]<<[/color] 12) & 0x01;
    should be
    u = (ina [color=blue]>>[/color] 12) & 0x01;
    
  • Mart1970Mart1970 Posts: 23
    edited 2015-03-18 02:40
    Hello everybody thanks for all the help it's working fine now
Sign In or Register to comment.