We aim at investigating with high angular resolution the NH3/N2H+ ratio toward the high-mass star-forming region AFGL 5142 in order to study whether this ratio behaves similarly to the low-mass case, for which the ratio decreases from starless cores to cores associated with YSOs. CARMA was used to observe the 3.2 mm continuum and N2H+(1-0) emission. We used NH3(1,1) and (2,2), HCO+(1-0) and H13CO+(1-0) data from the literature and we performed a time-dependent chemical modeling of the region. The 3.2 mm continuum emission reveals a dust condensation of ~23 Msun associated with the massive YSOs, deeply embedded in the strongest NH3 core (hereafter central core). The N2H+ emission reveals two main cores, the western and eastern core, located to the west and to the east of the mm condensation, and surrounded by a more extended and complex structure of ~0.5 pc. Toward the central core the N2H+ emission drops significantly, indicating a clear chemical differentiation in the region. We found low values of the NH3/N2H+ ratio ~50-100 toward the western/eastern cores, and high values up to 1000 in the central core. The chemical model indicates that density, and in particular temperature, are key parameters in determining the NH3/N2H+ ratio. The high density and temperature reached in the central core allow molecules like CO to evaporate from grain mantles. The CO desorption causes a significant destruction of N2H+, favoring the formation of HCO+. This result is supported by our observations, which show that N2H+ and HCO+ are anticorrelated in the central core. The observed values of the NH3/N2H+ ratio in the central core can be reproduced by our model for times t~4.5-5.3x10^5 yr (central) and t~10^4-3x10^6 yr (western/eastern). The NH3/N2H+ ratio in AFGL 5142 does not follow the same trend as in regions of low-mass star formation mainly due to the high temperature reached in hot cores.