Using arduino in battery charger

Unless this is a research project, it should not be necessary to use an Arduino, much less PWM.

There are many charge controller chips and modules available for every battery chemistry. If you want to make one up from a chip then TI makes lots of great chips. However they require a high level of experience with switchmode PCB layout which is one of those "art not science" fields in electronic engineering.

I would look for a "programmable" module. One that lets you change the current-sensing resistor to achieve the charge current you desire. You should not need any Arduino code to program your battery charger.