PWM to const current

MrAl

Joined Jun 17, 2014
13,707
View attachment 318818
In these case I want to have 10- 1k Load and want to maintain the same mA output, Any suggestions?

Hi,

That circuit makes it look like you are on the right track. There are a few points to think about.

First, do you want (say) 10ma peak current or 10ma average current?
Your circuit so far is set up to be able to set the peak current, which is good I think, as long as the frequency is not too high.

Then, as others have been saying, if you want 10ma through 500 Ohms then the voltage across that 500 Ohms would have to be 5.000 volts or very close to that.
Unfortunately, the transistor and sense resistor will drop some voltage, so you may be stuck at 4.5 volts, which limits your resistor value to 450 Ohms if you really need 10ma peak. If you absolutely have to use 500 Ohms, then you would have to supply a little more voltage, like 5.5 volts, for that 10ma current that is. If you can go a little lower on the current, like 9ma peak, then you can probably do that 500 Ohm resistor value. You will have to test this of course.

The resolution will depend on the resolution of the D to A converter in your uC chip. If you have a 10 bit D to A you will get roughly 0.010/1024=9.77ua approximately, at least in theory. Unfortunately, the sense resistor probably would have to increase quite a bit in order for your A to D converter to be able to sense that small current. The voltage across a 0.25 Ohm resistor is just about 2.44uv, which is hard to measure with an A to D converter unless it is set up to amplify that low level.
In the case of 10ma, the voltage will only be 2.5mv, which is also a small level to be measured with a standard A to D converter.
When these issues come up it is sort of standard practice to use a measuring system that allows scaling of the measurement through amplification. You amplify the signal by a factor A, then in software you divide by A if needed. That gives you the actual measurement. You also need to be able to change that amplification factor A for different gains as the measurement goes lower and lower. For example, you might start at A=1, then jump to A=2, then A=5, then A=10, then A=20, then A=50, then A=100, like that, until you get a reading that can be handled accurately with the A to D converter you are using. This requires a programmable gain amplifier.

I do not know how far you want to take this though and how much error you can tolerate. You might have to mention that too because the allowable error will play a big part in the selection of parts.
 

dendad

Joined Feb 20, 2016
4,637
What is the ACTUAL load you are driving?
Is it a lamp?
Is it a resistor?
Is it a wet gopher?
What is the real value?
For 1 to 500 Load
1ohm to 500ohms?
1Kohms to 500Kohms?
Without letting us know your full details, we are just chasing our tails trying to help you.
For example, we need to know.....
Do you want to only supply 10mA for all the loads? If so, no controller is needed.
Will you want to alter the current? If so, then a controller may be the way to go, or just a pot may do.
The actual 1:500 range resistance must be defined as that will define the voltage needed to supply the current.
Why is it so hard to give us the details?
 

Thread Starter

nazmul0087

Joined Mar 29, 2024
15
Hy, Load should be between 1ohm to 400ohms. I want the current to be 10 milliampere square current waveform, and the amplitude will not change with different loads for 1 to 400ohms.
 

MrAl

Joined Jun 17, 2014
13,707
Hy, Load should be between 1ohm to 400ohms. I want the current to be 10 milliampere square current waveform, and the amplitude will not change with different loads for 1 to 400ohms.
Yes, but you have to realize that your circuit is for doing something like 10ma peak. This is peak not average, and you haven't answered that question yet so I am going to assume from here on out that you are talking about peak current amplitude and NOT average current.
It looks like it will do 10ma peak, but how accurate it is depends on your microcontroller ADC and DAC specs.
How fast it works (like highest frequency of operation) depends partly on the choice of op amp as well as your uC chip specs.

Oh I see you are using a Nano. That means a 10bit ADC and only PWM simulated DAC. The PWM DAC will limit you quite a bit to only those values that the uC chip can perform.
 

Thread Starter

nazmul0087

Joined Mar 29, 2024
15
Thanks, Do you suggest me any other uC for that? Uno can help me in these case also? and step by step what I should do to achieve this?
 

dendad

Joined Feb 20, 2016
4,637
It would be easier if you have 12V available. And if your accuracy was not to critical, something simple like this would maybe work...
ConstantCurrent.jpg

The circuit you posted will not drive the load at a square wave, but a DC current that is set by the PWM voltage and duty cycle.
It could be modified to do the square wave drive. But you may need a better op-amp, one that will drive the full 0 to 5V out, a "rail to rail" op-amp, as I think the one you have chosen will have limited output voltage swing.
Replace the input series resistor and capacitor from the controller with a pot so you can set the input voltage to the op-amp input. That will set the current.
 

Thread Starter

nazmul0087

Joined Mar 29, 2024
15
Replace the input series resistor and capacitor from the controller with a pot so you can set the input voltage to the op-amp input. That will set the current.
1711832829777.png

Thanks, But Is there any way I can control/vary automatically the op-amp input from controller ? Because if I change the Rload the ammeter reading as you can see 15.4 varies significantly
 

dendad

Joined Feb 20, 2016
4,637
Oh,I missed that :0
The 12V supplies are reversed. I should have spotted it as the meter polarity is reversed too.
I do not use simulators so am not real familiar with them.
 

Thread Starter

nazmul0087

Joined Mar 29, 2024
15
yes, Thanks It seems like good now. for 100 to 800 ohm its same. some spikes are there. Can you kindly give some calculation here or give some insight how its giving the same current.
1711835269718.png
 

dendad

Joined Feb 20, 2016
4,637
It is controlling the voltage across RS, so, as long as the supply voltage is sufficient for the total series string (RLOAD + RS + Q1 min voltage drop), the current will stay constant, and the circuit does not care what RLOAD is.
 

Alec_t

Joined Sep 17, 2013
15,119
square current waveform
By 'square' do you mean 50% duty cycle (i.e. on for exactly half a cycle and off for the other half cycle), or would some other duty cycle suffice? PWM is all about controlling the duty cycle to get a required average value.
Do you just want your load to have a controllable steady average current, or must the load have a pulsed current?
 

MrAl

Joined Jun 17, 2014
13,707
Thanks, Do you suggest me any other uC for that? Uno can help me in these case also? and step by step what I should do to achieve this?
Hi,

For me to do that I would have to know the explicit details of what you actually need, spelled out in great detail. Without that information, it's a never ending tale of trial and error. "Ok, that didn't work right, let's try something else". "Ok, that didn't work either, let's try something else".

It could even be that your setup is just fine the way it is, but you have to be willing to show very detailed information here. All of the requirements of the project including the precision and accuracy. This will also help to determine if the project is even feasible with regular, easy to obtain parts like the LM358.
 
Top