input sense to propeller problem
mklrobo
Posts: 420
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.
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.
Comments
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,
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++; }
}
and simplified things as much as I could to eliminate errors, or oversights.
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:
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.
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.
Thanks.
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:
Happy day! Happy day!
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!
#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:
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.
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] [/noparse]
When these code tags are used, the text between them shows up properly indented inside these blocks:
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.(?)
Did I mention you were a genius? Thanks again.
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.
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.