Hi i would like to know how did you match the output current to the setting point
am too building a dummy load using an arduino had it working but i have some oscillation on the mosfet i think
thanks \
shailesh
Hello, I am not 100% sure I understand the question, but this is how I do sampling and adjusting the duty cycle.
I attenuate the input voltage so it fit's within the range of the ADC e.g. 30V => 3V, mine is max 25V input. I've set the attenuation of the PWM to give me a max of ~6000mA and then with a 0.1R shunt I know the voltage over that resistor will be 100uV per mA, then I amplify the voltage over the shunt to match the scale of the 2nd ADC for current measurements.
The sampling, averaging and duty cycle adjustments are done on a timer interrupt that runs at 1kHz. The samples are averaged using 20 running averages.
The duty cycle is adjusted by a line of code something like this:
targetPwm += ((targetCurrent - lastCurrent) * 0.005);
This gives a nice self adjusting duty cycle without oscillation or overshoot.
Note: targetPwm is not the duty cycle, it is the on time.
If you have problems with oscillation, check that you have a configuration of the driving opamp and MOSFET similar to the one I posted in my partial schematic in one of the first posts. (Couple of resistors and a small capacitor) Power MOSFETs have significant capacitance on the gate.