PSoC 6 Measuring IRQ interval

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

cross mob
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

One of my customer wants to measure time between external IRQ signal,

which is supposed to be about 1ms.

So I tried with the following schematic using CY8CKIT-062-BLE.

Note: Counter_2 is used to generate dummy IRQ signal generator.

011-schematic.JPG

And Tera Term output seems to be OK,

Note : I'm changing the interval by 1 in the firmware loop.

010-Tera-Term-log.JPG

But the customer is anxious if triggering both reload and capture with same edge could cause wrong sequence,

for example, if there is/are chance that the captured value is the reload(ed) value (aka 0).

IMHO, if TCPWM was designed in usual sync manner, 

the following two will take place at the same time,

so captured value won't be overwritten with the reload value.

(1) Counter Value -> Capture Value

(2) 0 -> Counter Value

 

Question: Is my assumption correct?

Or is/are there something I need to be aware of to do this measurement?

My test project is attached.

 

moto

 

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

It's been a long (wrong?) day.

So I changed schematic something like

001-schematic.JPG

Pins

002-Pins.JPG

Somehow with my CY8CKIT-062-BLE, restore input did not seem to clear the counter.

So I added Timer_1_SetCounter(0) in the main loop

#include "project.h"
#include "stdio.h"
#include "tty_utils.h"

volatile int32_t sensor1_period = 0 ;
volatile int     sensor1_flag = 0 ;

void Pin_2_Write(int v)
{
    Cy_GPIO_Write(Pin_2_0_PORT, Pin_2_0_NUM, v) ;
}

void sensor_irq1_isr(void)
{
    int32_t source ;
    
    Pin_2_Write(1) ;
    sensor1_flag = 1 ;
    sensor1_period = Counter_1_GetCapture() ;
    source = Counter_1_GetInterruptStatus() ;
    Counter_1_ClearInterrupt(source) ;
}

void sensor_irq1_init(void)
{
    const cy_stc_sysint_t SysInt_1_cfg = {
        .intrsrc=(IRQn_Type)SysInt_1__INTC_NUMBER,
        .intrPriority = SysInt_1__INTC_CORTEXM4_PRIORITY
    } ;
    Cy_SysInt_Init(&SysInt_1_cfg, sensor_irq1_isr) ;
    NVIC_ClearPendingIRQ(SysInt_1_cfg.intrSrc) ;
    NVIC_EnableIRQ((IRQn_Type)SysInt_1_cfg.intrSrc) ;
}

void init_hardware(void)
{
    __enable_irq(); /* Enable global interrupts. */    
    
    Pin_2_Write(0) ;
    
    tty_init() ;
    
    sensor_irq1_init() ;
    
}

int main(void)
{
    int32_t prev_period = 0 ;
    int32_t period = 0 ;
    int32_t delta = 0 ;
    int32_t test_period = 0 ;
    int32   count = 0 ;
    
    init_hardware() ;
    
    cls() ;
    
    splash("PSoC 6 Interval Timer Test") ;
    
    Counter_1_Start() ;

    for(;;)
    {
        if (sensor1_flag) {
            Pin_2_Write(0) ;
            Counter_1_SetCounter(0) ; // <=======
            period = sensor1_period ;
            sensor1_flag = 0 ;
            if (prev_period != period) {
                snprintf(str, STR_BUF_LEN, "Sensor1:%d\n\r", period) ;
                print(str) ;
           
                prev_period = period ;
            }
        }
    }
}

Now my PSoC 6 project can measure the interval of the negative pulse output of PSoC 4 project.

 

PSoC 4 (Signal Generator Project) Tera Term log

004-PSoC4_TeraTerm.JPG

PSoC 6 (Interval Measurement Program)

(Showing the last part of the previous PSoC 4 output, period = 2000 with 2MHz clock)

003-PSoC6_TeraTerm.JPG

I'm glad that I could follow Len-san's suggestion and tested with an external signal 😉

moto

Note: Attached projects

PSoC 6 (CY8CKIT-062-BLE) timer_test_210606b

PSoC 4 (CY8CKIT-044) timer_test_210606

... I should have payed more attention about naming the project ... >_<

View solution in original post

0 Likes
7 Replies