PWM interrupt flag not clearing, I have read the datasheet and code looks fine

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

cross mob
SaWa_284216
Level 4
Level 4

So I am trying to recreate the code in this application note (I can't find the link to the actual project)

   
   

I have read through all the PWM datasheet and I think I have everything setup right.. I am reading the status register as it says but when I step through my code it just never leaves the interrupt.. it goes off to read the status register and then just loops infinitely in the ISR routine..

   
   

I have attached my code if someone could help me make sense of where I am going wrong..

0 Likes
8 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your active PWM will generate interrupts all the time because it is hardware. When single-stepping through your code you will always stop in the interrupt handler. At first sight I would think that your code is right.

   

 

   

I (personally) do not use the way you defined the interrupt handler. When switching to another PSoC switch or when deleting the generated files (which is allowed to do) you are going to loose the modifications you made in the file ISR_Compare.c

   

When declaring the Handler with CY_ISR_PROTO(YourHandler) and defining it with CY_ISR(YourHandler) in your main.c you can start it with ISR_Compare_StartEx(YourHandler) and have full control of the code. Have a look into the "System Reference Guide" to be found under Creator -> Help -> System Reference.

   

 

   

Bob

0 Likes
SaWa_284216
Level 4
Level 4

I am going to look into your way of doing it, but please could you elaborate on what you mean about the pwm always generating interrupts as it is hardware? also the single stepping thing.. I thought I would see the code exit the isr and back to main, then back to isr...etc

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

The moment you started the PWM it runs ang generates interrupt. When your program reaches a breakpoint the PWM does NOT stop, only the program halts. When single-stepping you will not leave the current instruction. proceed as follows:

   

Program has halted at BP1

   

Place BP2 to the next instruction after the  BP1.

   

Remove the BP1

   

Run program, it stops at BP2

   

Remove BP2

   

Set BP1 at the old position again

   

Run Program.

   

 

   

Bob

0 Likes
SaWa_284216
Level 4
Level 4

Ahh I get what you mean, but now I have done this and set a second breakpoint outside of the flag checking loop and surely the program should reach that.. but it doesn't, it never gets past the yellow line..

   

0 Likes
SaWa_284216
Level 4
Level 4

another twist..

   

 

   

I have downloaded and programmed the following tutorials example project

   

 

   

http://blog.hendriklipka.de/archives/2013/10/psoc_frequency_counter_2.html

   

 

   

and the exact same happens, the code gets stuck in the ISR and doesn't respond to any change in frequency,.. is it my board do you think? or a bug?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

First post's answer: Did you remember that I wrote to delete (or at least to disable) the BP at the current line (or did I forget that)?

   

 

   

Second post's answer: This behaveour has Nothing to do with your board / PSoC. It happens with EVERY PSoC. The cause is how breakpoints are handled, how a run-command is issued and when the interrupt-flag in the PSW is cleared.

   

 

   

Bob

0 Likes
SaWa_284216
Level 4
Level 4

Ahh right, It is working now, but only if I go back and delete and replace breakpoints every time.. is that the only way to do debugging in PSoC creator because that is annoying as hell!

   

 

   

Thanks for the help by the way, very useful.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

This is the only way to debug an interrupt handler. Additionally you may disable interrupts temporarily: there is a button on the menu-header to enable or disable them.

   

 

   

Bob

0 Likes