Shop OBEX P1 Docs P2 Docs Learn Events
Pulse Generation — Parallax Forums

Pulse Generation

CenlasoftCenlasoft Posts: 265
edited 2011-07-24 19:01 in Propeller 1
Hi,
I am working on an ultrasound transducer. I have downloaded some objects on PWM from OBEX and I am lost as to how to produce:
40 KHZ pulse with a pulsewidth of .5 ms and an interval of 20 ms between the pulses.

It seems that the objects give me a choice of providing PIN and Duty. it's confusing.
Can someone help me?
Curtis

Comments

  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-24 13:10
    Do you mean a 40kHz pulse stream? How many pulses in the stream?

    You can always the counters in their own cog to pull this off; one counter would generate the 40kHz frequency, the other -- running in a synchronized loop could gate the signal (by applying a high to the modulation pin you can stop the signal; your output is active-low).
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-24 13:22
    Here's a simple idea using just one counter; note that this is intended to be launched with cognew so that it sends a pulse stream (which is active-low, btw) every 20ms
    pri ir_out(pin) | t
    
    '' IR pulse stream generator
    '' -- uses ctra to modulate pin at 40kHz
    
      ctra := (%00100 << 26) | pin
      frqa := 2_147_483                                             ' 40kHz @ 80MHz system freq
      dira[pin] := 1
    
      t := cnt
      repeat
        outa[pin] := 0                                              ' allow modulation
        waitcnt(t += (clkfreq / 1_000_000 * 500))                   ' on 0.5ms
        ouat[pin] := 1                                              ' kill modulation
        waitcnt(t += (clkfreq / 1_000_000 * 19500))                 ' off 19.5ms
    

    This works because the ctra output is OR'd with the pin output; when either is high the output will be high. You enable modulation by bringing the pin low so that the counter modulation comes through.
  • CenlasoftCenlasoft Posts: 265
    edited 2011-07-24 13:22
    Hi,
    Thanks for your response,
    I want to send a pulse to an ultrasound transducer (freq=40 khz) the pulse width = .5 ms and the time between these pulses is 20 ms. I guess its a stream because as soon as I send the pulse, I will listen for a response. I could use two pins if needed. Could you explain more about the counter generating a 40 khz and the gating process?
    Curtis
  • CenlasoftCenlasoft Posts: 265
    edited 2011-07-24 13:32
    Thanks, Jon
    I'll try it
    Curtis
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2011-07-24 15:56
    Hi Curtis, Do I interpret this right, that you want a burst of 20 cycles at 40kHz, the burst to repeat every 20 ms? I had posted a burst routine using the counters from spin in another thread, I-need-a-Spin-counter... This works to generate given number of pulses on command, up to 20 MHz within the burst with an 80MHz clkfreq. It uses two cog counters, one at the target frequency, while the second is retarded in phase by the exact number of cycles to blank out the first except during the burst. The command to start each burst would have to be given in another loop every 20ms.
  • JonnyMacJonnyMac Posts: 9,208
    edited 2011-07-24 16:39
    Could you explain more about the counter generating a 40 khz and the gating process?

    It's explained in the PE Lab book (by Andy Lindsay) and I think I covered it in my column about transmitting SIRCS.
    -- http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/prop/col/nvp4.pdf

    You're basically setting the counter as a free-running oscillator to do the modulation. By ORing the pin with the counter you can gate the modulation output. Again, when "off" the pin output signal will be high so you circuitry should be configured for this.
  • CenlasoftCenlasoft Posts: 265
    edited 2011-07-24 19:01
    Thanks to everyone for the great help. Jon, your code worked out great. Tracy, I'll try what you suggested. Now to work on the receiving part of the code.
    Thanks,
    Curtis
Sign In or Register to comment.