Hamiltonian formulation of Villain models