We study the dynamic process of splitting a condensate by raising a potential barrier in the center of a harmonic trap. We use a two-mode model to describe the phase coherence between the two halves of the condensate. Furthermore, we explicitly consider the spatial dependence of the mode funtions, which varies depending on the potential barrier. This allows us to get the tunneling coupling between the two wells and the on-site energy as a function of the barrier height. Moreover, we can get some insight into the collective modes that are excited by raising the barrier. We describe the internal and external degrees of freedom by variational ansatz. We distinguish the possible regimes as a function of the characteristic parameters of the problem and identify the adiabaticity conditions.