I'm working on a project where i need to charge multiple li-ion cells. I'm thinking of buck converter circuit powered by ac-dc 24V 1A wall adapter and controlled by Atmega328P MC PWM. I've covered theory behind li-ion battery charging, buck converters, PWM. I believe constant voltage mode implementation is quite straight forward. A simple voltage divider to get feedback voltage to ADC and Rsense resistor with current sense amp to ADC adjusting PWM duty cycle to keep stable voltage while checking current drop to 10% to cut off power(correct me if i'm wrong about this). But i'm unsure how to approach constant current mode.