Simple IDE waitpeq and waitpne code problem.
todieforteo
Posts: 7
in Propeller 1
Hi everyone,
I have propeller quickstart board. I like work it but I have a problem. I use waitpeq and waitpne in C code, its not working properly.
int count=0;
while(1)
{
waitpeq(1,0); //wait pin0 to high
waitpne(1,0);// and wait pin0 to low
count++; // count++
}
when p0 to high and low cnt is increasing two.
another problem I don't select different pin for input.
ı use waitpeq(1,2); or waitpeq(1,5)// it is not working.Propeller select pin0 for input, this code only work on pin0.
Please help me.
Thanks in advance
I have propeller quickstart board. I like work it but I have a problem. I use waitpeq and waitpne in C code, its not working properly.
int count=0;
while(1)
{
waitpeq(1,0); //wait pin0 to high
waitpne(1,0);// and wait pin0 to low
count++; // count++
}
when p0 to high and low cnt is increasing two.
another problem I don't select different pin for input.
ı use waitpeq(1,2); or waitpeq(1,5)// it is not working.Propeller select pin0 for input, this code only work on pin0.
Please help me.
Thanks in advance
Comments
By the way, do you see the "C" in the text box formatting bar (here on the forums, not SimpleIDE)? Pressing that and then pasting your code, or pasting your code, highlighting it, and then pressing the "C" will make your code easier to read here on the forums, like mine right above.
#define waitpeq ( state, mask )
Wait until INA equal state & mask.
Parameters
state Target value
mask Ignore masked 0 bits in state
#define waitpne (state, mask )
Wait until INA not equal state & mask.
Parameters
state Target value
mask Ignore masked 0 bits in state
you need a high or low (1 or 0) pin state in the first position and a 1 in the bit corresponding to the pin number (P0 = bit 0 = 0b1 = decimal 1) in the second position.
try this:
If the code is entered with p0 = low, the program should wait until the pin goes high. But it will then halt until the P0 = low again.
Tom
I use IR (reciever and transmitter) with op-amp comparator to have clear pulses. I increase delay time for example (CLKFREQ/1000 + CNT) it is good work but ı don't want too much delay time. I am working on RPM counter speed motor.Do you have a different idea in this matter?
twm47099 thank you for your reply. its working but count increase two one pulse. I have to use delay time, I think. Pin select working good thank you for your helps.
Well, once you get the pin mask in there correctly, as twm47099 mentioned, there are a couple things that could go wrong (that I can think of)
1) The wait is too short, and it overflows giving you a 53 second wait period. Knowing whether you're compiling as LMM or CMM can help us make a better guess as to what the shortest wait period is.
2) The pulse is smaller than 100/80,000,000 of a second (for measuring RPM, that's pretty unlikely )
You mentioned that "waitcnt(CLKFREQ / 1000 + CNT)" worked, but that was a longer delay than you wanted. The good news, that gives you lots of wiggle room. CLKFREQ / 1000 should be 80000, assuming an 80 MHz clock frequency. So try a delay of 30 us, or (CLKFREQ * 30 / 1000 / 1000)
Here's a mechanism I use (converted from Spin) that works like a "click" event in PC program: the button has to be pressed and released.
As you can see, the pin must be held high for at least 20ms, then released -- at that point the code will return to the caller. This function is easy to tune by changing the loop timing an the number of bits used in dbmask.
For longer duration debouncing, the mask trick isn't always convenient. Here's a bit of code I wrote for a friend's retrofit of a kiddie ride (kiddie ride computer replaced with Propeller and small video player). I have a background cog that run every millisecond. In that cog TTL inputs are scanned. After than, this code is called. It does a long-duration debounce of the coil acceptor.
(this is Spin -- I'll leave you to convert to C)
JonnyMac thank you for your helps. I use to define binary code such as (0b11110) in simple IDE but its not work. I think, SimpleIDE can't decode binary code.
Fortunately, I solved this problem by using very small waiting times.(CLKFREQ/10000 + CNT)
Here's the complete program that I used to test that function. It is running -- and working! -- on an Activity Board.
FOLLOW UP: As I do want to learn C for the Propeller I went ahead and installed the latest version of SimpleIDE (1.1) -- the program still works.
i recorded reading this thread for QS pad
http://forums.parallax.com/discussion/135794/quickstart-touchpad-tutorial-demo-for-propgcc
i want to ask you something. can we use binary system to define for pin ?
for example ;
on spin code , we can use binary numeric system to define pins. This makes our job much easier. we can detect more than one pin in waitpeq function at the same time. is this possible in C code?
thanks in advance.
While this is generally acceptable syntax with GCC, it is relying on a compiler extension (unless you are using C++14 or later) so it should be avoided if the code is intended to be portable across compilers, or it must be strictly standard compliant (can check for standard compliance by compiling with -Wpedantic).
Good to know! So was there no C or C++ standard way to provide binary literals until C++14?
That is correct. It was considered for C99, but per the revision rationale (open-std.org/jtc1/sc22/wg14/www/C99RationaleV5.10.pdf, bottom of page 51) "A proposal to add binary constants was rejected due to lack of precedent and insufficient utility". I don't agree with that but the standard is what it is. Support wasn't added in C11 either but now that it has been added to C++ maybe it will make it into the next revision of the C standard.
Another readability feature that was added by C++14 is using single quotes as digit separators (e.g. 0b0101'1010)just as underscores can be used in SPIN/PASM.
Thanks for the info. What the heck is wrong with underscores as digit separators? Java has that too as of Java 7... seems to make a lot more sense than a single quote.
Underscores were set aside for user defined literals in C++11. According to this document, their removal was considered. I have no experience with user defined literals so I have no idea how useful they actually are.