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.

How to generate a really short GPIO pulse (1 clock cycle)

Other Parts Discussed in Thread: TM4C123GH6PM, TPS56628

I'm trying to generate a pulse which lasts just one or two clock cycles (125ns~250ns) for triggering an external sample and hold buffer on a TM4C123GH6PM with 80MHz clock.

I can do this with the PWM module and it kind of works... the only problem is I can't seem to stop it and synchronising it is a pain (I need to be able to generate it on command, not at a repetitive frequency. I can zero the PWM counter, but I can't set the phase from what I can see in the API, which means the pulse occurs too late to be useful.)

If I drive the output directly through GPIOPinWrite (which I assume is fairly fast - it takes about 5 clock cycles) the pulse is too long because it still has to do all those clock cycles. Maybe there's a way to toggle the pin at the register level with two XORs for example; I haven't tried that yet.

I can't use the timer module because there doesn't appear to be a pulse generation option. I could use an external pulse generation solution but I'd prefer not to if there's a way to do it with the MCU.

  • Might it make more sense to resolve, "yesterday's business" prior to launching anew?

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/349898.aspx

    Multiple responders jumped to your request - some order/courtesy should be shown - don't you agree?

  • Thanks for that - now quickly to (your) today's issue.

    Best means I believe to achieve so brief a pulse is via (again) a Timer - but configured into PWM Mode.  By setting the duty cycle very, very low - a minimal width pulse may be generated.  BTW - it is only via the Timer - set to PWM mode - that most ARM MCUs can propagate the timer signal to an external pin.

    Should this method not work - you should read/review the "high performance bus" - which will enable faster and briefer gpio pulse output.

    Very brief pulses may not be the strong suit/sweet spot of Cortex M4 - but your experimentation and report back will serve to benefit others...

  • That's my fault for not updating that thread. Sorry about that, have done so... This question is unrelated to the last, as that issue has since been resolved. I've now got my MCU syncing to VGA video, so the next challenge is to get it sampling averaged points of the video signal for this monthly personal project. (I want to get PCBs sent away as fast as possible so I'm in a bit of a rush.)

  • Dreaded, "Post Crossings!"  (1 minute apart)  Please vector up two - see if my suggestion blips your radar...

    Tom Oldbury said:
    I'm in a bit of a rush

    And - is anyone - anywhere - not in that very situation?   None here caused your dilemma - we should not be tasked now to rectify...

    Even more telling - the average response time to both of your most recent, initial posts was 12.5 minutes!  One doubts even a, "paid service" could approach (yet alone match) that!...  (rush indeed...)

  • I'm an electronics engineering student... not a professional engineer (yet? £18k in tuition so far!)

    Most of my background is with PICs/dsPICs (including assembler) and more recently STM32s. (Never touched an Arduino.) However I decided to jump over to Tiva MCUs due to a suggestion by my lecturer. It's especially useful that you can use the Launchpad as a budget JTAG programmer! I did my 2nd year project with the TM4C123GH6PM -- and there was just a single Q on that I asked and it worked great.  This is a monthly project I set myself -- an Ambilight clone for my TV. (Look up Philips Ambilight.) I'm doing it with 210 WS2812B RGB LEDs arranged around a 50" screen. I've gotten the RGB LEDs and video sync timing working and all purely interrupt driven now. And a Noritake VFD working. The final stage is to sample the VGA video, store it in an array, and then output it to the RGB strips. But there's a deadline to hit to get in on a group buy for PCBs and I need to prove that the concept will work before I get the rather large PCB made up at fair expense. Due to the high speed analog, it's a 4 layer board with 6/6 rules and a guaranteed impedance.

    Needless to say, I'm extremely grateful for the help, and don't want to seem as anything but. I work first, jumping from problem to problem, trying to prove prototypes for now, rather than finish anything thoroughly. I just need to know something will work... or I have to think about other options, switching to a different MCU, changing circuit architecture, etc.

    More of a learning challenge than anything practical - not a commercial product by any means.

  • RE: PWM output. I've tried that already. And it does kind of sort of work, but the problems so far I'm encountering are:

     - It's not possible to set the phase of the output (or is it, please someone prove me wrong?)

     - Turning on the output takes many uS if using enable due to long instruction path - maybe I can HWREG just the ENABLE bit, I haven't tried this yet

     - No DOWNCOUNT mode for PWM timers so that's not an option for zeroing phase. 

    The alternative idea: I could pulse a GPIO line coupled through a capacitor into an inverter. With some RC timing math I can set the pulse to be very narrow. Trouble is - how well will a 74LVC "OneGate" handle such - surely it will be affected by ambient temperature etc. My LED strips draw about 40W full white and there are two TPS56628 switchers on the board for the left & right LED power bus, supply 4.5V@4.3A each... these will get hot & will vary in temp with the displayed content so I imagine there would be some effect... this is all a TBD if I got this route ofc.

  • Use of an R-C network to generate precise/narrow pulse - may not reside too many textbooks...

    It is possible to "sync" between multiple PWM Generators and I believe that each may enjoy variable duty cycle.  But the set-up/config and sync of such is far more demanding than the KISS (simple timer) method I've suggested.  And - somewhere we read of, "rush."

    Continue to suggest that you invest the 30 minutes or so - and try the Timer as PWM Generator - set to extremely low duty cycle.  I suspect that you will be able to "dial this down" to 2-5 timer cycles - perhaps even less.  (We did this year's past - but work w/multiple vendor's ARMs - cannot recall which...)  To me - this is the fastest/easiest means to generate your requested, very narrow pulse - which we learn now has received (still unclear - at least to me) phase synchronization restrictions.  (of course that detail "escaped" forum title...)

    You don't really explain/justify your belief that, "Timer Enable" encounters a long, instruction path.  Might you make some effort - we don't find that!   (have you consulted the driver library - and reviewed the code sequence w/in timer enable?)

    That's my best, quick effort - your behalf. 

  • So I'm reading through the documentation on the Timer module, and it has a section on PWM. I've always been making the assumption that when I use the PWM API that it's a separate peripheral independent of the timers. Can a timer be set up to output PWM independent of any PWM module...?

    Precision of the pulse = not important really, it just needs to be in the range 100~300ns every ~2us. Ideally consistent -- as a change in the pulse width will change the behaviour of the S/H & amplifier. I need the 2us to take two ADC samples (one channel samples R,B, the other samples G... the sample/hold amplifier is needed because the Tiva doesn't have independent S/H for each input and I'd have one of the colours out of sync.)

    I have already tried the PWM timer enable. I can see when the ISR begins via LED pulse on the scope... and about 3us later the timer enable occurs because the output PWM pulses appear. It's about the same for disable. The problem is one VGA line is 33us... and I need to extract as many pixels as possible from it especially around the edges.

  • A quick read of the timer section of the MCU manual reveals the, "how/why" of massaging the timer into PWM output upon the timer's external pin.  Yes - the timer may serve as a quite robust PWM generator - completely independent of any PWM module. 

    Suspect your larger challenge may be acquiring & processing your ADC data @ 2uS intervals.  During any one sequence you can surely achieve that - but on a consistent, on-going basis - I'm not so sure. 

    You speak of "PWM timer enable" - but w/o any code nor further detail - it's not easy to "intuit" how/why you incur a 3uS penalty...