Square wave function programming on Arduino Due

have a look at the tc_lib library for the Due
it contains useful functions for measurning and generating signals