Help with easy code.
Beginer
Posts: 21
Hello, could you help me with this easy code in spin? I want to sense states at pin 7. At pin is log.1 initial. When come first log.0 at this pin, program will wait to coming second log.0. In this time run repeat cycle that increase variable COUNT. Then i want to active pin(16) for time which depends on COUNT. But I have problem. Real time to waiting next log.0 is not equal as real time that the pin7 is activate !!! I think, Repeat cycle is "too slowly". I cant understand it.
One questation yet. How highest frequency could be sensing in this code? Schould I write it in asembler? Thank you.
Zdenek (Czech)
One questation yet. How highest frequency could be sensing in this code? Schould I write it in asembler? Thank you.
Zdenek (Czech)
spin
982B
Comments
Try something like this, delay should contain time in clocks between 2 0's
can you write what you want to do IN THE END in normal words
(no describing of code)
anyway
your code seems to do count the amount of time as pin7 is low
after measuring the time set pin 16 high for the SAME time
Count:= Count + 1 does count at a much slower speed than the systemvariable "cnt" is counting
so it cannot be done this way
therefore you have to use something like timmoore suggested
and then code
code]
waitcnt(delay + cnt)
[noparse][[/noparse]/code]
if it is okay that pin 16 is high PARALLEL to pin 7 beeing low your code reduces to
to add some information
you should not code
always as do it this way
add the actual value of cnt at the END of the expression to keep the time that will pass by between interpreting the spin-expression
and the REAL call of the PASM-command waitcnt (done by the interpreter) as short as you can
because of the interpreting overhead the minimum value to wait is 385
with values lower than 385 the counter has already passed your value
example:
value of counter is 1000
interpret spin-command
meaning wait for cnt-value to match 1250
AFTER interpretating the expression "(250 + cnt)" the value of cnt will be
already 1384 and it will take 53 seconds until the counter has counted up to 2^32 and rolls over to zero and count up from zero to 1250 again
once again:
in your project you will do much more in the end then just that few lines of code
Write a posting that says ALL about your project.
In the past it has been always the same:
as soon as the COMPLETE project is described much better solutions to detail-problems were found
best regards
Stefan
http://forums.parallax.com/showthread.php?p=467912
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
Check out the new Savage Circuits TV!
·