Page 1 of 1
ADC controlling needs advice.
Posted: Fri Mar 07, 2014 8:47 am
by oookey
Hi all,
I’m trying to use ADC reading to control current flow.
The circuit as followed:
The FC3 program & the output waveform is attached, from what I observed through the scope, I got the same waveform regardless different values of “VAL0” settings.
If I'm not wrong with VAL0>5 setting, i should expect more OFF than ON compare to VAL0>128, hence reduce of current to LED.
The value of R=1k ohm.
Please any suggestion, how should I set the ADC?
Thanks.
Re: ADC controlling needs advice.
Posted: Fri Mar 07, 2014 8:16 pm
by medelec35
Hi oookey,
It's a bit more complex than is first thought.
You want to limit the current, so that means if the current exceeds a threshold, then PWM duty is reduced.
But what if the current is not exceeded, but is less than threshold?
PWM increase?
Problem is even during the 30 second on duration, with a PWM set at 50% the current will not be flowing for 50% of the time.
Also what is your current threshold?
You may want an adjustable threshold by using up another ADC channel?
I believe the solution would be to 1st sample the current, and if under a minimum value (not the current threshold value) then at this point the PWM is off so don't use sample for any PWM adjust.
If the sample is greater than minimum current then the sample should be compared with threshold value. So if greater than current threshold value, Reduce duty of PWM, otherwise leave as is.
You will need to determine the current threshold value and resistance value.
If you can let me know the values I can assist you with a modified Flowchart.
Martin
Re: ADC controlling needs advice.
Posted: Sat Mar 08, 2014 2:41 am
by oookey
HI Martin,
Thanks.
medelec35 wrote:
You want to limit the current, so that means if the current exceeds a threshold, then PWM duty is reduced.
But what if the current is not exceeded, but is less than threshold?
PWM increase?
Martin
This time round I'm solely setting On & Off at the output port, no PWM involve.
If the output port is OFF, VAL0 reads value less than 5%, then ON output port, as current flows increase over 5% mark, output port OFF again.
I think I'm correct using this method to control the amount of current flow. From the scope i can see On & OFF, but this on/off is not affected by the setting of the VAL0

Re: ADC controlling needs advice.
Posted: Sat Mar 08, 2014 4:02 am
by medelec35
oookey wrote:This time round I'm solely setting On & Off at the output port
You will need to bear in mind that if current limits and turns the pin off, then current is 0 so the pin is very rapidly turned on again.
It will be like very rapidly turn your house light on and of 1000's times a second.
So in effect you will have a pwm waveform anyway.
oookey wrote: From the scope i can see On & OFF, but this on/off is not affected by the setting of the VAL0
That sounds like the PWM effect I have described.
If it was me, I would use another ADC channel to adjust the current limit threshold.
As for the threshold value, Rather than stating over 5%. it would be better if you workout the normal current flow, add a percentage say + 10%, then use that figure as a current limit since under normal circumstances current limit is undesirable.