Forum Discussion
Altera_Forum
Honored Contributor
10 years agoThe flaw is with the condition if(ticks % 10==0 && flag==1)
Infact your code basically loops on this instruction. So, you have a rough 50% probabilty that the irq triggers between the two ANDed conditions. When you find both conditions true you toggle the blue trace. At this point tick%10==0 stays true until the next irq; but if irq triggers just after you evaluated tick and before you evaluate flag, at the end you would again have the whole if conditional true and would toggle the output one more time. To solve the problem, put the tick%10 condition inside the isr and set flag according to it.