Shop OBEX P1 Docs P2 Docs Learn Events
How generate short pulse in spin language ? — Parallax Forums

How generate short pulse in spin language ?

edited 2008-06-17 00:02 in Propeller 1
Hello,

this simple spin program generate short pulse at pin 0



CON

_xinfreq = 5_000_000
_clkmode = xtal1 + pll16x

PUB Pulse

dira[noparse][[/noparse]0]:=1

!outa[noparse][[/noparse]0]
!outa[noparse][[/noparse]0]




Why the on time of pulse is so long ? about 20 microseconds (45kHz)

How can generate a short pulse in spin language ?

Thanks

Francesco Santandrea

Comments

  • edited 2008-06-16 16:25
    Errata corrige

    OPS

    ...
    about 20 microseconds (45kHz)
    ...

    is .... about 10 microseconds (100kHz if repeated)...
  • RaymanRayman Posts: 14,233
    edited 2008-06-16 16:55
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-16 17:10
    Here's a Spin routine that will issue a pulse of any width, beginning at one clock period (12.5ns with an 80MHz clock):

    CON
    
      _clkmode      = xtal1 + pll16x
      _xinfreq      = 5_000_000
    
      outpin        = 0
      ctra0         = %00100 << 26 | outpin 'NCO with output on outpin.
      frqa0         = 1                     'Increment by 1 on each clock.
      dira0         = 1 << outpin
      
    
    PUB Start | t
    
      dira := dira0           'Set pin as output.
      frqa := frqa0           'Initialize frqa.
      repeat
        repeat t from 1 to 100 'Pulse widths from 12.5ns to 1.25uS.
          repeat 10000
            Pulse(t)
         
    PUB Pulse(t)
    
      phsa := -t            'Set phsa for pulse width.
      ctra := ctra0         'Start the counter.
      repeat while phsa < 0 'Wait for MSB to go low.
      ctra~                 'Stop the counter.
    
    
    



    -Phil
  • RaymanRayman Posts: 14,233
    edited 2008-06-16 17:20
    That's a nice example!
  • edited 2008-06-16 18:15
    RAYMAN Great !!!

    wink.gifwink.gif Thanks !!!


    and if I should be reduced the time between pulses?

    Is possible with stop of Cogs ? or otherwise ?


    Francesco Santandrea
  • RaymanRayman Posts: 14,233
    edited 2008-06-16 19:06
    I guess it depends on what you are doing...· What is this for?· Do you want burst or continous output?
  • jazzedjazzed Posts: 11,803
    edited 2008-06-16 19:24
    Phil, your example is great. You should write a book.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • edited 2008-06-16 23:56
    Rayman

    for continuos output

    example for

    PWM high resolution (10-12 bit and more)
    100 - 200 kHz and more
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-06-17 00:02
    Francesco,

    To output a 10-bit PWM at 100KHz would require a pulse width resolution of less than 10ns. You won't get PWM output like that with the Propeller. If you don't need true PWM, though, but can settle for the Propeller counter's DUTY mode output, you will come close to your objective.

    -Phil
Sign In or Register to comment.