You are here

Does ISR for 16-bit PSoC 1 Timer have to be written in assembler? | Cypress Semiconductor

Does ISR for 16-bit PSoC 1 Timer have to be written in assembler?

Summary: 5 Replies, Latest post by Bob Marlowe on 20 Dec 2016 12:38 PM PST
Verified Answers: 0
Last post
Log in to post new comments.
tonypayn902_1586141's picture
User
6 posts

The reason for this question is that the data sheet for the User Module says, in the example C code:

The same code in C is as follows. Note that the interrupt routine must be written in assembly.

I note however that the User Module comes with an example project, which uses an ISR written in C, so I am wondering it the statement in the User Module data sheet is simply incorrect.

My datasheet is version 2.6, Designer is version 5.4.

I note also that the Compiler Guide says:

To associate the interrupt handler with an interrupt, add ljmp _name at the interrupt vector in the boot.tpl file.

When I look in the boot.tpl file, it says:

    org   38h                      ;PSoC Block DCC12 Interrupt Vector
    `@INTERRUPT_14`
    reti

so I think the compiler guide is asking me to change this so that it reads:

    org   38h                      ;PSoC Block DCC12 Interrupt Vector
    ljmp _MyTimer16Interrupt
    reti

 

Would that be correct?  If I do this, it builds but with a warning "old-style function definition for `MyTimer16Interrupt'"

and it warns me that 'boot.asm' has been modified outside of the editor, do I want to reload it. (Words to that effect.)

I can't help thinking that, despite following the instructions, I'm not doing whatever it needs to make it entirely happy.  Any suggestions?

 

user_1377889's picture
User
9947 posts

You have to tell the compiler that "MyTimer16Interrupt" is an interrupt handler by declaring

#pragma interrupt_handler MyTimer16Interrupt

See "ImageCraft C Compiler Guide"

 

Bob

tonypayn902_1586141's picture
User
6 posts

Thanks Bob, I did do this (add the #pragma statement) but am still having problems.

To try and get it working, I have created a simple project that does nothing more than setup a timer16 and interrupt on terminal count.  During the ISR, it is supposed to toggle a port line.

The project is for CY8C29466-24PXI.  There is one User Module placed - a Timer16 - placed in blocks DBB00 and DBB01.  It is clocked from VC1 which is set to SysClk/1 so it should be running at 24 MHz.

Port0_2 pin has been set as 'strong' drive mode in the Designer.

The code reads:

void main(void)
{
    M8C_EnableGInt ; // Uncomment this line to enable Global Interrupts
    // Insert your main routine code here.
    
    //setup and start Timer16
    Timer16_1_WritePeriod(1500);
    Timer16_1_EnableInt();
    Timer16_1_Start();
    
    //idle
    while(1)
        ;
}

#pragma interrupt_timer Timer16Interrupt
void Timer16Interrupt(void)
{
    unsigned static int State;
    
    if (State == 0)
    {
        PRT0DR |= 0x04;            //set Port0_2 pin high
        State = 1;
    }
    else
    {
        PRT0DR &= ~0x04;        //clear Port0_2 pin low
        State = 0;
    }
}

Also, I have modified the boot.tpl file so that the relevant portion reads:

    org   20h                      ;PSoC Block DBB00 Interrupt Vector
    ljmp _Timer16Interrupt
    reti

    org   24h                      ;PSoC Block DBB01 Interrupt Vector
    ljmp _Timer16Interrupt
    reti

The reason I have put this in twice is because I couldn't find any definitive statement telling me from which block the interrupt should be associated with for a Timer16 User Module terminal count.  The Design view image suggests that it would be the second block, but as this didn't work, I gave it both blocks.

Still there is no activity on the pin.  I only have a MiniProg so can't debug.

Any ideas of what to try next?  I couldn't find an example project that uses Timer terminal count as interrupt.  Mine is attached in non-working condition.

user_1377889's picture
User
9947 posts

You need a Build -> Generate/Build Current Project. The information from the .tpl file weren't transferred into the boot.asm file.

What do you think about changing to PSoC4? Prototyping Kits start at $10.

 

Bob

tonypayn902_1586141's picture
User
6 posts

Thanks again, Bob, I have got it working now.

The Generate/Build gave me a warning: !W C:\Users\Tony902\DOCUME~1\PSOCDE~1.4PR\TIMER1~1\TIMER1~1\TIMER1~1\main.c(24):[warning] unknown #pragma interrupt_timer

My #pragma should of course have been #pragma interrupt_handler, not #pragma interrupt_timer.  I must have typed that absent-mindedly, thinking about the function I wanted to achieve.

And I have confirmed that the interrupt is associated with the second block in the Timer16 User Module.

The PSoC4 does look interesting, I may give this a try in the near future.  I like the fact that it incorporates a debugger into the low-cost dev kit - very handy.  I am using a lot of digital blocks in the PSoC1 in this project - is there anything that the PSoC4 can't do compared with the PSoC1?

Regards

Tony

 

user_1377889's picture
User
9947 posts

PSoC4 hasn't got that kind of analog blocks the PSoC1 has. So no analog filters except using the OpAmps.

You can download and install Creator 4.0 and the kit installation files to see what you will get.

 

Bob

Log in to post new comments.