- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
So in my previous question, I could manage to measure interval of external IRQ signal.
https://community.cypress.com/t5/PSoC-6-MCU/PSoC-6-Measuring-IRQ-interval/m-p/279015#M10056
But then the customer wants to use a PSoC 6 without UDB. >_<
So I changed the strategy to get the capture value in the ISR,
and take care of the handling from software.
I changed the schematic something like
And in the ISR I "tried" to clear interrupt flag as below
void sensor_irq1_isr(void)
{
uint32_t source ;
source = Counter_1_GetInterruptStatus() ;
if ((source & CY_TCPWM_INT_ON_CC) != 0) {
Pin_2_Write(1) ;
sensor1_period = Counter_1_GetCapture() ;
sensor1_flag = 1 ;
}
NVIC_ClearPendingIRQ(SysInt_1_cfg.intrSrc) ;
Cy_TCPWM_ClearInterrupt(Counter_1_HW, Counter_1_CNT_NUM, source) ;
// Counter_1_Disable() ;
}
But this ISR seems to be called repeatedly.
The upper yellow signal is from CY8CKIT-044.
The lower purple signal is written to 1 inside ISR and cleared in the main loop.
So although I'm expecting seeing only 1 pulse around the falling edge of the input signal,
my CY8CKIT-062-BLE has been generating interrupts repeatedly.
I spent whole day today, but in vain. (T^T)
Probably I'm missing or misunderstanding something...
Now my question is what is the proper method to clear interrupt of TCPWM (Capture)
and reload the counter (TCPWM) to count next interval?
main_cm4.c
#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)
{
uint32_t source ;
source = Counter_1_GetInterruptStatus() ;
if ((source & CY_TCPWM_INT_ON_CC) != 0) {
Pin_2_Write(1) ;
sensor1_period = Counter_1_GetCapture() ;
sensor1_flag = 1 ;
}
NVIC_ClearPendingIRQ(SysInt_1_cfg.intrSrc) ;
Cy_TCPWM_ClearInterrupt(Counter_1_HW, Counter_1_CNT_NUM, source) ;
// Counter_1_Disable() ;
}
void sensor_irq1_init(void)
{
#if 0
const cy_stc_sysint_t SysInt_1_cfg = {
.intrsrc=(IRQn_Type)SysInt_1__INTC_NUMBER,
.intrPriority = SysInt_1__INTC_CORTEXM4_PRIORITY
} ;
#endif
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() ;
Counter_1_Start() ;
}
int main(void)
{
int32_t prev_period = -1 ;
int32_t period = 0 ;
int32 count = 0 ;
char fun[] = { '|', '/', '-', '\'' } ;
int fun_index = 0 ;
init_hardware() ;
cls() ;
splash("PSoC 6 Interval Timer Test") ;
// Counter_2_Start() ;
for(;;)
{
if (sensor1_flag) {
Pin_2_Write(0) ;
period = sensor1_period ;
sensor1_flag = 0 ;
Counter_1_TriggerReload() ;
// Counter_1_Enable() ;
#if 0
if (prev_period != period) {
snprintf(str, STR_BUF_LEN, "Sensor1: %d\n\r", period) ;
print(str) ;
prev_period = period ;
CyDelayUs(100) ;
} else {
count++ ;
if (count > 100) {
count = 0 ;
fun_index = (fun_index + 1) % 4 ;
snprintf(str, STR_BUF_LEN, "\b%c", fun[fun_index]) ;
print(str) ;
}
}
#endif
}
}
}
Any suggestions and/or corrections will be appreciated.
moto
Solved! Go to Solution.
- Labels:
-
PSoC 6 MCU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @MotooTanaka
This is not a solution but could you try generating an interrupt on the falling of the sensor signal and read the timer count in the corresponding interrupt handler?
As shown in the CE219521 – PSoC 6 MCU - GPIO Interrupt code example, the input signal (sensor irq) could be used to generate an interrupt.
The proper method to clear TCPWM interrupt is shown in the code snippet provided in PSoC 6 API Reference manual which is similar to what you have done
I will try to recreate the issue at my end and get back to you.
Thanks and Regards
Ekta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @MotooTanaka
This is not a solution but could you try generating an interrupt on the falling of the sensor signal and read the timer count in the corresponding interrupt handler?
As shown in the CE219521 – PSoC 6 MCU - GPIO Interrupt code example, the input signal (sensor irq) could be used to generate an interrupt.
The proper method to clear TCPWM interrupt is shown in the code snippet provided in PSoC 6 API Reference manual which is similar to what you have done
I will try to recreate the issue at my end and get back to you.
Thanks and Regards
Ekta