cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Highlighted
Observer
Observer
6,973 Views
Registered: ‎06-03-2015

Exact Delay Generation in PS

I would like to Delay Execution of PS progarm.

 

Can I use below code with AXI timer  for exact Delay Generation in PS??

 

------------------------------------------------------------

 

void usleep(unsigned int useconds)
{
    unsigned int timer_count = 0;
    unsigned int wait_for_timer = 0;
    unsigned int count_value = 0;

    wait_for_timer = 1;
    count_value = useconds * (PROCESSOR_CLOCK_FREQUENCY / 1000000);
    XTmrCtr_Disable(XPAR_TMRCTR_0_BASEADDR, 0);
    XTmrCtr_SetLoadReg(XPAR_TMRCTR_0_BASEADDR, 0, 0x00);
    XTmrCtr_LoadTimerCounterReg(XPAR_TMRCTR_0_BASEADDR, 0);

    // Set the timer running
    XTmrCtr_SetControlStatusReg(XPAR_TMRCTR_0_BASEADDR, 0, XTC_CSR_ENABLE_TMR_MASK);

    while (wait_for_timer)
    {
        timer_count=XTmrCtr_GetTimerCounterReg(XPAR_TMRCTR_0_BASEADDR, 0);
        if (timer_count > count_value)
        {
            wait_for_timer = 0;
        }
    }

    XTmrCtr_SetControlStatusReg(XPAR_TMRCTR_0_BASEADDR, 0, 0x00);

 }
0 Kudos
3 Replies
Highlighted
Explorer
Explorer
6,971 Views
Registered: ‎11-24-2013

Hello,

 

Every time you call a function to enable, disable or check the counter, the processor has to write or read to the peripheral through the AXI bus. Since you call the function until the counter starts, there will be a delay. Also, since the counter reaches your desired value until the processor "realizes" by reading it, a time interval will pass. If you have other peripherals generating interruptions, these times could vary.

 

So, I would say this is a way to generate delays, but not 100% exact.

 

Regards

Ignacio

Tags (2)
0 Kudos
Highlighted
Observer
Observer
6,950 Views
Registered: ‎06-03-2015

Hello,

 

Thanks for your reply. Is there any other way to generate exact delay in PS?

0 Kudos
Highlighted
Teacher
Teacher
6,937 Views
Registered: ‎03-31-2012

is this under any OS or bare metal? if you are not taking any interrupts in a bare metal configuration, the best "exact delay" you can do is to loop over the builtin counter till it gets to the number you want.
- Please mark the Answer as "Accept as solution" if information provided is helpful.
Give Kudos to a post which you think is helpful and reply oriented.
0 Kudos