Shop OBEX P1 Docs P2 Docs Learn Events
200kHz +/- 5kHz pulse output? - Page 2 — Parallax Forums

200kHz +/- 5kHz pulse output?

2»

Comments

  • StephenMooreStephenMoore Posts: 188
    edited 2012-03-11 01:10
    Pretty amazing.

    I will test it out as soon as I can get back to my lab on Monday.

    Some people are blessed with both brains and compassion... thanks Phil.

    sm
  • jmgjmg Posts: 15,183
    edited 2012-03-11 01:43
    I see that those fractions add up to .8431372583393682, but how did you come up with those particular values?

    I cheated a little, and used Wolfram.. :)

    The reason Egyptian fraction work nicely, is it is the same as a variable modulus counter, in this example /7 or /8
    If you divide by 7 exactly half of the time, and by 8 exactly half, you will average divide by 7.5,
    so the Egyptian fraction tells you what ratio of the time to divide by which whole number, to fit.
    The size of the fractions, tells you how often a period difference will be seen.

    In this example, the actual frequency is not really 10.2M, it is
    80e6/(2^32/(round(2^32/(80e6/10.20e6)))) = 10199999.995529651 Hz, and
    if we do
    ef=1/2 + 1/3 + 1/102 + 1/290917621
    (ef = Egyptian Fraction)
    and apply that fraction to the TIME DOMAIN, as the ratio of two possible periods summed, we get an average value of
    1/((7/80e6)*(1-ef)+(8/80e6)*ef) = 10199999.99552966233

    These agree to ~ 1 part in 10^15.
    The general form is always ef*PeriodDivisionChoiceA + (1-ef)*PeriodDivisionChoiceB

    I'll add: This maths also nicely reminds the user they do not actually get
    10199999.995529651 Hz, even though 80e6/(2^32/(round(2^32/(80e6/10.20e6)))) suggests they do.
    What you actually get (& can see above on the scope plots) is two frequencies,
    1/((7/80e6)) = 11428571.42857142Hz
    1/((8/80e6)) = 10000000Hz
    and the average calculated, is really the long term average of these two choices.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-11 16:46
    Stephen,

    Attached is the jitter-free clocks program in a more usable object form.

    -Phil
  • jmgjmg Posts: 15,183
    edited 2012-03-11 21:00
    Where you said "This permits limited duty cycle adjustment, so long as each half period is no longer than about 133 system clocks.
    "

    I think you meant to say "so long as each half period is no shorter than about 133 system clocks" ?

    Another common switching driver topology is a Bridge, where every alternate pulse swaps between two pins. The ON times are common between the pins, to keep magnetic balance, and ideally should adjust to 0 (or close) for soft start
    Each pin cannot (should not) go above 50% duty.

    - with this control you can tune resonance, via frequency, and also tune circulating energy (via ON times)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-11 21:27
    jmg wrote:
    Where you said "This permits limited duty cycle adjustment, so long as each half period is no longer than about 133 system clocks." I think you meant to say "so long as each half period is no shorter than about 133 system clocks" ?
    Yep. Thanks for the catch!

    -Phil
  • StephenMooreStephenMoore Posts: 188
    edited 2012-03-12 16:46
    The object works great. Two counters per cog each running in NCO differential mode (to provide the signal for a MOSFET gate driver which in turn switches two MOSFETs in a high frequency half-bridge resonator).

    The object more effectively utilizes the Propeller for this project: 14 counters with two pins per counter equals 28 pins total.

    There are many of these circuits that will be used to replace a single high power supply.

    Thanks for your help guys... I'll keep you posted on the outcome.

    sm

    P.S. I assume that the phase adjust value ($8000_0000 + 6) includes additional clock cycles to make up for the subtraction and negation instructions but why six instead of 8?
    test      inp,maska wz            'Has pina changed?
            if_z  jmp       #testb                  '  No:  Try pinb.
    
    
                  rdlong    perioda,par             '  Yes: Read latest periods for ctra.
                  test      prev,maska wz           '       Was previous input a zero?
            if_z  shr       perioda,#16             '         Yes: Use high 16 bits of period.
                  and       perioda,_0xffff         '       Mask off period for other half cycle.
                  sub       perioda,phaseadj        '       Subtract the phase adjust constant.
                  sub       perioda,phsa            '       Subtract the current phase.
                  neg       phsa,perioda            '       Write adjusted phase to phsa.
    
    prev          long      0                       'Previous pin states. Always starts out as low:low
    _0xffff       long      $ffff                   'Period mask.
    phaseadj      long      $8000_0000 + 6          'Phase adjustment added to phsa is $8000_0000 - period.
    
    
    acc           res       1                       'Scratch register.
    inp           res       1                       'Input anded with pin mask and XORed with previous input.
    maska         res       1                       'Mask for pina.
    maskb         res       1                       'Mask for pinb.
    addrb         res       1                       'Address of phaseb long in hub.
    perioda       res       1                       'Half period of ctra.
    periodb       res       1                       'Half period of ctrb.  
    
    
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-12 18:36
    Stephen,

    'Glad it worked out for you!

    Why six instead of eight? Actually, the question is, "Why six instead of four?" The reason is that the source read of phsa in the sub operation occurs in a different part of the four-stage pipeline than the destination write in the neg statement. BTW, I didn't try to figure it out a priori. I just adjusted it until the frequency was right. Sometimes the empirical approach is quicker than actually knowing what you're doing. :)

    -Phil
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-03-13 09:38
    Fourteen well-tempered frequencies and and still one cog and lots of hub left to implement exactly the flexible application-specific tuning interface you need! It's an elegant solution, the sort of thing the Prop was made for, I think. If you find you need a fast serial port or something like that in order to implement the interface, well, you still have 12 frequencies.
  • jmgjmg Posts: 15,183
    edited 2012-03-13 17:35
    The caveat that "so long as each half period is no shorter than about 133 system clocks" is a rather big fish hook.
    It is nice to be able to drop duty cycles to close to zero, for soft start / short circuit hiccup conditions.

    I think I can get it down to ~28 cycles for a preferred pulse ( ie min _/=\_ ) , and ~36 for the non-preferred (ie =\_/= )

    Next challenge is to add Alternate-drive for bridge applications, but that will cost cycles, and I'm unsure what the Prop does as CTR is dynamically flipped across pins ?
    It would usually be when both are low, so I guess a pin defined as L, will stay low ?

    I have not seen Gate Drivers with a FlipFlip built in, as the PWM controllers usually have that.
    I guess an external 1G74 would save pins ?
  • Bob Lawrence (VE1RLL)Bob Lawrence (VE1RLL) Posts: 1,720
    edited 2012-03-13 18:41
    Thanks to all that made this an interesting learning experience and a special thanks! to Phil for the code to experiment with.

    For anyone interested I ran it in the Propeller emulator - Gear (screen capture below)

    JitterFreeClk.jpg
    1024 x 640 - 119K
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-03-14 08:55
    Don't know about flip/flops in gate drivers, but I've seen plenty with dead time and anti shoot-through.
  • RaymanRayman Posts: 14,844
    edited 2012-03-14 10:40
    Out of curiousity... You used the word "pulse" in the title... Can you have a fixed pulse frequency but with a pulse width that varies?
    (like a faster version of servo control). If so, maybe there's some trick you could do...

    Anyway, if you need several of these outputs, isn't it better to use one cog to do them all in assembly anyway?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-14 10:44
    Rayman wrote:
    Anyway, if you need several of these outputs, isn't it better to use one cog to do them all in assembly anyway?
    With 12.5 ns resoluiton? How??? At 200 KHz, you've only got 50 instructions for each half cycle.

    -Phil
  • CircuitsoftCircuitsoft Posts: 1,166
    edited 2012-03-14 10:55
    Phil, Doesn't your PWMx8 object do exactly that?

    http://obex.parallax.com/objects/359/
  • RaymanRayman Posts: 14,844
    edited 2012-03-14 11:02
    Does he really need 12.5 ns resolution? I didn't see that...
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2012-03-14 11:12
    At 200 KHz, every 12.5 ns change per half-cycle amounts to a 0.5% change in period, or about 1 KHz.

    -Phil
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-03-14 13:14
    If that is done with the cog counters, the main steps come between division of phsa into 400 steps for close to 200 kHz, and division into 399 steps for 200,501 Hz, or 401 steps for 199501 Hz.

    The ones with odd numbers of steps are asymmetric, that is, one half cycle is 12.5ns shorter than the other. So, the symmetrical main step with the cog counters is also about 1kHz like Phil pointed out.

    The counters can achieve intermediate values, but that is accomplished with bobble, jitter, whatever you want to call it. For example, 200250 Hz is comprised of alternating cycles of the periods corresponding to about 200000 Hz and 200501 Hz. That goes back to the talk about exotic fractions.
  • StephenMooreStephenMoore Posts: 188
    edited 2012-03-15 16:46
    Here is an update to the original object which adds NCO differential mode and a PST user interface(using 6 cogs per Tracy Allen suggestion so that control can be added). My programming technique is kind of stone club and axe but I think it works OK. I also rearranged the pin assignments (all ctra pins assigned and then all ctrb pins assigned)

    SM
Sign In or Register to comment.