Interruption always active

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

cross mob
TimoTtt
Level 2
Level 2
10 sign-ins First like received 5 replies posted

Hello, i am a french student working with a P SOC 5LP CY8CKIT-059 (CY8C5888LTI-LP097)

 

My project is to build a functional timer with a 2 digit seven segment, and i need to be able to pause (or at least reset) my timer and buzz when i get sent a signal.

 

So, i decided to use a button to simulate the received signal while my teammates work on it.

And, so far, i've managed to make the buzzer and the seven segment work, but i can't seem to make the interruption work no matter what i do, it remains in an active (high) state.

 

Could you have any advice for me? i tried using NOT gates, changing the ISR state from derived to high-state and everything i could think of but it doesn't work.

 

Thanks for your understanding.

 

P.S: i use switch case for the timer, hence the cut in the middle of the code screenshots.codebas.PNGcodehaut.PNGPins.PNGtopdesign.PNG

 

Timothée ZEUGIN, IUT GEII TOURS, 2022-2025

Timothee.zeugin@etu.univ-tours.fr

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,
I tried with my CY8CKIT-059, and as I don't have 2 digit 7seg, I used UART instead,
but it should work for 7segs, too.

Schematic

002-Schematic.JPG

Pins

003-Pins.JPG

TeraTerm log

001-TeraTerm-log.JPG

When I push SW2 on the CY8CKIT-059, the timer stars/pauses.

main.c

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

#define STR_LEN 64
char str[STR_LEN+1] ;

volatile int sw2_flag = 0 ;
volatile uint32_t tick_count = 0 ;
volatile int one_sec_flag = 0 ;
volatile int second = 0 ;
volatile int run = 1 ;

CY_ISR(sw2_isr)
{
    sw2_flag = 1 ;
    SW2_ClearInterrupt() ;
    if (run == 0) {
        run = 1 ;
    } else {
        run = 0 ;
    }
}

void print(char *str)
{
    UART_PutString(str) ;
}

void cls(void)
{
    print("\033c") ; /* reset */
    CyDelay(100) ;
    print("\033[2J") ; /* clear screen */
    CyDelay(100) ;
}

/* utility functions for systick */

CY_ISR(tick_callback)
{
    if (run) {
        tick_count++ ;
    }
    if (tick_count >= 1000) {
        tick_count = 0 ;
        one_sec_flag = 1 ;
        second++ ;
    }
}

int find_empty_slot(void)
{
    int result = -1 ;
    uint32_t i ;
    for (i = 0 ; i < CY_SYS_SYST_NUM_OF_CALLBACKS ; i++ ) {
        if (CySysTickGetCallback(i) == NULL) {
            result = i ;
            break ;
        }
    }
    return(result) ;
}

void init_hardware(void)
{
    int sys_tick_slot = 0 ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    int_sw2_ClearPending() ;
    int_sw2_StartEx(sw2_isr) ;

    sys_tick_slot = find_empty_slot() ;
    if (sys_tick_slot < 0) {
        print("Sorry No empty SysTick Slot available\n\r") ;
        while(1) { } /* halting here */
    } else {
        CySysTickStart() ;
        CySysTickSetCallback(sys_tick_slot, tick_callback) ;
    }
    
    UART_Start() ;
    cls() ;
}

int main(void)
{
    init_hardware() ;
    
    snprintf(str, STR_LEN, "CY8CKIT-059 GPIO INT Test (%s %s)\n\r",__DATE__, __TIME__) ;
    print(str) ;

    for(;;)
    {
        if (sw2_flag) {
            sw2_flag = 0 ;
            if (run == 1) {
                print("Timer started\n\r") ;
            } else {
                print("Timer paused\n\r") ;
            }
        }
        if (one_sec_flag) {
            one_sec_flag = 0 ;
            snprintf(str, STR_LEN, "%d\n\r", second) ;
            print(str) ;
        }
    }
}

Some additional notes,
As CyDelay() may not be accurate enough for a timer, 
I used SysTick (hopefully, better)

moto

View solution in original post

0 Likes
5 Replies
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,
I tried with my CY8CKIT-059, and as I don't have 2 digit 7seg, I used UART instead,
but it should work for 7segs, too.

Schematic

002-Schematic.JPG

Pins

003-Pins.JPG

TeraTerm log

001-TeraTerm-log.JPG

When I push SW2 on the CY8CKIT-059, the timer stars/pauses.

main.c

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

#define STR_LEN 64
char str[STR_LEN+1] ;

volatile int sw2_flag = 0 ;
volatile uint32_t tick_count = 0 ;
volatile int one_sec_flag = 0 ;
volatile int second = 0 ;
volatile int run = 1 ;

CY_ISR(sw2_isr)
{
    sw2_flag = 1 ;
    SW2_ClearInterrupt() ;
    if (run == 0) {
        run = 1 ;
    } else {
        run = 0 ;
    }
}

void print(char *str)
{
    UART_PutString(str) ;
}

void cls(void)
{
    print("\033c") ; /* reset */
    CyDelay(100) ;
    print("\033[2J") ; /* clear screen */
    CyDelay(100) ;
}

/* utility functions for systick */

CY_ISR(tick_callback)
{
    if (run) {
        tick_count++ ;
    }
    if (tick_count >= 1000) {
        tick_count = 0 ;
        one_sec_flag = 1 ;
        second++ ;
    }
}

int find_empty_slot(void)
{
    int result = -1 ;
    uint32_t i ;
    for (i = 0 ; i < CY_SYS_SYST_NUM_OF_CALLBACKS ; i++ ) {
        if (CySysTickGetCallback(i) == NULL) {
            result = i ;
            break ;
        }
    }
    return(result) ;
}

void init_hardware(void)
{
    int sys_tick_slot = 0 ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */

    int_sw2_ClearPending() ;
    int_sw2_StartEx(sw2_isr) ;

    sys_tick_slot = find_empty_slot() ;
    if (sys_tick_slot < 0) {
        print("Sorry No empty SysTick Slot available\n\r") ;
        while(1) { } /* halting here */
    } else {
        CySysTickStart() ;
        CySysTickSetCallback(sys_tick_slot, tick_callback) ;
    }
    
    UART_Start() ;
    cls() ;
}

int main(void)
{
    init_hardware() ;
    
    snprintf(str, STR_LEN, "CY8CKIT-059 GPIO INT Test (%s %s)\n\r",__DATE__, __TIME__) ;
    print(str) ;

    for(;;)
    {
        if (sw2_flag) {
            sw2_flag = 0 ;
            if (run == 1) {
                print("Timer started\n\r") ;
            } else {
                print("Timer paused\n\r") ;
            }
        }
        if (one_sec_flag) {
            one_sec_flag = 0 ;
            snprintf(str, STR_LEN, "%d\n\r", second) ;
            print(str) ;
        }
    }
}

Some additional notes,
As CyDelay() may not be accurate enough for a timer, 
I used SysTick (hopefully, better)

moto

0 Likes

Hello man, thank you for the reply it's really really appreciated.

I try to understand your code but everything is so complicated it makes my whole code looks like hello world compared to it ;-;

 

I will try and extract whatever i can understand from it to make the interrupt work, i think the idea of using an actual interruptor in the TopDesign is perhaps what i needed.

 

I think i will stick to my timer using switch case because yours looks like i would need thousand of hours to even begin to understand it lol.

 

Hope you have a wonderful day :D.

 

ZEUGIN Timothée

0 Likes
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, 
I tried to make the code eaiser to read. 
This time it contains only SW2 interrupt handling with LED1 on/off.
And main.c is less than 30 lines 😉

main.c

#include "project.h"

volatile int sw2_flag = 0 ;    /* SW2 pin pushed flag, note "volatile" */

CY_ISR(sw2_isr)
{
    SW2_ClearInterrupt() ;     /* First clear interrupt flag of the pin */
    sw2_flag = 1 ;             /* Flag that SW2 pin was pushed */
}

int main(void)
{
    CyGlobalIntEnable;         /* Enable global interrupts. */
    
    int_sw2_ClearPending() ;   /* Clear Pedings, may be not necessary         */
    int_sw2_StartEx(sw2_isr) ; /* Start pin interrupt with sw2_isr as the ISR */

    for(;;)
    {
        if (sw2_flag) {             /* SW2 was pushed */
            sw2_flag = 0 ;          /* First clear the interrupt flag */
            if (LED1_Read() == 0) { /* LED1 is off now */
                LED1_Write(1) ;     /* Turn LED1 ON    */
            } else {                /* LED1 is ON now  */
                LED1_Write(0) ;     /* Turn LED1 OFF   */
            }
        }
    }
}

Schemaitc

101-schematic.JPG

pins

102-pins.JPG

Hope this will serve you better.

moto

 

TimoTtt
Level 2
Level 2
10 sign-ins First like received 5 replies posted

Hello, sorry for bothering you after thinking it was solved.

I am currently trying to program the switch (SW_1) like you did in the post but i don't understand why does it need to be connected to a 10k ohm resistor and to the VDD? and how does it work? because i have a 3 pin switch or a button but neither seems to work so i am very confused.

Thanks for your understanding.

 

Timothée ZEUGIN

0 Likes
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

Hi,

> I am currently trying to program the switch (SW_1) like you did in the post but i don't understand
> why does it need to be connected to a 10k ohm resistor and to the VDD?
You are right, it was my bad.
I thought I was copying the information from the CY8CKIT-059 schematic.

006-059-schematic.JPG

But somehow, I ended up with some wrong values. 
(Or it was the default value of the off-chip component...)
And make things worse, I left the LED as a resistor >_<
So please forget about the schematic. m(_ _)m 

To make the long story short, the sample should work
without any modification and/or additional component 
to the CY8CKIT-059.


moto

 

0 Likes