Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob

Delay Time Accuracy of PSoC® 4 CyDelay Functions

Delay Time Accuracy of PSoC® 4 CyDelay Functions

Anonymous
Not applicable

How accurate is the delay time of CyDelay() and CyDelayUs() functions with PSoC 4?

 

The CyDelay functions, CyDelay() and CyDelayUs(), implement simple software-based delay loops. These loops are designed to compensate for bus clock frequency and other factors, but there are additional factors that may also influence the actual time spent in the loop. The CyDelay functions provide a minimum delay. If the processor is interrupted, the length of the loop will be extended by as long as it takes to service the interrupt. Other overhead factors, including function entry and exit, may also affect the total length of time spent executing the function. This will be especially apparent when the nominal delay time is small. Without the interrupt intervention, the delay accuracies should be close to IMO accuracy (excluding the function entry and exit times), which clocks the CPU.

Table 1 provides a quick reference to the various CyDelay function prototypes. Complete details on the APIs can be found in PSoC® Creator™ System Reference Guide. The details are also available under Help > System Reference > System Reference Guide in PSoC Creator.

Table 1. CyDelay functions descritpion                                         

    Function Prototype     Arguments     Description
    void CyDelay(uint32 milliseconds)     uint32 milliseconds – Number of milliseconds to delay     Delay by the specified number of milliseconds. By default, the number of cycles to delay is calculated based on the clock configuration entered in PSoC Creator. If the clock configuration is changed at runtime, then the function CyDelayFreq is used to indicate the new Bus Clock frequency. CyDelay is used by several components, so changing the clock frequency without updating the frequency setting for the delay can cause those components to fail.
    void CyDelayUs(uint32 microseconds)     uint32 microseconds – Number of microseconds to delay     Delay by the specified number of microseconds. By default, the number of cycles to delay is calculated based on the clock configuration entered in PSoC Creator. If the clock configuration is changed at runtime, then the function CyDelayFreq is used to indicate the new Bus Clock frequency. CyDelay is used by several components, so changing the clock frequency without updating the frequency setting for the delay can cause those components to fail.
    void CyDelayFreq(uint32 freq)     uint32 freq – Bus clock frequency in Hz;
    0: Use default value
    Nonzero: Set freq value
    Sets the Bus Clock frequency used to calculate the number of cycles needed to implement a delay with CyDelay or CyDelayUs functions. By default, the frequency used is based on the value determined by PSoC Creator at build time.
    void CyDelayCycles(uint32 cycles)     uint32 cycles – Number of cycles to delay     Delay by the specified number of cycles using a software delay loop

 

If you need a more accurate method of calculating the delay time, consider using hardware timers like TCPWM, SysTick, or UDB-based timer components.

0 Likes
11573 Views