Using a microcontroller input as crude comparator (threshold variation effects)

Hi

I am working on a current mode controlled SMPS. I have a sawtooth voltage r= amp (measured current in a sense resistor) and I would like use a digital i= nput pin of a micrcontroller to turn off the PWM that controls the ramp. Th= e ramp moves from 0 to 100mV in 10us.=20

I do not have a free comparator on the micro, so I thought of using the dig= ital input threshold as the fast level detect, and an outer loop measuring = the current for slow current control. The ramp is offset shifted to just be= low the threshold since I have a low voltage swing

But, does the typical digital input have a threshold that moves due to exte= rnal factors fast, appart from supply voltage? (I only need the positive th= reshold)

Thanks

Klaus

Reply to
Klaus Kragelund
Loading thread data ...

On a sunny day (Mon, 3 Sep 2012 04:24:25 -0700 (PDT)) it happened Klaus Kragelund wrote in :

That is difficult to answer, and it likely differs from micro to micro. Some time ago I bought a bunch of unijunction transistors on ebay... make great level triggers (percentage of supply), but in any case I would spend the money on a small real comparator or opamp if it is critical, or just add an 8 pin PIC with comparator.. Maybe 555 timer's comparator?

Reply to
Jan Panteltje

Doubtful. Most uCs have hysteresis on the input pins, and many don't guarantee the magnitude of it. In most applications, input pin hysteresis is on the order of 200mV, which would screw up your plan pretty quickly (unless you want to amplify it, or use a CT).

You're effectively depending on the input pin's linear range, which may be just as slow as anything else available, in other words not as fast as you had hoped.

Is this a peak current mode control, most likely boost/flyback? If you can get access to the full current waveform (the triangle, not the sawtooth), average mode control is better -- it's not chaotic.

Tim

-- Deep Friar: a very philosophical monk. Website:

formatting link

I am working on a current mode controlled SMPS. I have a sawtooth voltage ramp (measured current in a sense resistor) and I would like use a digital input pin of a micrcontroller to turn off the PWM that controls the ramp. The ramp moves from 0 to 100mV in 10us.

I do not have a free comparator on the micro, so I thought of using the digital input threshold as the fast level detect, and an outer loop measuring the current for slow current control. The ramp is offset shifted to just below the threshold since I have a low voltage swing

But, does the typical digital input have a threshold that moves due to external factors fast, appart from supply voltage? (I only need the positive threshold)

Thanks

Klaus

Reply to
Tim Williams

I am only using the positive level, so the hysteresis does not come into play (its reset, since the input goes to zero at the end of the ramp)

Yes, peak current mode

Good point, just easier for the circuit implementation to shut off at each period by defined current level

Thanks

Klaus

Reply to
Klaus Kragelund

Could do that, was just playing around to see if I could save a package from the design

Regards

Klaus

Reply to
Klaus Kragelund

PS why mot use the Vbe of some Si transistor? they make excellent ramp peak detectors. You know exactly the temp drift, and that really is not much to worry about in most cases.

2 resisisters and 1 transisiter
Reply to
Jan Panteltje

Ok, but the hysteresis tolerance will change the absolute threshold level where the uC input internally switches high. Even if it didn't have much hysteresis the level where it switches can vary between production lots. Mostly they only guarantee that it is somewhere between

30% of VCC and 70% of VCC.

No chance to mux the comparator also to that pin and give it some priority in the code?

I am trying the opposite, controlling a switcher on the cheap with a digital uC output. We should start a "Penny Pincher Club" :-)

[...]
--
Regards, Joerg

http://www.analogconsultants.com/
Reply to
Joerg

most cases.

Yes, that's another option. I just wondered about the cheapish solution with the microcontroller input :-)

Thanks

Klaus

Reply to
Klaus Kragelund

Well, I am also controlling the switcher by the microcontroller, having the= goal to keep the processor from doing anything that needs to very responsi= ve (current loop). Adding a large capacitor on the output to lower the open= loop crossover could be a way to ease the computing power, but that adds b= ucks to the design, and then I am thrown out of the "Penny Pincher Club" ;-= )

Cheers

Klaus

Reply to
Klaus Kragelund

If the uC has a priori knowledge of the load behavior because it also controls the load (luckily mine does) then you could meter out the energy in chunks. Essentially it boils down to a forward steering action, just like your right foot does when you see a sign that says

80km/h, because after owning your car for some time you know how how much power it will need to go up that incline at this speed.

Ok, I also have an emergency throttle on my circuit in case the code hangs for some reason. But that's a simple hiccup loop.

--
Regards, Joerg

http://www.analogconsultants.com/
Reply to
Joerg

We are feeding a RS485 line, so I don't know the load.

I have a simple transistor across the sense resistor to pull the reset pin of the microcontroller. An upset should not happen often...

Reply to
Klaus Kragelund

The uC could ping it once in a while to find out, for example via voltage drop, and then tally up the total load according to the data it is sending out. But that does get old, can mean a lot of code overhead and someone has to write all that code. In my case we have no choice but I don't have to write the code :-)

Good that it's there though. Many systems don't have such last-resort emergency stops and then a hang-up is followed by a loud bang and some smoke.

--
Regards, Joerg

http://www.analogconsultants.com/
Reply to
Joerg

I have TIA-485, i can find the maximum line values easy. Will post back, it is at the office. The driver devices will take a little bit more. Check that datasheet in the meantime.

pin of the microcontroller. An upset should not happen often...

Reply to
josephkk

Yes, but then a service technicial takes the terminating resistor off while the line is busy and youy lose control of the voltage

Regards

Klaus

Reply to
Klaus Kragelund

Then it could run into the transzorbs which would normally always be there on a wired remote data link. Depends on the architecture, with an isolated buck there should not be a problem, with flyback it'll run into the diodes. The uC would then catch the situation during the next probe cycle. When a technician pops off a resistor he or she should not be too surprised when there is at least momentary data loss.

--
Regards, Joerg

http://www.analogconsultants.com/
Reply to
Joerg

back,

Eeek. I still owe you this.

pin of the microcontroller. An upset should not happen often...

Reply to
josephkk

also

back,

pin of the microcontroller. An upset should not happen often...

@Klaus

Here it is: The TIA-485 is based on the unit load concept. A generator is supposed to supply up to 32 unit loads. A unit load can be describes as the union of two triangles: One with vertices -7 V, 0 mA; +5 V, 0 mA; and -7 V, -0.8 mA: Next with vertices -3 V, 0 mA; +12 V, +1 mA; and + 12 V, 0 mA. The differential output for either a "1" or a "0" must be at least 1.5 V but no more that 5 V when loaded two 27 ohm 1% resistors in series. There are more requirements if you want to know.

TIA-485 references TIA-422 and TSB-89 for more information.

As promised,

?-)

Reply to
josephkk

o

k,

pin of the microcontroller. An upset should not happen often...

Hi Joseph

Thanks ;-)

Regarding the load, some RS485 drivers has only 1/8 loading, so possibly up= to 256 devices on one string. But there is no fixed load, so cannot really= be sure what the load is, except for the maximum load. For Modbus, RS485, = the load is maximum 50ohm (2 120R load terminations and 32 input loads of 8= kohm)

But, for sure, the load can be measured at a instant in time and possible a= lign the regulation loop accordingly

Regards

Klaus

Reply to
Klaus Kragelund

also

the

says

how

back,

more.

code

reset pin of the microcontroller. An upset should not happen often...

V

up to 256 devices on one string. But there is no fixed load, so cannot = really be sure what the load is, except for the maximum load. For Modbus,= RS485, the load is maximum 50ohm (2 120R load terminations and 32 input = loads of 8kohm)

possible align the regulation loop accordingly

Pretty much. You seem to have a handle on it, except (maybe) for one = case where all generators (transmitters) are off. Then your generator line currents must be below 100 uA.

?-)

Reply to
josephkk

You might also be able to estimate the load by putting a sense resistor in the ground connection on the input side. Then have the AD converter in the uC keep an eye on that value. uC often feature 12-16 bit AD conversion so even if the shunt drops less than 100mV it might be enough to get by without amplification.

--
Regards, Joerg

http://www.analogconsultants.com/
Reply to
Joerg

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.