Shop OBEX P1 Docs P2 Docs Learn Events
Propeller Assembly and frequency — Parallax Forums

Propeller Assembly and frequency

gambrinogambrino Posts: 28
edited 2008-11-22 19:24 in Propeller 1
Hello Forum , always i can't know the frequency when i am using waitcnt , can someone tell how it work ?
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
PUB Main
cognew(@Toggle, 0) 'Launch new cog
DAT
        ORG 0 'Begin at Cog RAM addr 0
Toggle
        mov dira, Pin 'Set Pin to output
        mov Time, cnt 'Calculate delay time
        add Time, #$f 'Set minimum delay here
        
:loop
        waitcnt Time, Delay 'Wait
        xor outa, Pin 'Toggle Pin
        jmp #:loop 'Loop endlessly
        
Pin long |< 1 'Pin number
Delay long 8_000 'Clock cycles to delay
Time res 1 'System Counter Workspace




here Delay= 8000 is this means that generate 5KHz?
Thank you in advance

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-22 19:24
    In your example, Delay = 8000. With an 80MHz system clock (5MHz x 16), the delay is 100us plus the additional fraction of a microsecond for the 3 instructions to execute. If you take 1 / 100us, that gives a toggle rate of 10KHz (half cycles) or a frequency of 5KHz.

    If you want a frequency of 6KHz, that's a toggle rate of 12KHz. 1 / 12KHz = 83+us. That's a Delay of 6667.
Sign In or Register to comment.