How to detect voltage between 100v - 130v DC?

I'm curious why you don't want to measure 36v, which is your target, rather than the input?

Can't you just measure the output, and if it is low, increase the duty cycle, and if it is high, reduce it?

You say that:
Rtotal = Vin / Iload

Shouldn’t it be:
Rtotal = Vin / Itotal

Itotal = IR1
IR1 = Iload + IR2

Yes, I believe you are correct. I rushed through my calculations and forgot to account for:

R2 || RLoad | where RLoad = RADC Input A0
IF at 4V , the current flowing through R1 is the current of R2 and RADC in parallel, and the current of ADC is 140 uA, then,

Vout = Vin * [(R2 || RADC)/ (R1+(R2 || R(ADC)]
Let IR2 = 0.000130 A (130uA)
IR2 = 130v/1 Mohm = 0.000130 A (130 uA), (there’s nothing magic about that number . You have to choose something arbitrarily (because you know the Voltage across R2 (4V) but you don’t know the resistance OR the current) and I chose 130 uA because it was similar to the ADC current.) You need to know the current through R2 because you need to know the total current. You can look up the ADC current (140 uA) and if you choose 130uA to be the current through R2 ,this allows you to calculate the resistance of R1 because you know the voltage across R1 = 130V-4V = 126V. You now know the current (270uA) ,
so R1 = 126V/0.000270 A (270uA) = 466666.6 ohms

then 130 uA + 140 uA = 270 uA.
If ITotal = 0.000270 A, (270 uA)

then Rtotal = 130 V /0.000270 A (270 uA )= 481481.48 = 481482 ohms.
if 4V/130V =0.030769
then,
R2 || RADC = 0.0307692 * (481482 ohms) = 14814.8 ohms
R2 = (481482 ohms - 14814.8 ohms) = 466667.1 ohms (which we already knew from above)

R1 = 466667.1 ohms
R2 = 30769.2 ohms
4V/14814.8 ohms = 0.000270 A (270 uA)

PROOF
RADC = 4V/0.000140 A (140uA) = 28571.4 ohms
R2 = 30769.2 ohms
4v/30769.2 ohms =0.000130 A (130 uA )
30769.2 ohms || 28571.4 ohms = (30769.2 * 28571.4)/(30769.2 + 28571.4)
= 879120000/59340.6 = 14814.8 ohms
4V/14814.8 ohms = 0.000270 A (270 uA)

Everything I said about using a pot and calibrating the circuit still applies. My feeling is that a pot used to comprise a portion of R1 would behave like a COURSE adjust and a pot used to comprise a portion of R2 would behave like FINE adjust. I could have that backwards but tell me what you think. You can try , one or the other or both. Since none of the values are standard you are forced to do both in order obtain the values calculated above. The pots should not comprise more than 25% of the total value of the resistance R1 or R2. Note: I am trying not to get involved in the discussion about WHERE you should be measuring , but I think I have provided enough information to apply the same method to calculate the values if you decide to measure some other voltage (like 36V). I am doing this because I posted to address your post title. If you post title said 36V then I would have used that value.

[quote author=Nick Gammon link=msg=2057620 date=1422075695] I'm curious why you don't want to measure 36v, which is your target, rather than the input?

Can't you just measure the output, and if it is low, increase the duty cycle, and if it is high, reduce it? [/quote]This would make more sense than the setup the OP currently has. Alternatively a simple NPN transistor, a zenner diode and resistor would make the arduino totally redundant and be far more stable.

KenF: This would make more sense than the setup the OP currently has. Alternatively a simple NPN transistor, a zenner diode and resistor would make the arduino totally redundant and be far more stable.

using a zener diode like that would be a LINEAR power supply, and would cause a tremendous amount of wasted power. The variation in the supplied voltage and the required load voltage gets eaten up by the resistor... and dissipated as waste heat! Not something you really want in an alternative energy setup such as used with LED lights and wind powered generators. Did ya think to wonder why I was going through all the trouble with making a switching regulator over a linear regulator? Thanks for the suggestion though.. however useless it is...

And your suggestion that measuring the output voltage and making adjustments to the duty cycle rather than measuring the source voltage and applying the correct duty cycle baffles me... This seems like absolutely the most backward approach to the problem.

I can see the use for measuring the output as a feedback mechanism to fine tune the duty cycle.. but using it as the main means for acquiring the correct duty cycle to use?? backwards!! This poses all types of problems.. the load may be exposed to excessively large voltage pulses while the system is attempting to adjust itself to find the correct duty cycle... Whereas if the source voltage is simply measured, the correct duty cycle can be calculated and applied without issue. Output voltage can be measured, and if it's off by a bit, duty cycle can be slightly adjusted accordingly.

Does anyone else see anything wrong with what kenF and nick gammon are suggesting?

localbroadcast: using a zener diode like that would be a LINEAR power supply, and would cause a tremendous amount of wasted power. The variation in the supplied voltage and the required load voltage gets eaten up by the resistor... and dissipated as waste heat! Not something you really want in an alternative energy setup such as used with LED lights and wind powered generators. Did ya think to wonder why I was going through all the trouble with making a switching regulator over a linear regulator? Thanks for the suggestion though.. however useless it is...

And your suggestion that measuring the output voltage and making adjustments to the duty cycle rather than measuring the source voltage and applying the correct duty cycle baffles me... This seems like absolutely the most backward approach to the problem.

I can see the use for measuring the output as a feedback mechanism to fine tune the duty cycle.. but using it as the main means for acquiring the correct duty cycle to use?? backwards!! This poses all types of problems.. the load may be exposed to excessively large voltage pulses while the system is attempting to adjust itself to find the correct duty cycle... Whereas if the source voltage is simply measured, the correct duty cycle can be calculated and applied without issue. Output voltage can be measured, and if it's off by a bit, duty cycle can be slightly adjusted accordingly.

Does anyone else see anything wrong with what kenF and nick gammon are suggesting?

So many mistakes in this I don't even know where to start.

Sorry I'm out. bye.

@OP, You saw the correct calculations , right ?

if you really want to make a regulator out of an arduino you for sure need to monitor the OUTPUT (currentwise or voltagewise) and you for sure need a PID algorithm

adjusting the PWM looking at the input is stupid, you will not obtain the correct current end\or voltage never!!! you will not even get close to it

localbroadcast: I will not be using the arduinos PWM output to create the on / off switching action of my switching regulator. The arduino will be used to control the switching, but I will be using my own code to create the exact timing of the pulses.

Your own code running on what processor? The Arduino can vary PWM frequency and duty cycle of the output, you know.

And your suggestion that measuring the output voltage and making adjustments to the duty cycle rather than measuring the source voltage and applying the correct duty cycle baffles me... This seems like absolutely the most backward approach to the problem.

I'm not sure why. By measuring the input, you are having to predict what changing the duty cycle will cause. By measuring the output you know whether or not you have reached your target.

Let me give you an analogy: Say I want to boil some water in my kettle. I could measure the ambient temperature, add in the efficiency of the kettle heater, compensate for the mains power supply voltage, and try to predict how long I need to heat the water. Or I could just measure the water in the kettle (the output) and stop when it is boiling.

right!!!

localbroadcast: And your suggestion that measuring the output voltage and making adjustments to the duty cycle rather than measuring the source voltage and applying the correct duty cycle baffles me...

See http://www.ecnmag.com/articles/2009/12/designing-buck-converter

In particular:

The timing information for the lower and upper MOSFETs is provided by a pulse-width modulation (PWM) controller. The input to the controller is a voltage fed back from the output. This loop allows the buck converter to regulate its output in response to load changes. The output of the PWM block is a digital signal toggling up and down at the switching frequency. The signal drives the MOSFET pair. The duty cycle of this signal determines the percentage of the time that the input is directly connected to the output. Thus, the output voltage is the product of input voltage and this duty cycle.

(My emphasis).

localbroadcast wrote:

And your suggestion that measuring the output voltage and making adjustments to the duty cycle rather than measuring the source voltage and applying the correct duty cycle baffles me... This seems like absolutely the most backward approach to the problem

Then it is time to get yourself un-baffled :)

The suggestion was hinted to you early on in this thread, but you seemed to have ignored it. Also, the idea of using a PID was mentioned, and I am wondering if you looked into using this.

screwpilot states it again, quite plainly again for you that this is a good approach.

To tell you that this works and maybe give you that extra bit of confidence , I can tell you I use this very idea in my own re-newable energy system, where I too have a generator feeding a load.

I monitor the voltage of my load, in my case my battery system, and then have the Arduino do a PID loop control function at a regular time rate of 100mSec to control a SSR to dump energy to maintain a very nice voltage on the battery system.

In terms of the PMW duty cycle, I don't care what it is, the PID loop control function handles this nicely and will try to maintain the output point of what you want to acheive as close as posible to the set-point value you give it.

The only difference in my case is that my generator is a 3 phase AC induction device, but that make no difference to the concept of what has been suggested to you. But you can see it working if you so wish, below.

It's all pretty standard industrial process control stuff really.


Paul

rockwallaby: It's all pretty standard industrial process control stuff really.

Your real life example, and Nick's kettle power timer analogy should hopefully convince OP of the desirability of the feedback approach.

I wonder if he drives his car by estimating the correct position for the throttle for the desired speed, or if he watches the speedo and adjusts right foot accordingly?

With an inexpensive op-amp IC and some properly sized resistors, you could convert the 100 to 130V signal to get a range of 0 to 5V. http://www.electronics-tutorials.ws/opamp/opamp_5.html

Hi, localbroadcast.

Can you tell me how much experience you have with electronics, programming, hardware and control systems?

The process of sampling the output of a SMPS and adjusting its PWM to get the correct output is so common that even the computer/laptop you are using has a powersupply using this control system.

It is called negative feedback. Please Google it.

Negative feedback will compensate for most of the in-tolerances in the control and filtering circuits. Your method assumes that everything after the 100 to 130Vdc input will have the same characteristics for ever and under all current and voltage conditions.

Your switching FET will not have ZERO ON resistance, the inductors will have some RESISTANCE, capacitors have in the case of electrolytics some resistance and change values over time and temperature.

Tom..... :)

Polymorph.. you seem to be confused. The use of a mosfet to pulse the source voltage on and off (100v for example) to create a lower voltage (36 volts in this case) is a very well accepted way for voltage to be regulated.

My point is that to get 36V from 100V in a switch mode power supply, you can't just set the PWM duty cycle at 36%. You -must- use feedback, and design it carefully with regards to the inductance, load current range, and voltages in and out.

I'm not confused, but thanks.

wow... so nobody read where I said that I agreed it would be useful to measure the output as a feedback loop to fine tune the duty cycle to keep the output voltage on target.. I never said that measuring the output and adjusting the duty cycle was a bad idea.. Just think that measuring the input voltage and running calculations to predict the most likely correct duty cycle as a starting point for the output duty cycle makes more sense than starting at 0 and slowly increasing until it reaches the desired output.

The duty cycle will be adjusted to maintain the 36 volts as desired. The PWM output of the arduino will not be used. I will be writing the code that will allow for a customized pwm output from the arduino.. This way I can have full control over the frequency and the duty cycle, depending on if I run into problems with interference etc. or switching speed issues with the mosfets. Also, I won't be constrained to just the PWM output pins on the arduino board. I will be able to use all of the output pins.

Here's a good article on that : arduino pwm

I have a lot of experience in the electrical / electronics field. I used to work for rockwell automation building large scale 5000hp + variable frequency drives. For a period of time I worked at general electric water and process technologies building reverse osmosis systems for intels chip manufacturing water supplies. I've built a number of water turbines, wind turbines, solar panel systems, battery charge controllers, etc.

Sometimes my approach to things may be different than what is normally expected.. but that's why I come on places like this to talk and compare notes with like minded individuals.

Did you see the new calculations ? (in Reply#21)

This way I can have full control over the frequency and the duty cycle, ...

Very good, but as I said using the Arduino timers you also have "full control" over frequency and duty cycle. Subject of course to limitations imposed by hardware, in the sense that for very high frequencies the duty cycle is necessarily coarse, but that must apply to other chips as well.

As an example, if you count to 1000 with the timer (and therefore the frequency is the clock speed divided by 1000, subject to prescaling) then your granularity of duty cycle is 1000 (the duty cycle can be on for 10 cycles and off for 990, for example).

I will be writing the code that will allow for a customized pwm output from the arduino..

As I asked you earlier, where is this code running? Is there another processor? Are you controlling another PWM chip? Or are you manually doing PWM instead of using the hardware timers?

raschemmel: Did you see the new calculations ? (in Reply#21)

I saw the new calculations, yes, thank you. I have not had time to run through them to double check the math yet.. perhaps someone else can do that? If not, I will get around to it soon enough.

Who wants to calculate the mosfet size to use? so many people want to tell me how to build my circuit, might as well just do the calculations for me! Saves me the work. The LED modules are 36 volts and about 3 amps each. I want to drive 4 of these modules from this power source... so a total of about 12 amps, 432 watts.

Here's another thought.. I could run all 4 of these modules in parallel, and control them all with the same mosfet.. OR, I could use 2 mosfets.. The first mosfet for LEDs 1 and 2 in parallel, and the second mosfet for LEDs 3 and 4 in parallel. When the supply voltage is at 100v for example, I could have mosfet 1 switched on for 36% of the time, and mosfet 2 switched on for a different 36% of the time, and both off for 28% of the time. Only 1 of the mosfets would be switched on at any given instance. This would mean each of the mosfets would be handling less amps.. and the instantaneous current draw on the source would be half of what it would be if all 4 LED modules were run on a single mosfet.

What way do you think would be best to use?? 1 mosfet powering all 4 LED modules in parallel? or 2 mosfets powering 2 LED modules each.. having only 1 mosfet on at any given time.. splitting the current draw of the 4 modules between the 2 mosfets.

Or maybe somebody has some other type of ingenious solution I haven't considered. let me have it!

put them in series in couples? this way you can save on capacitors size and maybe on efficiency

also this "switching turn" thing is interesting but consider that you are going to put more harmonic frequencies on the system this way, but it will save on transistor size and capacitors size overall