What is the amount of instability you observe in the square wave?
I have a similar situation for a 1kHz wave and have very good stability, far below 1us.
I use IOWR_ALTERA_AVALON_PIO_DATA, too, so I think this is not your actual problem. I'd rather think it's due to alt_timestamp function or to your nios/sopc configuration (as DSL suggested). Infact, I don't use alt_timestamp but I have tried the following solutions, both achieving similar stability:
- pio controlled in timer interrupt service
- polling directly the timer count register until switching condition is achieved, in the same way you did through alt_timestamp.
Cris