Lets say assembler may help... but without seeing what you have now, it's hard to suggest something or know why it doesn't work as expected. Is this a software or hardware related... ??? who know

If you're using interrupts, that might be one problem source... but...mmm hard to guess.