In this contribution we revisit the lattice discretization of the topological charge for abelian lattice field theories. The construction departs from an initially non-compact discretization of the gauge fields and after absorbing $2pi$ shifts of the gauge fields leads to a generalized Villain action that also includes the topological term. The topological charge in two, as well as in four dimensions can be expressed in terms of only the integer-valued Villain variables. We test various properties of the topological charge and in particular analyze the index theorem in two dimensions and discuss the Witten effect in 4-d. As an application of our formulation we present results from a simulation of the 2-d U(1) gauge Higgs model at vacuum angle $theta = pi$, where we use a suitable worldline/worldsheet representation to overcome the complex action problem at non-zero $theta$.