Shop OBEX P1 Docs P2 Docs Learn Events
Stupid Question needs answer!!! — Parallax Forums

Stupid Question needs answer!!!

anita1984anita1984 Posts: 23
edited 2008-10-26 13:56 in Propeller 1
Hello , can someone answer to my question , in the example 1 :
PUB Toggle
dira[noparse][[/noparse]16]~~
repeat
!outa[noparse][[/noparse]16]
waitcnt(3_000_000 + cnt)

it runs the internal fast clock about 12MHz , is this means that on the output Pin 16 we will have a frequency of 12MHz ?

Comments

  • TJHJTJHJ Posts: 243
    edited 2008-10-24 15:37
    If you are in fact running the internal fast clock. It should have a frequency of 3_000_000* 2(for one complete cycle) = 6_000_000. So wait time devided into clock speed gives you frequency. 12_000_000/6_000_000 = 2hz.

    Rember the speed is how fast per second. So your clock counter runs increments 12_000_000 per second. and the waitcnt command, waits for that number to increase xxxx amount. In this case 3_000_000. So it changes the state of the pin every 1/4 of a second. 12_000_000/3_000_000 = 4.

    Hope this helps.

    TJ

    edit. The above assumes the world is perfect. And does not account for command time.
    EDIT********* SEE WHAT BEAU SAYS BELOW. He knows way more than me. ************

    Post Edited (TJHJ) : 10/24/2008 5:28:18 PM GMT
  • Beau SchwabeBeau Schwabe Posts: 6,562
    edited 2008-10-24 16:15
    "...it runs the internal fast clock about 12MHz , is this means that on the output Pin 16 we will have a frequency of 12MHz..."

    With the waitcnt instruction in place it will toggle P16 at about 2Hz. With the waitcnt instruction removed it will toggle P16 at about 6.8kHz


    The 'repeat' plus '!outa[noparse][[/noparse]16]' takes 880 system clocks to execute in Propeller Spin... at 12MHz that's 83.3333ns times 880 clocks or 73.3333us.

    Toggling a pin every 73.3333us equates to 6.8kHz


    If this were written in Propeller assembly running at 12MHz, then it would toggle the pin at about 750kHz because it would only require 8 system clocks.·· ...at 12MHz that's 83.3333ns times 8 clocks or 666.6666ns.

    Toggling a pin every 666.6666ns equates to 750kHz

    [b]CON[/b]
     
    IOPIN = 16
    
    [b]PUB[/b] Main_TOGGLE_Demo
    
        AsmToggle
        'SpinToggle
       
    [b]PUB[/b] AsmToggle
        [b]cognew[/b](@AsmTogg1e,0)
    
    [b]PUB[/b] SpinToggle
         [b]dira[/b][noparse][[/noparse]­IOPIN]~~
         [b]repeat[/b]
           ![b]outa[/b][noparse][[/noparse]­IOPIN]
           'waitcnt(3_000_000 + cnt)
    
    [b]DAT[/b]
    
    AsmTogg1e      [b]org[/b]
            [b]mov[/b]   [b]dira[/b],     PinMask
    
    Loop    [b]xor[/b]   [b]outa[/b],     PinMask
            [b]jmp[/b]   #Loop       
    
    PinMask [b]long[/b]  1 << IOPIN
    
    
    

    Note:

    Keep in mind that using the internal 12MHz clock is not a very·accurate time base.· In my tests my measured results ran about 11% faster which means that my 12MHz clock was actually running closer to 13.3MHz

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 10/24/2008 4:48:36 PM GMT
  • mparkmpark Posts: 1,305
    edited 2008-10-24 23:29
    How did you come up with 880?
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-10-24 23:38
    Measure it with a scope:

    toggle a pin, then toggle it back, measure the pulse width and record it's value.

    place the instruction to be timed in between the two toggles, measure the new pulse width.

    subtract the first value from the second value and that's how long the instruction took to execute.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • mparkmpark Posts: 1,305
    edited 2008-10-25 00:49
    Measure it? That's cheating [noparse]:)[/noparse]

    How did you measure the REPEAT?
  • Beau SchwabeBeau Schwabe Posts: 6,562
    edited 2008-10-25 02:30
    mpark,

    Paul is correct! smilewinkgrin.gif I did measure it with a scope.

    As for measuring the REPEAT, I didn't... the 880 is a combined number that represents both the REPEAT and the OUTA command.

    If I wanted to measure the REPEAT, then I could do it by deduction... adding another OUTA command to another pin as a "filler" command.
    By noting how much delay was added by the additional OUTA, I could subtract that same amount of time from my original 880 clocks to determine the amount of time that REPEAT takes to execute.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • anita1984anita1984 Posts: 23
    edited 2008-10-26 13:15
    thank you alot , and what about duty cycle of this frequency , is it true 50% ?
  • Beau SchwabeBeau Schwabe Posts: 6,562
    edited 2008-10-26 13:56
    Yes, because of the TOGGLE (Spin) or XOR (Assembly) , each "half period" goes through the code identically resulting in a true 50% duty cycle.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.