Shop OBEX P1 Docs P2 Docs Learn Events
simple interrup and delay issue — Parallax Forums

simple interrup and delay issue

ziadziad Posts: 2
edited 2009-03-23 18:48 in Propeller 1
I have been trying to implement a simple interrupt _ delay program using the propeller starter kit. However, there are few issues with the timing.


I am feeding the propeller with a TTL pulse on pin0, then I output a hight on pin1 and bring it back to zero. Running the propller at 80 MhZ(clock cycle of 12.5 ns) , I expect that the propeller would respond withing a clock cycle for the transition on pin1 to happen.

I am getting about 6.8 microsecond delay between the transition on pin0 and pin1 (that is 6800/12.5= 544 clock cycles). also I noticed that its taking the same amount of time (about 6.8 micro sec) for pin1 to go from high to low, although it should take one instruction.

Could someone please take a look at the code below and tell me if there is something wrong.

I would appreciate if someone can provide me with an alternative way.

Thanks


CON
_CLKMODE = XTAL1 + PLL16X
_XINFREQ = 5_000_000

PUB ButtonBlinkSpeed ' Main method
dira~~
outa := 0

repeat ' Endless loop

waitpeq(%0001,%0001,0)
outa := 1
outa := 0

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2009-03-23 18:25
    There's nothing wrong with your code. Spin is an interpreted language, so you will not get the same one-instruction (i.e. four-clock) latency with Spin as you would using assembly.

    -Phil
  • Mike GreenMike Green Posts: 23,101
    edited 2009-03-23 18:33
    Spin is an interpreted language. It gets compiled into interpretive bytecodes, not the native instruction set of the Propeller. The sort of times you're seeing are approximately what would be expected. The WAITPEQ Spin statement when interpreted uses a WAITPEQ instruction which does respond within a single clock cycle, but the interpreter overhead adds to this.

    To get a faster response, you'd have to rewrite your routine in assembly language. Even there, the instruction time is on the order of 50ns (4 clock cycles) and your loop would require about 4 instructions to execute. The minimum pulse width you could produce would be 50ns and the response time from an input to output edge would be about 50ns. The minimum repetition time would be about 200ns (12.5ns x 4 x 4).

    In some circumstances, you can use the cog counters (see AN001 for details) from Spin for a rapid response. These can divide an incoming pulse by any power of 2 without further assistance and by other counts with some help in reloading the counter from Spin code or assembly code.

    The ImageCraft C compiler does compile into a semi-interpreted native code that executes about 5 times slower than pure native code, but much faster than Spin. It's also possible to incorporate small pieces of native code into a C program.
  • ziadziad Posts: 2
    edited 2009-03-23 18:48
    Thanks for all the help and suggestions, I will try to rewrite the code in assembly..

    I will keep you posted,

    Thanks again
Sign In or Register to comment.