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.

DELAY_US convert to nanosecond

One quick question concerning the Delay-US macro. My understanding is that the Delay_US takes in an input that is 32 bit unsigned integer. I would like to put a decimal value in to reach a certain frequency or convert the Delay_US macro into a nanosecond delay so that I can achieve these same frequencies. Are there any recommendations on how to do this to be as precise as possible?

Thanks

  • Hi,

    Why not make use of asm nop instruction; which would in turn introduce a delay of 1clock cycle ie 6.67ns for a 150MHz clocked controller.

    Regards,

    Gautam

  • The problem is I'm trying to create an accurate 12.5 us delay so I can generate a 40 kHz square wave. I don't want to use a PWM simply because I only use a few cycles before changing the period and then stopping the output. And creating a 500 ns delay with asm(NOP) would require calling that function a bunch of times, which increases the memory that the .txt takes up. And if I put it in a software loop, then I'm adding a undetermined delay for the software to service the loop.

     

  • Matthew, all that you've mentioned above is cent percent true and I agree with that. Then the only option that remains is toggling using timer. What do you say?

    Regards,

    Gautam

  • Great. And thats what I've been doing more or less. I'm using code that looks like this:

    while(count1++<Cycles1)
    {
    GpioDataRegs.GPATOGGLE.all |= 0x0003;
    EPwm2Regs.TBCTR = 0;
    while(EPwm2Regs.TBCTR < Toggles[0]){}
    }

    Unfortunately, I can't get as exact results as I would like. Is there a way to load a new period into a PWM during an interrupt? I tried but unfortunately I received an error and the code wouldn't execute. I know there must be because of the Shadow Load registers, but I'm afraid I don't know how to use it. 

    Also, I will be outputting a signal on 9 different pins, which requires a lot of power consumption and PWM pins if I were to use all PWMs,which makes the GPIO toggle with timer a little bit better. Of course, I could use a MUX, but for now I can just use the GPIO toggle with timer. 

  • Hi,

    Is there a way to load a new period into a PWM during an interrupt?

    Did you try with

     EPwm2Regs.TBPRD = 750;   	//In your ISR

    Regards,

    Gautam

  • Also why don't you try modifying/adding a new delay found here : in  "DSP2833x_Examples.h"

    By default here is the routine for Delay_US:

    #define DELAY_US(A)  DSP28x_usDelay(((((long double) A * 1000.0L) / (long double)CPU_RATE) - 9.0L) / 5.0L)

    Try editing :)

    Regards,

    Gautam