AFAIK the counter inputs of the CPU314-2DP are 24Vdc. This means that anything between about 16V and 30V will be regarded as a 1-level and anything between about 0V and 8V will be regarded as a 0-level. So yes, you may connect a 5V encoder to the counter inputs of a CPU314-2DP, but it won't do you any good.
Regards,