Copied code to ClockTiM_old