Shop OBEX P1 Docs P2 Docs Learn Events
input sense to propeller problem — Parallax Forums

input sense to propeller problem

mklrobomklrobo Posts: 420
edited 2014-11-17 18:08 in Propeller 1
:innocent: Hello! I have a question...
condition: I put one cog putting a 10 Hz signal output to pin 0, then jumped that pin to
pin 1. I used an if/then condition to sense the voltage on pin 1, and count.
and it did not work. If I put a 3.3 volts there, it senses it. BUT, it will not
sense it from another pin, even it I make that pin high.
One cog is controlling and sensing/counting, the other is putting a high on a pin.
Question(s): Why will it not sense it? do I need more "sinking" power to make it see it?
Will this only work with counters in the cogs, becuase of a time limitation?
Do the logic, if/then processes, have a limit on time sense?
Programmed this in SimpleIDE. Have not tried Spin yet.
(reason for this; using spare Cogs for diagnosic reasons, to "calibrate" the main program.)
Thanks for your help.:smile:

Comments

  • Heater.Heater. Posts: 21,230
    edited 2014-11-16 09:48
    I don't understand what you have tried to write there but it sounds like you are toggling an output pin at 10Hz and the trying to read that pin from another cog. Perhaps by adding a jumper wire between the two pins.

    If so:

    The jumper wire is not needed. Pins are connected together internally so an output on a pin by one COG can be read by all the other COGS.

    I have done this before. I wanted to know how fast some code was running in a cog so I toggled a pin every time around it's loop. Another cog looked for changes in that pin measured the timing of the toggling. Worked a treat. The loop I was timing was going around at almost a mega Hz,
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-11-16 09:51
    You'll probably need to post your code. There's no reason why one I/O pin couldn't sense the other (when wired together) unless the hardware is damaged or there's an error in the code.
  • mklrobomklrobo Posts: 420
    edited 2014-11-16 10:15
    :innocent: ok, this is the code. I appreciate your help, I am about to cry here!
    This should have worked, with no problem, as the main part is removed from
    the tutorials.

    :nerd: Pin 0 is jumped to pin1. I have also changed the code to control and sense pin 0. It
    will not count in the "high" part. I did a for process, that called the blue function several times,
    and it still did not count. I measured the high/low transistion on a voltmeter, and the pin DID change.
    Must be something stupid I am doing, or not seeing.:frown:

    #include "simpletools.h" // Library include
    int x, z;
    int psl;
    void blue();
    int main() // Main function
    {
    psl = input(1);
    high(0);
    pause(100);

    blue();

    pause(1000);
    low(0);
    print("the value of x = %d",x);
    print("the value of z = %d",z);

    }
    void blue()
    {
    if (psl == 1) { x++; }
    if (psl == 0) { z++; }

    }
  • mklrobomklrobo Posts: 420
    edited 2014-11-16 10:19
    -also, I did have another cog generating a pulse and a steady high, but that did not work, So I backed up
    and simplified things as much as I could to eliminate errors, or oversights. :(
  • mklrobomklrobo Posts: 420
    edited 2014-11-16 10:22
    :nerd: Duane & Heater,

    Thanks for your help. Do you have any code you have made?
    If I use your code, and it does not work, it must be something physically that
    I am doing, or not doing.:frown:
  • cavelambcavelamb Posts: 720
    edited 2014-11-16 10:41
    I do not see where you have declared pin directions.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-11-16 11:00
    cavelamb wrote: »
    I do not see where you have declared pin directions.

    I'm not positive, but I think the "high" and "low" functions set the pins as outputs.

    I don't see any sort of loop.

    To me it looks like the input is read once and then after the input is read, the pin is set high but the input is not read again.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-11-16 11:06
    How about trying the code below?
    #include "simpletools.h"                      // Library include
    int x, z;
    int psl;
    void blue();
    int main()                                    // Main function
    { 
      while 1
      {
         
        high(0);
        psl = input(1);
        pause(500);
        
        blue(); 
        print("the value of x = %d",x);
        print("the value of z = %d",z);
        
        low(0);
        psl = input(1);
        pause(500); 
    
        blue();
        print("now the value of x = %d",x);
        print("now the value of z = %d",z);
      }
    }
    void blue()
    {
      if (psl == 1) { x++; }
      if (psl == 0) { z++; }
            
     }
    
  • mklrobomklrobo Posts: 420
    edited 2014-11-16 11:13
    :smile: Hello!
    cavelamb,
    I will look into declaring I/O pin direction. Appreciate your tip.

    Duane Degn,

    The setting of the pins was what I was worried about, that is why I set 2 pins apart when
    doing this. I will revamp my program to include the loops. I tried that before, and it
    did not work. I reduced the program to bare bones, to try to decipher what-in-the-world
    is going on. This problem should not have happened. I will try other pins, to see if the effect
    is the same.
    I will repost the new code.:innocent:

    Thanks.
  • mklrobomklrobo Posts: 420
    edited 2014-11-16 11:18
    Duane Degn wrote: »
    How about trying the code below?
    #include "simpletools.h"                      // Library include
    int x, z;
    int psl;
    void blue();
    int main()                                    // Main function
    { 
      while 1
      {
         
        high(0);
        psl = input(1);
        pause(500);
        
        blue(); 
        print("the value of x = %d",x);
        print("the value of z = %d",z);
        
        low(0);
        psl = input(1);
        pause(500); 
    
        blue();
        print("now the value of x = %d",x);
        print("now the value of z = %d",z);
      }
    }
    void blue()
    {
      if (psl == 1) { x++; }
      if (psl == 0) { z++; }
            
     }
    

    Thanks! looks like you are were thinking the same thing I was, as to let the pins set up first, then check
    the iterations. If this works, I will build a for loop into this to give a count of "on" pulse, and a count of "off" pulse.
    I have read that the Cogs have 2 counters designed to trigger on, on and off, and release counts to the PHSA register.
    Have not got that far, yet. Trying to get past this.:frown:
  • mklrobomklrobo Posts: 420
    edited 2014-11-17 05:54
    Duane Degn wrote: »
    How about trying the code below?
    #include "simpletools.h"                      // Library include
    int x, z;
    int psl;
    void blue();
    int main()                                    // Main function
    { 
      while 1
      {
         
        high(0);
        psl = input(1);
        pause(500);
        
        blue(); 
        print("the value of x = %d",x);
        print("the value of z = %d",z);
        
        low(0);
        psl = input(1);
        pause(500); 
    
        blue();
        print("now the value of x = %d",x);
        print("now the value of z = %d",z);
      }
    }
    void blue()
    {
      if (psl == 1) { x++; }
      if (psl == 0) { z++; }
            
     }
    

    :lol: Happy day! Happy day! :lol:
    Duane, You are a Genuis! It worked.
    The trick here is; The input MUST be initalized every cycle, or it is reset, even if you
    declare it.(?) Do not know why, but this program works, and can be used to count fast
    pulses, if necessary. How fast, I do not know at this time. I expect there will be a
    limit, and if faster counts are desired, the internal counters, A & B, that are built into
    every COG, will have to be used. For that, I will HAVE to use assembly to run in
    2K of internal COG memory, to achieve 20 MIPs. (In the manual) . Without the
    counters, I project obtaining counting speeds up to 4 MIPs. That is fine for my
    needs, at this time. Thanks again!:lol:
  • mklrobomklrobo Posts: 420
    edited 2014-11-17 06:10
    :cool: Here is the pulse counting program, revamped;(in C, if anybody wants it)

    #include "simpletools.h" // Library include
    int x,z,y;
    int psl;
    void blue();
    int main() // Main function
    {

    square_wave(0, 0, 9600);
    // while(1)

    for(y = 0; y < 500;y++)
    {

    psl = input(1);
    pause(5);
    blue();
    // print("the value of x = %d",x);
    // print("the value of z = %d",z);
    pause(5);
    // pause(1000);
    }
    print("the value of x = %d",x);
    print("the value of z = %d",z);
    }
    void blue()
    {
    if (psl == 1) { x++; }
    if (psl == 0) { z++; }
    }
    ***********
    This counts a pulse from a 9600 cycle square wave. This does not take up much space, and
    is pretty straightforward. Can use it to count pulses. Thanks again!
    :nerd:
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-11-17 06:38
    mklrobo wrote: »
    The input MUST be initalized every cycle, or it is reset, even if you
    declare it.(?) Do not know why,

    The variable holds the value of the input at the time the assignment is made. This is the same as with Spin.

    It's similar to setting one variable to another.
    x = y:
    

    If, after the above assignment, the value of "y" changes, the value of "x" won't also change. The value of "x" remains the value "y" had been at the time of the assignment. The same is true for the value of "psl", it remains the value of "input(1)" even if "input(1)" changes.

    While experimenting with some encoders I wrote some simple Spin and PASM code to count pulses. I counted the pulses using two different techniques. One section of the code counted the pulses using the cogs counters (I followed the example from the PEK pdf) and the other section of code was written in PASM. I don't know if you're interested in a Spin solution to counting pulses, but if so you could check out the code attached to this post.

    It's also possible to count pulses using waitpxx statements but I didn't think of this possibility when writing my example code.

    Edit: BTW, it's much easier to read code if you use code tags. To get " x = y;" to show up in code blocks above, I used the text:

    [noparse]
    x = y;
    
    [/noparse]

    When these code tags are used, the text between them shows up properly indented inside these blocks:
    x = y;
    
  • mklrobomklrobo Posts: 420
    edited 2014-11-17 07:41
    Duane Degn wrote: »
    The variable holds the value of the input at the time the assignment is made. This is the same as with Spin.

    It's similar to setting one variable to another.
    x = y:
    

    If, after the above assignment, the value of "y" changes, the value of "x" won't also change. The value of "x" remains the value "y" had been at the time of the assignment. The same is true for the value of "psl", it remains the value of "input(1)" even if "input(1)" changes.

    While experimenting with some encoders I wrote some simple Spin and PASM code to count pulses. I counted the pulses using two different techniques. One section of the code counted the pulses using the cogs counters (I followed the example from the PEK pdf) and the other section of code was written in PASM. I don't know if you're interested in a Spin solution to counting pulses, but if so you could check out the code attached to this post.

    It's also possible to count pulses using waitpxx statements but I didn't think of this possibility when writing my example code.

    Edit: BTW, it's much easier to read code if you use code tags. To get " x = y;" to show up in code blocks above, I used the text:

    [noparse]
    x = y;
    
    [/noparse]

    When these code tags are used, the text between them shows up properly indented inside these blocks:
    x = y;
    

    I will look into spin, it seems to have more functions. In reference to the inputs, I was used to the basic stamp following the input/output, to
    acquire the state without declaring it, every time. This is different with the propeller; as illustrated by this problem. This example implies
    more changes in programming, in using other functions.(?) :innocent:

    Did I mention you were a genius? Thanks again.:smile:
  • mklrobomklrobo Posts: 420
    edited 2014-11-17 16:14
    mklrobo wrote: »
    :cool: Here is the pulse counting program, revamped;(in C, if anybody wants it)

    #include "simpletools.h" // Library include
    int x,z,y;
    int psl;
    void blue();
    int main() // Main function
    {

    square_wave(0, 0, 9600);
    // while(1)

    for(y = 0; y < 500;y++)
    {

    psl = input(1);
    pause(5);
    blue();
    // print("the value of x = %d",x);
    // print("the value of z = %d",z);
    pause(5);
    // pause(1000);
    }
    print("the value of x = %d",x);
    print("the value of z = %d",z);
    }
    void blue()
    {
    if (psl == 1) { x++; }
    if (psl == 0) { z++; }
    }
    ***********
    This counts a pulse from a 9600 cycle square wave. This does not take up much space, and
    is pretty straightforward. Can use it to count pulses. Thanks again!
    :nerd:

    I tried increasing the iterations in the for loop, and the count in x and z went down! Why? I think that the more the Cog is loaded down, the
    less the effectiveness of the loops! This is why internal counters are so inportant, and assigning work to other Cogs. The speed of your
    program will suffer is you do not assign work to the other cogs; if speed is in need.:innocent:
  • Duane DegnDuane Degn Posts: 10,588
    edited 2014-11-17 18:08
    Duane Degn wrote: »
    x = y:
    

    BTW, it's much easier to read code if you use code tags. To get " x = y;" to show up in code blocks above, I used the text:

    [noparse]
    x = y;
    
    [/noparse]

    When these code tags are used, the text between them shows up properly indented inside these blocks:
    x = y;
    

    Quotes don't work the same as code tags.

    If you click on "Reply With Quote" on any post with proper code tags, you can see the way the code tags were used within the quoted text.

    There's also this tutorial by Phil.

    attachment.php?attachmentid=78421&d=1297987572
Sign In or Register to comment.