Voltage generator switching between alternating, first and second voltage values, in particular for programming multilevel cells