Time Period Measurement in PSoC® 4 - KBA87496

Version: *C

 

Question:

How do you measure a time period using PSoC® 4?

 

Answer:

Many applications require measurement of the time interval between two events. In PSoC 4, you can use the timer, counter, pulse-width modulator (TCPWM) counter’s Capture function to measure a time period.

 

The example project attached with this article shows the measurement of the time interval between the two consecutive falling edges, which can be generated by button pressing events. The GlitchFilter irons out the glitch introduced by pressing a mechanical button to improve the demo experience. It can be saved if you are measuring a signal edge, which has no glitch. See Figure 1 for a screenshot of the schematic.

 

For more information on the underlying principle, see the PSoC 3/ PSoC 5LP knowledge base article Time Period Measurement.

 

Figure 1. Example Project Schematic

 

1.png

 

Table 1 lists the Components used in this example project.

 

Table 1. Components Used

                                                                                                                                                                                                                            

Instance NameComponent NameComponent CategoryComments
CounterTimer Counter (TCPWM mode)Digital > FunctionsConfigured as up counter with rising edge capture.
UARTUART (SCB mode) for the following families: PSoC4000S, PSoC 4100/4200 PSoC 4100M/4200M PSoC4200L PSoC 4100BLE/ 4200BLECommunicationsTransmit to PC the time interval between two events. Configuration is as follows: Baud rate: 115200; Data bits: 8; Parity: None; Stop bits: 1. Any serial port viewer can be used to view the time value.
Software Transmit UART for the PSoC 4000 familyCommunicationsTransmit to PC the time interval between two events. Configuration is as follows: Baud rate: 115200; PinAssignmentMethod: Static Any serial port viewer can be used to view the time value.
Pin_InputSignalDigital Input PinPorts and PinsDigital pin for the signal input
ISR_CounterInterruptSystemInterrupts on capture and terminal count of the Counter
Clock_CClockSystemConfigured for 3 MHz, as Counter component clock. Improve precision with a higher clock frequency.
Clock_GClockSystemConfigured for 1 kHz, as GlitchFilter component clock.
0Logic Low ‘0’Digital > LogicConfigured for 3 MHz. Improve precision with a higher clock frequency.
GlitchFilterGlitch Filter Only for the following families: PSoC 4200 PSoC 4200M PSoC 4200L PSoC 4200BLEDigital > UtilityConfigured for 3 MHz. Improve precision with a higher clock frequency.

 

Note: For device families that do not have a glitch filter, remove the GlitchFilter and its related components, and hook the Pin_InputSignal terminal directly to the capture terminal of the Counter component. In this case, if you need to filter the possible glitches in your application, you must leverage some other method, such as firmware processing.

 

The example project is for the PSoC 4200 device family and designed based on the CY8CKIT-042 kit. It was verified on PSoC Creator™ 3.2. You can use the PSoC 5LP USB-UART Bridge in the kit to view the UART output. Refer to the kit guide for information on how to use the built-in USB-UART Bridge. The implementation for the other PSoC 4 device families is similar; choose the corresponding kit for different device families.

 

You can use a serial port viewing program, such as HyperTerminal, to view the UART output. Figure 2 shows the configuration settings required for this project. Figure 3 shows the expected UART output.

 

Figure 2. HyperTerminal Configuration Settings

 

2.png

 

 

Figure 3. Expected UART Output

 

3.png