• 1 Post
  • 53 Comments
Joined 3 years ago
cake
Cake day: July 2nd, 2023

help-circle


  • the higher I can get the frequency, the less ripple I’ll have to deal with.

    Why not just use a low-pass filter to remove the switching frequency? Most regulator outputs are already buffered with a large capacitor to stabilize the voltage, so adding the inductor to form an LC circuit is not exactly adding much.

    However, there’s nothing really stopping me from doing variable frequency.

    Why make this harder? A constant frequency simplifies the analog design, because you can do the bandwidth analysis once when verifying stability. A feedback loop that is statically and dynamically stable at one frequency might entirely fall apart at another frequency, because the frequency response of the regulator itself or the load may interact with the regulator frequency.

    combine 3 pwm signals into one per channel

    cpu begins grinding cycles to reset the buffers to adjust everything to a new duty center.

    I’m struggling to see how this 20 MHz ATTiny would have so much trouble regulating a DC output that it needs to resort to rather strange techniques.

    I mainly have experience on the TI MSP430 and ATMega328p, but both those microcontrollers have a robust PWM feature set that includes fixed waveforms that trigger an output whenever a value in memory is equal to the waveform. Such a value could also be the result of the ADC, meaning that zero CPU involvement is needed to keep regulation. That the ADC and PWM peripherals can be clocked independently from the CPU means this can all be done in the background, so the CPU can just go to sleep.

    If the ATTiny3224 doesn’t have such capabilities, you would want to figure out another way to do things in the hardware peripherals – or even getting a different chip – than do regulation in software.


  • In the context of DC/DC converters, I don’t know if there’s a specific name for the regulation precision. But analogizing from op amp designs, I think a reasonable term would be “gain bandwidth”. This is because the objective of the regulation mechanism is to apply a change which brings the output voltage back to some target.

    If the output has moved away from the target by -10 mV, then the objective is to adjust the output by +10 mV. But this cannot happen in instantaneous time. The feedback loop delay necessarily means a small lag. But even after the lag, if there is insufficient gain, the output might only be able to move -2 mV per feedback cycle. So it would take 5 cycles to return to the target.

    By adjusting the PWM frequency, you might be able to reduce the length of time for each feedback cycle, so doubling the frequency might mean you can now move -4 mV/cycle. But in exchange, there is less precision. So rather than -4 mV/cycle, it now might be -8 mV/cycle.

    Doing this for two cycles means the output voltage is +6 mV. So the next cycle would try to correct with -8 mV, which brings the output to -2 mV. And so on.

    A higher frequency with reduced precision has resulted in an output that will “wobble” more, but it will indeed converge faster toward the target, when dealing with larger deviations.

    A circuit without load that is statically stable will maintain a target voltage indefinitely. Applying a static load to this circuit will cause a temporary deviation, a subsequent correction, and then it’ll maintain the target voltage indefinitely. But applying a dynamic load means this process is repeated over and over. That is to say, dynamic stability is a continual transient condition, and so the analysis is very much related to what happens in a step transition: how a regulator reacts when going from stable to perturbed.

    All regulator designs should quantify their result in how quickly it can return to the target (mV/s) when perturbed once or repeatedly (expressed as a frequency). This seems to match the term from op-amps.


  • I suppose it’s worth mentioning that the 3224 datasheet suggests that it’s perfectly capable of running at 3.7 volts directly, since it has a wide voltage range from 1.8v to 5.5v absolute. But I imagine you have other ICs that need the 5v supply.

    I’m not entirely familiar with what you mean by a “convertor”, but I presume it’s some sort DC to AC function. Given the output loading, 3 amps through that Toshiba MOSFET seems reasonable enough, with the power dissipation being something like 0.3-0.5 W max, depending on switching speed.


  • A push-pull BJT configuration seems like it could be appropriate, if your application will be unbothered by limiting the Vgs to a max of 5.5v (the 3224’s max supply voltage). The MOSFET in question seems to be good for Rds(on) below 20 mOhm at that voltage, so it seems fine for at least a handful of amps.

    If you are doing higher frequency switching than a few kHz, then you probably want to use a driver IC. And especially so if you have a higher voltage bus than the 5v needed by the ATTiny.


  • the original switch (as it looks good) which it turns out, does not really appreciate having to switch 230V instead of the 12V (or 24V?) it was designed for. I believe I can patch up the switch to work as designed, however I do want a better solution to switching the lamp on and off.

    Please, please do not ever subject electric components to more than their rated voltage. Unless the switch has an overt label that says it is rated for: 1) 230 volts, and 2) AC, this is a recipe for tragedy.

    I will briefly explain why, and then get to the suggestions. In a nutshell, components designed for 12 volts use closer spacing between conductors, premised on air’s natural insulating ability. Likewise, the insulation and plastic housings are designed to withstand that low voltage without becoming a hazard. But higher voltage means the spacing must be wider, the insulation thicker, and above 60 volts is when more strict regulation come into effect, because that’s the international threshold for where there is a serious risk of fatal electric shock.

    As for DC vs AC switches, they are built differently to suppress arcs that form when opening the contacts. When a manufacturer gives the voltage rating for both DC and AC, it is often the case that one is substantially lower than the other, depending on which type of arcs they intended the switch to safely suppress. This is a worst-case rating, though, and a modern LED light bulb is unlikely to cause arcs (except when it’s dying).

    To my knowledge, there are no common pre-built relays that provide their own low-voltage DC supply. Some relays do provide low-voltage AC (eg 24 VAC to control 240 VAC), but that doesn’t help you since that’s still putting AC into a DC switch.

    However, a fairly safe approach would be to use a 230 VAC relay with the most common, safe power supply in the world: a USB phone charger. Provided that your relay can switch on 5 VDC, it should be easy enough to find a small USB charger that can be hidden inside the lamp, wired safely to 230 VAC, and that feeds 5 VDC to your existing tractor switch, which connects to the relay.


  • Generally, assume the lower result unless explicitly stated otherwise. If there are two pins supplying 12vdc but only a single output rating, then the assumption should be that the PSU produces a single 12vdc rail, and the total of both pins is 5A max. It is implied (unless otherwise stated) that the full rating of 5A can be drawn from just a single pin.

    From a marketing perspective, if there were multiple output rails, they have an incentive for them to list them out in detail. ATX PSUs for PCs do this.

    From a safety perspective, it would be downright irresponsible to design a connector on a finished product (like this standalone PSU) that has a lower per-pin rating that what the supply can offer, so any decent pre-built PSU will not have per-pin limits that are lower than the total output limit of that group of pins. As a counterexample, ATX PSUs are a component in a larger product (a computer) and so individual pin limits must be adhered to.



  • I wish you the best of luck in your automotive endeavors. But specific to that field, be advised that automobile power can have a lot of voltage spikes, most notably right after the starter motor shuts off after ignition. This could be as high at 15v or around there. So if you’re not probing during this dynamic event, then your scope will likely still be useful.

    I will also note that a used benchtop scope can be had for about $200 USD, often with good tactile controls and acceptable bandwidth and voltage capabilities. A cursory search on eBay shows a 2-channel 50 MHz Siglent SDS1052DL with 400 volt inputs. For general technician and hobbyist diagnostics work, that’s a good deal for an instrument that is one step above what a competent DMM can provide.


  • I read your question and was wondering how an oscilloscope could be giving such widely-differing values, with the widest being 0.4 volts against itself and nearly 0.8 volts against a separate instrument. Then it dawned upon me that this oscilloscope is a PC-attached scope with some unique operating limits. I say this having come from a background of using only benchtop digital scopes.

    The first limitation is that your scope has a very narrow input voltage range, with the manual listing it as +/- 5 volts but damage would only occur at +/- 35 volts. This is voltage measured at the input BNC connector, so it’s before any probe multiplication is accounted for. Whereas if we look at an inexpensive benchtop oscilloscope like the now-fairly-old Rigol DS1052E, it has an input voltage range of +/- 40 volts. The practical result is that to measure something like a laptop power supply, the Hantek must use attenuation probes, whereas the Rigol can measure that voltage directly. Slightly more expensive oscilloscopes have wider ranges, with some being +/- 400 volts.

    Attenuation probes are great for measuring wider voltage ranges, but they come at the cost of both precision and accuracy. The loss of precision comes from the fact that the resolution of the oscilloscope is unchanged, but the voltage range is wider. In concrete terms, both the Hantek and Rigol use an 8-bit ADC, meaning that the span of input voltages visible on the display are mapped to 256 discrete values. If the ADC is imprecise by 1 bit, then that will amount to the reading being off by a certain number of millivolts. But something like a 20:1 attenuation probe causes that millivolt error value to be multiplied by 20x. Whereas the Rigol doesn’t need attenuation probes, and thus doesn’t suffer this penalty.

    Furthermore, the Rigol has a neat trick: it uses a separate, more-precise internal attenuation circuit for voltages smaller than +/- 2 volts, and then uses its normal-precision input circuit for all other voltages up to +/- 40 volts. The ADC is unchanged in both modes, and the scope switches seamlessly between the two (though usually with an audible click), but this means that a 20:1 probe measuring a laptop charger would actually cause the Rigol to switch into its precision circuit, which means the Rigol might never pay the precision penalty that the Hantek might. Perhaps the Hantek has a similar feature, but it is not listed in the manual.

    As for accuracy loss due to attenuation probes, this is not affected by the amount of attenuation, but rather is a function of how accurate the attenuation is. When a probe is marked as 20:1, it could actually be 19:1 of 21:1 or anywhere around there, depending on the manufacturing tolerances. However, accuracy issues can be resolved through calibration, which you’ve done.

    Overall, it seems that you are operating at the very limits of what your Hantek scope can deliver, with its 8-bit ADC and limited input range. Yet your test calls for a voltage 4x higher, so some error is to be expected from the 20:1 probe. With the 10:1 probe, the error is a bit smaller, but now you’re outside the affirmative safe voltage range of the scope. Calibration can only fix accuracy issues, but I think your error is now predominantly due to loss of precision, which cannot be resolved after-the-fact.

    If your intended use is to measure signals in the range of a laptop charger and require faithful analog voltage measurements, I’m afraid that you may need to find a different instrument.


  • In any case, pending your reply, I would suggest the following circuit for reliable operation. This will require a P-channel MOSFET, which is different from the two MOSFETs you tried earlier, which are all N-channel. This will also use two resistors. I am making an assumption that your speaker module simply requires two wires at feed it 4 volts, and does not care whether we add a switching circuit to either wire, the positive or negative wire.

    suggested circuit 1

    This type of circuit would be described as an inverting, low-side MOSFET switching circuit. The inverting part means that when the MOSFET is fed a lower voltage, that causes the transistor to become active, whereas a non-inverting circuit would require feeding the MOSFET with a higher voltage to make the transistor become active.

    Low-side switching refers to the fact that the load (ie the speaker module) is permanently attached to the higher voltage (the high-side) and we are manipulating the low-side. Not all electronic loads can be used with low-side switching, but this is the easiest mode to implement using a single MOSFET transistor. As a general rule, to do low-side switching always requires a P-channel MOSFET. WARNING: a P-channel MOSFET has its drain/source reversed from how an N-channel MOSFET is usually wired up. Observe the schematic very carefully.

    As for why we cannot do high-side switching (which would use an N-channel MOSFET), it is because a typical N-channel MOSFET requires that the gate be a few volts higher than the source. But consider that when the transistor turns on, the drain and source become almost-similar voltages. So if the drain is attached to 4 volts, and as the transistor becomes active, the source rises to something like 3.95 volts, then what gate do we use to keep the transistor active? If we give 4v to the drain, then the gate-to-source voltage is a mere 0.05 volts, which is insufficient to keep the transistor on. We would need an external source to provide more gate voltage, relative to the source pin. If we tried such a high-side switching circuit anyway, it would quickly oscillate: the transistor tries to turn on, then turns itself off, then back on, and so forth. Or it would sit comfortably at some half-way gate voltage, where the transistor is barely-on, barely-off. This is not useful as a switching circuit.

    The way that my suggested circuit works is as follows: when the tripwire (marked as SW3) is in place, then R4 and R2 will form a voltage divider. Given that the battery supplies 4v, we can show that the voltage at the MOSFET’s gate will be 91% of 4v, or 3.64 volts. This should be just enough to prevent the P-channel MOSFET from becoming active. Note: a P-channel MOSFET becomes active when there is a low gate-to-drain voltage, with 0v causing the transistor to become active. In this way, with the trip-wire, the transistor will not allow current to pass through the speaker.

    When the tripwire is pulled out, this breaks the connection to R4. That leaves the gate connected to only R2, which is connected to the negative side of the battery. Thus, any charge in the gate will seep away through R2, meaning that the voltage across R2 will equalize at 0v. This means the gate-to-drain voltage will be 0v, which means the MOSFET will activate. And that allows current to power the speaker module.

    Note: one end of the tripwire (labeled #1 in the diagram) will still have 4v on it. If the tripwire is cleanly detached from the whole circuit, using your loop-of-wire and nails idea, then there is no problem. But if the tripwire is still hanging onto the 4v side of the circuit, then be careful that the tripwire doesn’t make contact with another part of this circuit. The R4 resistor will still be there, so there won’t be a short circuit or anything bad like that. But if that tripwire reconnects to the gate, then the transistor will deactivate again, stopping the music.

    I wish you good luck in this endeavor!


  • I’m going to try to answer your situation, but although time appears to be of the essence, I need to first understand exactly what you’ve already tried. So bear with me for a moment.

    The examples I found were very simple, involving an NPN transistor (2n2222), 10KΩ resistor, battery, and DC Piezo speaker.

    With my initial attempt, I wired +4V from the switch to the transistor’s collector and then separated the collector from the base with a resistor. I connected the emitter to the pin that, when the switch is engaged, would send 4V through and power the module.

    Does this diagram correctly describe what you tried as a first attempt?

    schematic diagram of attempt 1

    Someone suggested that what I actually needed was a MOSFET …

    I have the resistor connected between Gate and Drain, +4V going to drain, and the load from the module on Source.

    With an RFP30N06LE, I get about 2V output to Source. With an IRF840N, I’m only getting 0.9V.

    Do these diagrams match your circuits with each MOSFET?

    schematic diagram of attempt 2

    schematic diagram of attempt 3

    What I am not able to understand, in your last photo with the MOSFET, is where the blue wire is going.



  • I see. Given those constraints then, I don’t see any option besides a new heater. Ideally, the new heater would be built with less circuitry, so there would be fewer things to break.

    Looking at the Adax Clea product description, it seems overly complicated for a radiator, IMO. I’m not sure I’d want triac switching for something like a heating appliance. Resistive heating doesn’t strictly require silicon switches, when a relay should work. But I suspect an equally-svelt radiator that’s also simple may be hard to find.



  • My experience is mostly with repairing lower voltage devices (eg 12v to 54v PoE). In your case, a phase to phase short has made quite the mark on that PCB, and being a much higher energy event than low-voltage DC, its possible that some delamination has occurred, with downstream effects on expected trace resistance, capacitance, and leakage/creepage.

    Were this a low-voltage board, I personally wouldn’t be worried about those downstream effects. But for AC line voltage, I’d rather buy myself the peace of mind. Do keep parts from the dead board that are salvageable, but IMO, a thermal event on the AC side of a 400vac board would disqualify it from continued service.

    P.S. does that circuit not have an onboard fuse? I’m not seeing one and I’m kinda surprised. Presumably an upstream circuit breaker or fuse was what tripped to stop this turning into a fire?


  • I’m taking a guess that perhaps the fridge makes similar assumptions that automobiles make for their lamps. Some cars that were designed when incandescent bulbs were the only option will use the characteristics resistance as an integral part of the circuit. For example, turn signals will often blink faster when either the front or left corner bulb is not working, and this happens to be useful as an indicator to the motorist that a bulb has gone bust.

    For other lamps, such as the interior lamp, the car might do a “soft start” thing where upon opening the car door, the lamp ramps up slowly to full brightness. If an LED bulb is installed here, the issues are manifold: some LEDs don’t support dimming, but all incandescent bulbs do. And the circuit may require the exact resistance of an incandescent bulb to control the rate of ramping up to fill brightness. An LED bulb here may malfunction or damage the car circuitry.

    Automobile light bulbs are almost always supplied with 12 volts, so an aftermarket LED replacement bulb is designed to also expect 12 volts, then internally convert down to the native voltage of the LEDs. However, in the non-trivial circuits described above, the voltage to the bulb is intentionally varying. But the converter in the LED still tries to produce the native LED voltage, and so draws more current to compensate. This non-linear behavior does not follow Ohm’s Law, whereas all incandescent bulbs do.

    So my guess is that your fridge could possibly be expecting certain resistance values from the bulb but the LED you installed is not meeting those assumptions. This could be harmless, or maybe either the fridge or the LED bulb have been damaged. Best way to test would be installing a new, like-for-like OEM incandescent bulb and seeing if that will work in your fridge.


  • To start, the idea of charging in parallel while discharging in series is indeed valid. And for multicell battery packs such as for electric automobiles and ebikes, it’s the only practical result. That said, the idea can sometimes vary, with some solutions providing the bulk of charging current through the series connection and then having per-cell leads to balance each cell.

    In your case, you would have a substantial number of cells in series, to the point that series charging would require high voltage DC, beyond the normal 50-60 VDC that constitutes low-voltage.

    But depending on if charging and discharge are mutually exclusive operations, one option would be to electrically break the pack into smaller groups, so that existing charge controllers can charge each group through normal means (ie balancing wires). Supposing that you used 12s charger ICs, that would reduce the number of ICs to about 9 for a pack with a nominal series voltage ~400vdc. You would have to make sure these ICs are isolated once the groups are reconstituted into the full series arrangement.

    Alternatively, you could float all the charging ICs, by having 9 rails of DC voltage to supply each of the charging ICs. And this would allow continuous charging and battery monitoring during discharge. Even with the associated circuitry to provide these floating rails, the part count is still lower than having each cell managed by individual chargers and MOSFETs.

    It’s not clear from your post what capacity or current you intend for this overall pack, but even in small packs, I cannot possibly advise using anything but a proper li-ion charge controller for managing battery cells. The idea of charging a capacitor to 4.2v and then blindly dumping voltage into a cell is fraught with issues, such as lacking actual cell temperature monitoring or even just charging the cell in a healthy manner. Charge IC are designed specifically designed for the task, and are just plain easier to build into a pack while being safer.


  • I don’t think there’s a good way to adapt this circuit to provide current limiting on the 18v rail. Supposing that it was possible, what behavior do you want to happen when reaching the current limit? Should the motor reduce its output torque when at the limit? Should the 18v rail completely shut down? Should the microcontroller be notified of the current limit so that software can deal with it? Would a simple fuse be sufficient?

    All of these are possible options, but with various tradeoffs. But depending on your application, I would think the easiest design is to build sufficient capacity on the 18v rail so that the motor and 5v converter inherently never draw more current than can be provided.


  • I suppose the first question is whether you had the baud rate set correctly. The photo of the “cleaned up signals” (not entirely sure what you did, compared to the prior photo) seems to show a baud rate of 38400, given that each bit seems to take about 25 microseconds.

    As for the voltage levels, the same photo seems to show 5v TTL. So it doesn’t seem like you would need a level converter from 15v RS-232 levels. This is one of the few times where the distinction between a “serial port” and an RS-233 port makes a difference, but a lot of data center switches will deal using 5v TTL, because the signals aren’t having to travel more than maybe 5 meters