Shop OBEX P1 Docs P2 Docs Learn Events
Can propeller accurately generate nanosecond duration pulses? — Parallax Forums

Can propeller accurately generate nanosecond duration pulses?

CuriousOneCuriousOne Posts: 931
edited 2015-02-04 19:26 in Propeller 1
I need to output pulses with high frequency, 2-4mhz. I've tried to do it on 12F1840 @ 32mhz. Operations is - high pin, low pin, loop. The high pin takes one tick, low pin takes 1 tick also, but loop takes 6 ticks, so output pulses have large "gaps" between them. If I'll try to do same on propeller, will I face same problem?

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-02-03 12:05
    You can use a counter to output your frequency in PLL mode. The average frequency will be accurate, but you will get a little bit of phase jitter. Does that matter for you application?

    You mentioned "pulses." Does that mean something other than 50% duty cycle?

    -Phil
  • Heater.Heater. Posts: 21,230
    edited 2015-02-03 12:26
    I love this kind of question.

    "nano second pulses" it says in the title.

    "2-4mhz" it says in the question.

    Very different things.

    2MHz is a 500ns period. 4MHz is a 250ns period.

    Making a wild guess at a 50% duty cycle requirement that's 250/125ns to 125/62.5ns up and down time.

    That is one or two orders of magnitude away from 1ns.

    So, what is it you need? A 1ns pulse at 4Mhz or perhaps a 1ns pulse just once or something less demanding?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-02-03 12:43
    CuriousOne wrote: »
    Operations is - high pin, low pin, loop. The high pin takes one tick, low pin takes 1 tick also, but loop takes 6 ticks, so output pulses have large "gaps" between them. If I'll try to do same on propeller, will I face same problem?

    if you want a 50% duty cycle then the loop section of code will cause a gap. You could compensate by adding a "nop" not an operation.
    loop  or outa, pinMask
          nop
          andn outa, pinMask
          jmp #loop
    

    On an 80MHz Prop the above code should generate a 5MHz pulse.

    As Phil mentioned, using counter you should be able to generate faster pulses.
  • jmgjmg Posts: 15,173
    edited 2015-02-03 13:12
    CuriousOne wrote: »
    I need to output pulses with high frequency, 2-4mhz. I've tried to do it on 12F1840 @ 32mhz. Operations is - high pin, low pin, loop. The high pin takes one tick, low pin takes 1 tick also, but loop takes 6 ticks, so output pulses have large "gaps" between them. If I'll try to do same on propeller, will I face same problem?
    Using Sw alone, you have the same issues, using the Hardware Peripherals you face not the same problem, but you will have different problems.

    You need to give numbers on Pulse granularity, and Frequency Granularity, and what jitter can be tolerated, and how often - also does 50% duty cycle matter

    The NCO (adder) mode in Prop, can generate 2.50000MHz and 5.00000MHz that are jitter free & stand alone.
    As #2 says, for other values there is some jitter.
    The Prop can only ever place edges every 12.5ns, but the Adder cannot do a simple "divide by" non binary values so it gets close, but every now and then adds an extra 12.5ns so the average is ok.
    This appears as a phase step ( or an edge delay if you prefer)
    The 'now and then' varies with adder value relative to 2^32.
    Even Whole integers can get infrequent jitter some seconds apart.
    eg /14 is actually going to be

    2^32/(round(2^32/14)) = /14.0000000130385161

    ie mostly (14*12.5ns), and quite rarely (15*12.5ns)
    Conversely, /14.5 will alternate 14*12.5ns, &15*12.5ns almost exactly 50:50
    The PLL mentioned in #2 will filter better above some PLL filter frequency, so that /14.5 example will give
    181.25ns +/- some small jitter ( sub ns?)
  • edited 2015-02-03 16:00
    Duane Degn wrote: »
    if you want a 50% duty cycle then the loop section of code will cause a gap. You could compensate by adding a "nop" not an operation.
    loop  or outa, pinMask
          nop
          andn outa, pinMask
          jmp #loop
    

    On an 80MHz Prop the above code should generate a 5MHz pulse.

    As Phil mentioned, using counter you should be able to generate faster pulses.

    This code should toggle the pin every 8 ticks giving 10 MHz.
    loop xor outa, pinmask
         jmp #loop
    

    Sandy
  • Duane DegnDuane Degn Posts: 10,588
    edited 2015-02-03 16:06
    This code should toggle the pin every 8 ticks giving 10 MHz.
    loop xor outa, pinmask
         jmp #loop
    

    I didn't think of "xor". Excellent.
  • jmgjmg Posts: 15,173
    edited 2015-02-03 16:50
    This code should toggle the pin every 8 ticks giving 10 MHz.
    An 8 cycle toggle is not 10MHz
    However, the XOR loop is smaller in code, and easier to scale, and can add 4 cycle NOPs for 3.3333 and 2.5MHz as the next SW steps.
  • ChrisGaddChrisGadd Posts: 310
    edited 2015-02-03 17:50
    Here's a trick I learned from Kuroneko for getting 10MHz: http://forums.parallax.com/showthread.php/158622-What-is-the-highest-frequency-square-wave-I-can-generate?p=1305844&viewfull=1#post1305844
    kuroneko wrote: »
    You can get 10MHz (clkfreq/8) in a loop (dira setup not shown):
    mov     outa, mask
    
            add     outa, #1
            djnz    outa, #$-1
    
    mask    long    !(|< pin)
    
    @Hugh: This thread may be of interest as well.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2015-02-03 19:37
    If you load the Tachyon Hardware Explorer (see sig) you can connect a terminal at 115200 baud and interact with the Prop. To use P2 at 5MHz just type:
    2 APIN 5 MHZ

    To change that to 100MHZ (pin has already been specified)

    100 MHZ

    or 100 HZ or 5 KHZ etc

    The counter is set to NCO mode but you can type PLL and change it to that mode and play with that too using <n> PLLDIV to set the divider.
  • CuriousOneCuriousOne Posts: 931
    edited 2015-02-03 19:56
    Let me introduce more details.

    I'm building multi-phase power converter, and while length of pulse for 2mhz is 500ns, there are several phases, and "distance" (so called "dead time") between them (when one pin goes low and next pin is going high" should be adjustable and kept with good precision, in 1-10ns range. Can prop do that?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2015-02-03 20:40
    CuriousOne wrote: »
    Let me introduce more details.

    I'm building multi-phase power converter, and while length of pulse for 2mhz is 500ns, there are several phases, and "distance" (so called "dead time") between them (when one pin goes low and next pin is going high" should be adjustable and kept with good precision, in 1-10ns range. Can prop do that?

    1 to 10ns is a big range, which do you want? For 1ns resolution you need 1GHz vs a much more achievable 100MHz for 10ns resolution. So say 10ns then and the Prop can be run at 100MHz within reason so it can be adjustable in the 10ns range. However if you are building a multi-phase power converter you almost want this stuff made in hardware or have a CPU with this special timer, or FPGA even, rather than rely upon software and glitches, even just starting up.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-02-03 20:45
    I assume the gaps are just to prevent "shoot-though" in a H-bridge? Is there any reason this could not be accomplished externally with a delay network that slows down rising edges a little?

    -Phil
  • jmgjmg Posts: 15,173
    edited 2015-02-03 20:56
    CuriousOne wrote: »
    .. there are several phases, and "distance" (so called "dead time") between them (when one pin goes low and next pin is going high" should be adjustable and kept with good precision, in 1-10ns range. Can prop do that?
    Nope.
    Your choices are either a digital delay line, or a chip with high resolution PWM hardware that includes deadband control, or a maybe CPLD.
    I think TI have low cost DSPs with 1ns and sub 1ns PWM edge control.
  • jmgjmg Posts: 15,173
    edited 2015-02-03 21:13
    I assume the gaps are just to prevent "shoot-though" in a H-bridge? Is there any reason this could not be accomplished externally with a delay network that slows down rising edges a little?
    There are also Gate Drivers that manage this by reading the D-S voltages, and not turning ON the other fet, until the first one is confirmed off.
    That scheme copes a little better with dynamic loads, which can affect how long recovery takes.
  • abecedarianabecedarian Posts: 312
    edited 2015-02-03 21:42
    jmg wrote: »
    Nope.
    Your choices are either a digital delay line, or a chip with high resolution PWM hardware that includes deadband control, or a maybe CPLD.
    I think TI have low cost DSPs with 1ns and sub 1ns PWM edge control.
    TI C2000 processors should fit the bill, and IIRC, TM4C can also handle that too.
  • LawsonLawson Posts: 870
    edited 2015-02-04 17:09
    CuriousOne wrote: »
    Let me introduce more details.

    I'm building multi-phase power converter, and while length of pulse for 2mhz is 500ns, there are several phases, and "distance" (so called "dead time") between them (when one pin goes low and next pin is going high" should be adjustable and kept with good precision, in 1-10ns range. Can prop do that?

    If 10nS steps are fine, you can do that in code with counters with some restrictions. Using counters in NCO mode it's easy to make a pulse of N clock cycles with a single write to the counter. You can also use a counter to have a pin change state N clock cycles after writing to the counter. Combining these two inside a loop, you can make sophisticated PWM waveforms.

    In one of my devices with the Propeller, I use the counters to generate two PWM waveforms at 48KHz with the two PWM pulses centered on each other. The code then synchronously sampled two ADC's connected to current shunts in the center of each PWM pulse so that the output current ripple would alias to DC with a near zero offset.

    Still, I've yet to make PWM code that controls the dead-time between two FETs. I like to avoid letting software bugs fry hardware if I can.

    Marty
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2015-02-04 19:01
    Lawson wrote:
    I like to avoid letting software bugs fry hardware if I can.
    That is always sound policy. Software should never be capable of destroying or compromising hardware in any harmful way because, if given the chance, it will. Hewlett Packard made this mistake early in the personal computer revolution in their HP-85. It had a built-in thermal printer that was completely controlled by software. 'Problem was that misbehaving software was able to burn out the thermal printhead if left on too long.

    -Phil
  • altosackaltosack Posts: 132
    edited 2015-02-04 19:26
    I've made 10 ns 4-phase PWM with dead time (and software stepping to increase the effective PWM resolution) in the propeller, and I haven't fried anything (yet !), but it isn't yet in production, either. In a single cog, the duty cycle is limited to ~24% or less; it would take 4 synchronized cogs for an unrestricted duty cycle. If anyone can come up with a way to do this with fewer cogs, I'd love to hear it.

    If you need 1 ns resolution phased PWM w/dead-time, the dsPIC GS models can do that (in hardware), and are available in a DIP, as well as being more friendly to program than the TI chips.
Sign In or Register to comment.