problem with working of PID Library

I am using Arduino-PID-Library-master for discharging of battery to maintain battery cell voltage and vary PWM( Discharging Current). also using Arduino-PID-AutoTune-Library-master to auto tune pid constants. i implemented pid in code but not getting proper result. its not maintaining voltage to specified limit. i am applying battery cell voltage at input and getting pwm at output. i read parameter controller direction in pid library. i think for my case i need REVERSE. but in both case i am not getting to work proper maintaining of voltage. any one can help me for this?

If you are discharging a battery , then its voltage will continue to fall. You can't discharge it and have a control loop trying to keep that voltage constant.

If you want to discharge it to a certain voltage, then you monitor the voltage and turn of the discharge circuit when you reach that voltage. if you want to measure the no load voltage -discharge it for a time, disconnect the load, wait, read the voltage, then decide to stop discharging or discharge some more and repeat. No PID needed.

BTW post your code !

Hammy. Actually i am using Big battery with 20 modules inside and each module have 6 small cell inside. so what exactly it looks like i am discharging whole battery all 20 modules but i just want maintain voltage of single module for specific time i can vary my current but, let me explain it in detail, i start my discharging with some constant current say 2.7 A at one stage i want to maintain that any single module at specific voltage say 5V. so if voltage is constant so current should be variable. so i am decreasing my current to specific limit for some time interval to maintain that module voltage at 5V. but for that rate of varying current i am using pid for. pid generating PWm which is applied to mosfet to vary current from battery. so could it be possible with pid to maintain module voltage(not whole battery voltage ).? is pid useful for this? or just PI or any other suggestions?

But a battery is not a resistor -if you vary the current you will get a slight change due to the drop across the batterys internal resistance, but dominately the voltage will drop due to the cell discharging and there is nothing you can do about that.

In any case you have the problem that you would need to tie in voltage measurment when the PWM signal is not discharging you

What are you actually trying to do - I suspect this is the root of the problem - are you trying to create a constant voltage supply, in which case there are other workable/better methods.

If you are just tapiong across a few cells in the middle of a pack, then that is bad practice nad can lead to over/under charging