Shop OBEX P1 Docs P2 Docs Learn Events
Count 16 external clock cycles and waitpeq style interrupt — Parallax Forums

Count 16 external clock cycles and waitpeq style interrupt

TransistorToasterTransistorToaster Posts: 149
edited 2007-06-13 19:33 in Propeller 1
Hello,
I was wondering if there is an efficient way to make a prop count pause until 16 external clock cycles are counted. I know it's easy with an external counter, but I'd like to do it purely in software.

I thought about writing several waits with the state alternating 0 and 1 16 times.
Other ideas?
Thanks,
Frank

Comments

  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-10 09:33
    just code it so that it sits in a loop and everytime the signal goes from low to high add one to a counter, when 16 leave loop.

    Or use the hardware counter in edge detect mode, set frqa as 1 and wait unil phsa is 16.

    Graham
  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-06-10 15:42
    Is there a way I can compare the internal prop counter with 16 (or even 8) real fast? The clock is 13.333Mhz, generated also by the Prop as 80Mhz/6.

    Post Edited (TransistorToaster) : 6/10/2007 3:48:38 PM GMT
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-10 18:01
    In assembly.

    Do you want to use the divided clock or just output it again?

    Graham
  • TransistorToasterTransistorToaster Posts: 149
    edited 2007-06-10 18:12
    The 13.3Mhz clock is generated to be used externally by other ICs. I'd like to have the Propeller to wait for 16 clock cycles of the 13.3MHz signal. I do not need to transmit 13.3Mhz/16 anywhere external to the Prop. All I need is to count or wait for that to happen. All I want to do is to avoid an external mod 16 counter IC.
  • LawsonLawson Posts: 870
    edited 2007-06-10 18:35
    um... since the Prop is generating the frequency you're trying to count cycles of, why not just use a WAITPEQ to sync with the pulse train then a WAITCNT to wait for 16 cycles to go by?

    something like (in pseudo code)

    WAITPEQ 'sync to the incoming pulses
    temp = CNT
    temp = temp + 16*6 - 4 'the minus 4 compensates for the time spent sampling CNT
    WAITCNT(temp)
    'it's now 16 cycles later
    'so do stuff


    Marty
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-10 22:52
    Marty, I think you have the wrong end of the stick. The 13.3mhz is an external clock, the propeller needs its operations synced to 1/16th of this clock.

    TT,

    Assembly is fast enough and it provides quite a bit of time to process between clocks. Using waitcnts is possible but that ties up an entire cog just to doing the divide, it can't do anything else.

    Using a counter is good because you can do the compare, then reset it and do some processing and then come back to check it again, just make sure the processing fits in the time frame.

    I don't actually know if spin is fast enough even using the counters, I have no feel for its speed.

    Graham
  • janbjanb Posts: 74
    edited 2007-06-12 18:49
    Hi,

    I have not tried this, so I'm only speculating.

    You want to delay action of a cogg by 16 (or 16*16?) clock ticks seen by cog, right?

    One assembler 'wait' ·command : NOP taks 4 clock ticks.

    Would be enough to write an assemble code with 4·NOP instructions.

    If you need dealy of 256 ticks, a loop in assembler should work.

    On command in SPIN 'costs' 100-200 colck ticks·- probably it is hard·to get such short delay in SPIN.

    If you·choose to assembler you need to 'sacrifce' the whole cog, since it can't run spin·& assebler code simultanously

    Jan
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-06-12 20:24
    Jan, he needs to count an external clock not the one running the propeller.

    Graham
  • ericballericball Posts: 774
    edited 2007-06-13 19:33
      MOV CTRA, initctra ' set CTRA to POSEDGE or NEGEDGE detect and APIN
      MOV FRQA, #1
      WAITPEQ pinmask, pinmask  ' to detect trigger
      NEG PHSA, #16 ' set PHSA to -16
    waitclk  TJNZ PHSA, #waitclk ' wait for 16 cycles
    ' code for after waiting 16 cycles
    initctra LONG 
    pinmask LONG
    
Sign In or Register to comment.