General technique to produce isochronous Hamiltonians