ADC controlling needs advice.

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
oookey
Posts: 42
Joined: Thu Mar 08, 2012 3:00 pm
Has thanked: 17 times
Contact:

ADC controlling needs advice.

Post 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.
Attachments
ADC-ONOFF.fcf
(4 KiB) Downloaded 249 times
Signal @ GPIO 0
Signal @ GPIO 0
WaveFormGPIO0.jpg (96.89 KiB) Viewed 3805 times
ADC-ControlCurrent.jpg
ADC-ControlCurrent.jpg (12.5 KiB) Viewed 3805 times

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: ADC controlling needs advice.

Post 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
Martin

oookey
Posts: 42
Joined: Thu Mar 08, 2012 3:00 pm
Has thanked: 17 times
Contact:

Re: ADC controlling needs advice.

Post 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 :?:

medelec35
Matrix Staff
Posts: 9521
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times

Re: ADC controlling needs advice.

Post 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.
Martin

Post Reply