Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

PWM generators comparator A&B Up/Down compare & resulting Trapezoidal wave form.

Guru 54678 points
Other Parts Discussed in Thread: INA282, TM4C1294NCPDT, LM3S8971

Figure 23-5 below infers there to be only a single pulse on A or B PWM output Up/Down counter mode during load and zero count match. An attempt was made in an earlier illustration of the up/down PWM generator counter to show a reoccurring pulse stream in a very confusing way. A single output pulse from PWM generator A&B is then shown to occur for the zero to zero transition below.  

Might the PWM generator A&B output signal be drawn incorrectly in relation to the discussion on the PWM up/down counter mode? Does the PWM generator output only a single pulse for a incremental up/down count of many integers only when the comparators match a set point in the sloping integer count? If so in a 20Khz PWM frequency & resulting trapezoidal wave form a single PWM generator period of integer counts results in a single 50us pulse inside the trapezoidal wave form over 1ms in horizontal length. More over then load count match occurs at the peak of every 50us pulse with (zero) count pulse on either side of each and every 50us generator pulse. Possibly this topic has been over simplified to the point it makes no sense in relation to the Tivaware C++ programming of the PWM generators and other functions. Tivaware is not alone Stellarisware departing with the same diverged datasheet topic to actual occurring PWM events in the real world of DSP leaves one scratching head, beard and or whiskers!

This figure below does not make that point clear as it relates to the resulting trapezoidal wave form or center aligned PWM pulse stream when (pwmA & pwmB) are not shown to have more than one rising and one falling edge. The relation to this diagram and the resulting trapezoidal wave forms (below) figure 23-5 share similar pyramid architectures making a through understating of it even more confusing.

 

  • Hello BP101,

    The PWM Generator outputs two signals (A and B). The diagram attempts to show what the output on the PWM channel would look like for the respective comparator counts being matched and an event being programmed for the same.

    Regards
    Amit
  • Hi Amit,
    Nice try but that does not answer the more pressing questions being asked. When and where comparator matches occur in real time PWM generator output events? Do the A&B generator outputs follow the count up/down exactly or only the comparator match events in building a center aligned PWM pulse stream?

     
    Other words is the A&B signal in Figure 23.5 representing a single PWM pulse or abstracting the entire trapezoidal wave form created from the count up/down matches of theses comparators. The Figure makes no sense in the world of counter theory since an count up/down count includes more than a single BCD or integer transition. Multiple increment/decrement integers would toggle the output more than one time. Figure 23.5 showing only a single rising & falling edge does not properly describe how the A&B outputs would toggle during a count especial since it is depicted with zero(0) and LOAD nomenclature.

    More importantly Figure 23.4 & 23.5 failure to illustrate the PWM generator A&B output signal not at all or as a pulse stream is important because the ADC sample triggers can be fired by the PWM generator during any of the 4 comparator, PWM Load or zero events. Thus one has to know where in the resulting trapezoidal wave form the comparator match occur in real time. All figures if kept the way they are would then need to show where the ADC trigger points occur in the PWM generator output pulse. Thus one would not simply deduct the data sheet PWM figures abstracts a Trapezoidal wave form.

  • Hello BP101,

    The Generator output follows the count up/down scheme.

    The A and B signals represent a single PWM pulse. Now the diagram is a graphical representation of a 16-bit counter. That being illustrated in a datasheet would mean quite some pages.

    Regards
    Amit
  • Hi Amit,
    Never fully understood this PWM figure for over two years. Now fighting the ADC sample trigger timing to correct PWM current monitoring positions for the INA282 shunt monitor.

    "The A and B signals represent a single PWM pulse"; Well if that is indeed true then a zero and load match pulse occur with every single period pulse. So it actually takes several incremental integers in up/down counts to produce a single pulse of some (amplitude) based on the reload timing and fixed comparator match points?

    When and where do the ADC triggers assert in relation to the A&B output in figure format? All we have to go on is text making a statement of 6 points not fully qualified. There is no timing diagram representing the ADC trigger points in relation to A&B generator outputs. That makes for guess work as to where the event actually occurs in the resulting wave form.

    Clearly TI needs to spend a bit more time clarifying the center aligned PWM signal generation in Wiki or does this exist already?
  • BP101 said:
    When and where do the ADC triggers assert in relation to the A&B output in figure format?

    While the MCU manuals may not be "crystal clear" - perhaps this "cut/paste" from hallowed LX4F manual - supplies the "when."  Where depends upon the PWM Generator's config. and (likely) the particular PWM modulation scheme.  If Trapezoid Modulation & "Slow Decay" is selected - then "only" the high-side PWM driver's reaching its "load value" serves as the ADC trigger.   This requires, "PWMGenIntTrigEnable()" with parameter, "PWM_TR_CNT_LOAD."  Note that other ADC triggers exist - yet this particular one triggers (as you ask) - during PWM impulse's center.

    As that occurs at PWM Center - the ADC Trigger should be proper - even (and especially) during low-duty cycles.  (an ADC trigger too early - or too late (as opposed to center of the PWM output) - would likely "miss" a narrow PWM impulse.)  That's "le raison d'etre" for "center based" PWM triggers of the ADC...

    MCU Manual Extracts - supporting this assertion - follow:

    Our small firm also was intrigued by this - we confirmed this "center of PWM impulse ADC trigger"  by driving the selected ADC channel input with a ramping, linear voltage - which served to reveal the "very near to PWM center" ADC measure...  

  • Hello BP101,

    The A and B do not represent a single PWM pulse but two channels attached to the same generator (also called pwmA and pwmB). This is especially required when a Motor Control Signal with DeadBand is required.

    If the ADC trigger is the true question, then it is triggered (as cb1 highlighted) based on another enable register PWMxINTEN. Of course your point on documentation (one which cb1 has always made us accountable for) is taken and a new data sheet format (breaking from the TM4C and Stellaris) would be the correct place to make changes from TI.

    Regards
    Amit
  • Hello CB1,

    Was quite aware these points made above. Was actually requesting a figure format clock timing illustration showing the PWM clock pulses and the 6 PWM generated trigger points with respect to comparator A&B outputs.

    The defining difference between Load and Zero triggers (data sheet states) comparator A&B match is ignored if ever they occur simultaneously with Load or Zero. It is plausible two distinct pulses of the trapezoidal wave form generation might actually trigger undesired current samples during Load match. This symptom is hard to unravel not knowing where the comparator match count to ADC trigger points occur in relation to the pulse period. One can only use visual feed back from test equipment to determine what and why.

  • Perhaps adding the PWM clock into the illustration would have removed most all confusion as to what the pyramids (^) are trying to relate in my thinking to be ramping counter time. The PWM comparator outputs following the match count throws a twist into the mix where BCD counters would have direct output in synchronization with the clock and up/down count.

    Have to believe anyone jumping into this PWM world should have some back ground in BCD counters. That said, without the PWM clock timing added in the illustration it is easy to confuse conventional BCD counters theory with PWM generator theory. That is especially true when periods of time elapse between topic review. There needs to be timing clarity in the PWM illustrations topic to avoid silly question, especially true when vendors work with BCD counters and PWM in the same project.
  • One other thing; Figure 23-5 text states there to be 2 PWM generators yet the illustration is one drawn as a continuous signal from the same source. Perhaps we need to separate the two (^) and add the PWM clock. Then everyone on Earth will understand (pwmA&B) rising/falling edges represent single individual pulses from two generators.
  • (an ADC trigger too early - or too late (as opposed to center of the PWM output) - would likely "miss" a narrow PWM impulse.) Hard to imagine comparator match ADC triggering being any less edge aware than Load match no matter the PWM pulse width. That said, some kind of error % might be expected in the linear world of trigged events but not in digital or the die might have errata issues.

    Our test instruments capture current peaking closer to PWM Low side MOS enable times. Current samples taken from the far right each every pulse have distinctly greater amplitude. Slow decay MOS appears to prolong current lagging behind the voltage in each inductor. Sampling the middle every pulse appears to miss most all peak current events,. So noted in visual timing aspects between trapezoidal wave form pulses and low side current monitor pulses given some minimal propagation delay in the mix.
  • BP101 said:
    Hard to imagine comparator match ADC triggering being any less edge aware than Load match no matter the PWM pulse width.

    Edge awareness impacts (other) than the "TRCNTLOAD" ADC Trigger I referenced.  Review the "Center based" ADC Trigger (diagram, below) - note the load pulse is "dead-centered" w/in the PWM impulse (either of them)!  

    When the PWM pulse width is short - which results from low duty cycles - the importance of such, "Trigger on load" becomes especially magnified.   While there exist 4 "comparator edge" ADC triggers - each/every one exist at the (very) beginning or (very) end of the PWM impulse - and an ADC trigger at such extreme seems "less effective" than "Trigger @ PWM Center." 

    Power Engineering texts detail very well - if I may recite their "essence" - "ADC Triggering as a pulse just begins" (counting up) may be too soon - may miss the peak current. (expected close to center)  Likewise - "ADC Triggering as a pulse just falls/extinguishes" (counting down) may be too late - again may miss the peak current.  Again - this is not my invention - I'm simple recipient/exploiter (ot text's valued guidance) & reporter, here. 

    Center based triggering is employed by all such MCU vendors - and was used in the days of "dedicated" BLDC Controller ICs (prior to MCUs)  - as well.

    As duty cycles "flirt" w/90%+ the requirement for such "dead center ADC Trigger" may lessen - and one expects that's what you're reporting.

    That said - "center based ADC trigger" has long been proven - we'll (and many/most here) will continue in its use & application...

  • "each/every one exist at the (very) beginning or (very) end of the PWM impulse" That's a far stretch to say when in fact the comparator match points are not at the very end according to figure 19-4. More so they occur mid way up/down slope.

    How would we know exactly at what time in the PWM pulse match comparator points occur without having access to PWM clock and latency specifications?
  • BP101 said:
    That's a far stretch to say when in fact the comparator match points are not at the very end according to figure 19-4

    My friend - one (crystal clear picture = 1000 words!  Look (instead) here:  Fig 19-5: (one diagram further than your 19-4!

    Your use of "far stretch" to attack your "helpers" is curious - is it not?   And earlier - your response to Amit's writing - was, "Nice try!"   That's not right nor proper!

    Rather clearly - when "up counting" an ADC Trigger is delivered (just as past stated) at the very beginning of the PWM impulse.  When "down counting" the ADC Trigger is delivered (again just as past stated) at the very end of the PWM impulse.  There is absolutely "No stretch" yet alone a, "Far stretch" to note.

    Why do you characterize this as a "far stretch?" PWM impulse (either of them) commences EXACTLY @ the match point - and extinguishes EXACTLY @ the opposite match point!

    Earlier - my (unverified) initial post - I described (rather exactly) "how we'd know (exactly) where the match points could be determined..."

    I'll leave to Amit to detail fig 19-4 - which serves a different role - due to its use of "direction."   Hopefully his explanation may escape, "stretch!"

  • Hello BP101,

    The illustration is trying to show the count in terms of up count and down count. I don't think it is confusing (pardon me for over familiarity with the datasheets).

    Regards
    Amit
  • Let me register vote #2 for, "Not confusing!" One hopes your writing (this time) does not warrant a second, "Nice try!"

    Hard to understand how (would be) helpers warrant such stern rebuke.   Just two have responded - might there be a reason?

  • Earlier - my (unverified) initial post - I described (rather exactly) "how we'd know (exactly) where the match points could be determined..."

    Was referring to the ramps (^) in the count positions match points and actual location in the resulting trapezoidal wave form are not exactly at the beginning and ends of a single pulse period. For one the MOS free wheeling diode in the high and low side FET shuts off at the down count ends of pwmA&B causing a ringing in the signal that extend beyond down ends period timings and flowing into dead band.

    The inductive phase coil voltage also hangs around for a while longer after the FET shuts down. Hence the current lags behind the voltage beyond the trigger point of a center sample. A 4us center sample just barely catches declining current ramp, speaking of each individual low side phase current not the total high side B+ source return a current (probe) my reveal. Since horizontal time base is moving from right to left the current sample points can best be witnessed; Scope triggering set on the trapezoidal wave form (voltage) order to see inductive (current) lag behind the trigger points.

    Simple figures as clarification get fuzzy upon trying to back step into the trapezoidal signal build. Becomes difficult to visualize pwmA&B when trying to mentally set imaginary ADC trigger points within the resulting trapezoidal and current wave form. Only then do we know without doubt the ADC triggers are asserting exactly as they are programmed to and sampling in the ideal time position.

  • However appreciative in each every response there lacks the answer for trapezoidal wave form timing material being asked for in the 1st and later posts. Apologize for any perceived frustration my part alone is enough head explodes leave white walls grey matter soaked. 

    Obviously the first in kind a tagged scope capture below attempts to clarify why the timing of the comparator edges is so vital from the stand point of where Zero and Load match logically should occur in the trapezoidal wave form. The PWM clock pulse missing from all figures makes it difficult to know where the hard edges might occur from the data sheet text alone. Least of all the electrical specifications make no attempt to air any such similar laundry.

    Two wave forms superimposed saw tooth current pulses inside Trapezoidal PWM (Illustrate) where ADC trigger points logically should start/end each PWM pulse and trigged ADC sample period. Suspecting the advantage of using comparator B down to trigger  current sample is the fact a Zero or Load match occurring simultaneously will Avert taking a current sample when I suspect the duty cycle falls to zero anyway. Like wise if BEMF is being sampled with the same ADC trigger a concurrent Zero or Load during Comparator B down should avert taking any would be false zero crossing samples. Like to have others do similar test and report the results in scope captures. Possibly TI can generate a Wiki paper of some kind?

    Current envelope (top trace), Free Wheel diode ringing pattern at the end of each PWM pulse period (bottom trace)

        

  • Hello BP101,

    When the ADC is to be triggered from the PWM, it has to be kept in mind that the ADC will sample the data after resynchronizing the PWM trigger to it and then start charging the Sampling Cap for 4 clocks of 16MHz. Hence the timing may be off from the sampling point. The trick is to know what is the range of the Sampling Cap to start the sample value and use this to change one of the comparator threshold to be able to generate a trigger at the correct instance. It may require a second generator to be used for the ADC trigger allowing fresh set of comparators to be time for multiple events,

    Regards
    Amit
  •  "use this to change one of the comparator threshold"

    Might this be ADC differential mode you are referring as the comparator threshold?

    The configuration being described samples single analog input mode, 3 inputs 1 for each leg of the bridge.

    The electrical characteristic section of datasheet TM4C1294NCPDT list ADC latency 2 ADC clocks = (125ns), (Ts)= 250ns sample time, (Tc) 1us conversion @1Msps. Setting ADC hardware averaging 32x divides (Ts) 250ns, rending a (Ts) 8us sample plus 1us (Tc) = 9.375us total yet still an incredibly short time. Believe the sampling capacitor formula adjusts the ADC internal sample hold period based on the expected analog input resistance is omitted from the electrical section and is waiting for update in 2Msps electrical section?

    Now sampling with ADC inside LM3S8971 MCU - ADC Now have over sample 32x= (Ts) 9.4us is capturing current rising slope @match CMPB down. The ADC now samples for three very precise INA282 shunt monitors on the low side MOS. Possibly the TM4C1294NCPDT ADC phase control time delay can be of help for insisting center trigger-errs? A time phase delay added to ADC1 after the PWM Load match trigger might actually catch rising current peaks instead of my perceived falling envelope.

  • Amit Ashara said:
    it has to be kept in mind that the ADC will sample the data after resynchronizing the PWM trigger to it and then start charging the Sampling Cap for 4 clocks of 16MHz

    Hi Amit,

    I blew up that portion of your explanation which is "outside my knowledge."   We know that sometimes you're forced to write "fast-furiously" and the writing I've highlighted seems to grant (at least to me) "NEW POWERS" to the ADC!   I was (and remain now) "unaware" of the ADC's ability to "Resynchronize any PWM Trigger!"

    Would not any such "resync" of the PWM Trigger by the (pardon) lowly ADC - "throw into ruin" the entire concept (at least a substantial part of same) of PWM Triggered ADC measurements?  

    We know that multiple, PWM Generators are often "Sync'ed" and the MCU manual explains that process as intended to prevent, "ill formed PWM pulses."  That said - never/ever - here or w/in multiple other ARM MCU manuals - have I read of the "ADC being able to "boss/control" the PWM Generator."

    Would you be so kind as to give a quick read/review of that past paragraph - and then confirm/deny - the ADC's "resync" of the PWM Trigger.   Should you verify this - does it appear anywhere where we "mortals" (w/out regular/serious access to "insider info) may read in some detail?

    Thanks your time/attention...

  • Hello cb1,

    The PWM works in System Clock Domain (and add to that the divider options) while ADC is fixed 16MHz clock domain. To ensure that the Clock Domain Crossing is well met for transfer of the trigger signal, the Trigger signal is to be synchronized across the two domains.

    It sounds bad, but in actual circuit it may not be that bad as the current or voltage change being measured will also have an inertia and we can (in an ideal condition of no sync) meet the actual sampling time frame,

    Regards
    Amit
  • "the ADC will sample the data after resynchronizing the PWM"

    Good enough reason why a generic PWM to ADC signal timing diagram is needed, possibly with an example SYSCLK & PWMCLK reference signal. Good to have some electrical characteristics section or conditional (latency specifications) when PWM is asserting ADC triggers. Otherwise we are basically flying blind and at the mercy of the white jacketed silicon laboratory wizards. Data sheet states PWM generator Up/Dn comparator matches are ignored during Load and Zero should they coincide but when would that exact event ever occur?

    Now discovered might be hidden PWM timing issues when triggering an ADC sample via comparator B down from PWMGEN0. To make matters worse we sample BEMF in the very same trigger event. Issues seem to show up as what appears to be shoot through on the low side MOSFETS even with Dead Band generator asserted @140ns delay. Might even be the BEMF sample gets stepped on and commutation crashes shorts out one FET most always in the center. CB1 poked at this in earlier post mentions duty cycle issues but did not relate any symptom it might avoid. I don't generally aspire to the idea everyone else does it this way and what to know why or what is the advantage or disadvantage for doing so. Worst thing is comparator B down ADC trigger works great for low pole counts (8) but may be flaky at far greater pole counts especially during motor acceleration. Hi ho hi ho back to center trigger we go - to rule that out among other ADC SW changes.
  • Hello BP101,

    The issue with synchronization is it guarantees the signal propagation, but it can have a variation of 1 clock based on the PTV conditions. So a timing diagram would be more misleading.

    Regards
    Amit
  • "The PWM works in System Clock Domain (and add to that the divider options) while ADC is fixed 16MHz clock domain"

    Regards to the TM4C1294NCPDT; Does not the ADC (sample clock) run at 1 or 2 Msps derived from a divided SYSCLK only for sampling. The 480mHz PLL/30 MOSC clocks the ADC peripheral @16mHz for conversions and data across the peripheral interface onto the local bus but not for sampling or triggering sequencers.

    My take on ADC trigger based on data sheet TM4C1294NCPDT is ADC trigger always runs synchronous with PWM:

    The PWM peripheral runs from divided SYSCLK to generate a 60MHz PWM clock same SYSCLK for ADC sample clock. That said, the PWM generator triggers the ADC channel sequencer ADCEMUX to enable sampling and runs synchronous by rule of same clock source. It doesn't add up the ADC sequencer or trigger running at ADC peripheral clock speed 16MHz when sampling is far slower at 1-2 Msps filling the sequence FIFO at the sample rate and or constrained by hardware averaging.

  • When one is comparing a resulting trapezoidal wave form to the datasheet, a single LOAD match appears to be dead center each Trapezoidal wave (yellow, cyan, magenta) and created by three configured PWM generators. Other words It is not instantly apparent the sloping count ^ builds only a single pulse even upon reading the text. Until recently believed figure 23-4/5 was a mirror for the entire trapezoidal wave form.

    The (re-load) count is hidden in Tivaware, Stellarisware function calls (PWMPulseWidthSet), (PWMGenPeriodSet) not exposed on the surface the counter was being reloaded every 80us for 12.5kHz frequency or 50us for 20Khz. Imagine my surprise to find the PWM peripheral was not producing the Trapezoidal wave from without extensive software routines reloading the count every single pulse and not at the start/end of a trapezoidal wave. Further if one ever reviews the resulting phase current captured signal it takes a dip dead center of the wave form on LOAD match shown in Figure 23-4. That's is why the PWM clock edges being illustrated in figure 23-4 would make it directly understood many reloads are required to build the trapezoidal wave.
  • Hello BP101,

    Note that it has the default setting of ADC is the PIOSC, which can be different in phase and frequency from the System Clock. When moving to the VCO-divided down clock, the only thing being maintained is the phase of rising edge on the slow clock from the fast clock. The frequencies are still different.

    Regards
    Amit
  • "The only thing being maintained is the phase of rising edge on the slow clock from the fast clock"

    Ok - yet in this case SYSCLK is used to clock both peripherals in regards PWM to ADC trigger and sample sequencer. Again one might deduct there should be no discontinuity between the PWM and ADC peripheral trigger edge timing or perhaps not.

    Seems like your inferring there to be issues in the clocking of FIFO data onto the local bus when the 16Mhz ADC clock skews apart from SYSCLK the sample sequencer is delayed by up to 1 SYSCLK before acting on the PWM trigger. The ADC then sets a trigger wait state on the sequencer array delaying 1 SYSCLK before acknowledging the request to the PWM generator and waiting until both clocks are again synchronized to finally process that request?

    Good question you knew I was going to ask: How often does SYSCLK skew occur and can it be mitigated by software in some way?

    Like this new feature of TM4C1294NCPDT ADC: Busy Status

    The BUSY bit of the ADCACTSS register is used to indicate when the ADC is busy with a current conversion. When there are no triggers pending which may start a new conversion in the immediate cycle or next few cycles, the BUSY bit reads as 0. Software must read the status of the BUSY bit as clear before disabling the ADC clock by writing to the Analog-to-Digital Converter Run Mode Clock Gating Control (RCGCADC) register.

  • Hello BP101

    The Busy bit is for Software Triggered Conversion using ADCPSSI register. For the software to time a HW trigger, it would be best to run both modules at the System Clock/PLL VCO. That way the clock balancing will ensure 1 or 2 of ADC Clock Cycle (based on part to part variation).

    Regards
    Amit
  • That aspect Busy signal new improved integral part of TM4C FIFO appears to support your explanation hardware resynchronization of ADC sequencer to PWM generator trigger at the ADC peripheral local bus timing. Hence the hidden circuit timings TI chooses to omit from datasheet order to keep copy right infringements in nondisclosure.

    No matter that information will not help us migrate the LM3S8971 attempting to support INA282 current sensors sampling prior migration TM4C. There are issues with the ADC building monotonic order from samples triggered center or end of pulse yet it appears more (current) data is actually collected near the end.

    e2e.ti.com/.../1412082

    TM4C architecture gives Hope rainbows will appear after migration but the horse needs a carrot or he's not going to budge!

    Think it might be more prudent to use the phase delay aspect TM4C1294 and LAG ADC1 separately sampling current measures in the envelope triggered from PWM0Gen1 or even attempt the SKEW configuration to sample these INA282 sensors.

    Amit many thanks for other useful ideas :)
  • Hello BP101,

    I have to put up an enhancement request for making the ADC Sample at the right time (well defined clocks) so that future applications can benefit from this discussion thread. Thanks to you and cb1...

    Regards
    Amit
  • Thanks Amit,
    Something more profound came out this thread. TI could add an ability to set a number of peripheral clock wait states after the PWM generator triggers ADC, lagging behind the sample time. Setting the ADC hardware averaging 32x just to capture a small portion of what may not be even the average is troubling. Suspect 32x sample time (9.4us) might possibly interfere with the minimum pulse width constraint low (.5us) when triggering ADC sample on PWM generator comparator B down.

    3/5/2015 Setting ADC sample trigger match comparator B down interfered with sensorless commutation also being in the same sample as current measure. That results in crashing the commutation timer on very rapid motor acceleration and shoot through occurs every single time.

  • Hello BP101,

    That is what the enhancement is all about!!!

    Regards
    Amit