# Simple analog PWM generation - use for isolated voltage monitor



## PStechPaul (May 1, 2012)

Looking at the design of the EMW charger, and particularly the way it now uses an optocoupler to measure input mains voltage, made me think of a possibly equally cheap, but much more accurate, way to implement this function. Basically, a voltage-to-PWM circuit could drive an oprocoupler with a PWM signal proportional to voltage, and then on the isolated control side, the PWM can be filtered to an analog signal which can be read by an A/D converter, or the pulse width itself could be read and converted to a voltage reading by the microcontroller.

Here is a discussion of a simple circuit using a 555 timer:

http://www.mycircuits9.com/2013/04/pulse-width-modulation-pwm-555-timer-ic.html

The illustration shows a sinusoidal AC signal which is converted to PWM with a carrier signal generated separately (could be another 555). An AC signal of variable frequency and voltage could be generated by analog means (or a sine table in an EPROM driven by a variable clock and into a DAC). A single phase or three or more phases could be produced at whatever phase angle is desired. Then the PWM signals could be used to drive the IGBTs or MOSFETs of a motor controller.


----------



## AntronX (Feb 23, 2009)

Keep it simple. Use linear optocoupler, like TIL300.


----------



## PStechPaul (May 1, 2012)

I was unaware of that part. It shows as obsolete at Mouser, but a similar part is available for about $3 each. Not bad..
http://www.mouser.com/ProductDetail/Vishay-Semiconductors/IL300/?qs=sGAEpiMZZMteimceiIVCBzqwdIHFLuAl1mEeybxX1d4%3d

http://www.mouser.com/ds/2/427/il300-67299.pdf

It may still be better in some ways to use the PWM approach. A 555 timer and a basic optocoupler are each about 25 cents, and it may be possible to operate with less current, but this seems like a good product, and I appreciate the suggestion. 

It is similar in cost to the HCPL-7520 and A7520 used in the EMW charger. 
http://www.mouser.com/ProductDetail...GAEpiMZZMt6N1sTk4DRxldE7p%2b3ohlND9uJUlyJL2k=

http://www.avagotech.com/docs/AV02-0956EN

That is simpler because it does not require extra components.

Any of these are much cheaper than the original ISO124 used in the charger, at almost $20 each.


----------



## cts_casemod (Aug 23, 2012)

I discussed this a couple of years ago on some forum. The duty cycle can be used to determine the battery voltage, current or temperature (whatever is being measured).

At present, I stick with using a high side micro and directly send a 10bit representation of the variable we wish to measure trough a serial line. The remaining 6 bits are used to number the variable (for example voltage/current/temperature) or CRC checking. The second micro reads the data, finds the index and updates the 10bit result to an array.

Once more than a few readings are required the serial interface makes greater sense than analog->digital->analog->digital approach both in terms of accuracy and pin usage.


----------



## PStechPaul (May 1, 2012)

There are many approaches to this, with pros and cons to each. A true isolation amplifier may be the best choice when accuracy, speed, and waveform are important. But most require power supplies on both ends, which add to the cost and complexity. Rather than a DC-DC converter, it may be better to utilize a simple line-operated supply made from resistors, diodes, and capacitors, along with a regulator (zener). This is practical when the voltage being measured has a specific and relatively narrow range, such as mains voltage and (to some extent) battery pack voltage.

DC current is probably best measured using a Hall effect transducer, especially when the current is rather high. Using one with a window gives the flexibility of using a single turn for maximum current (100 or 200 amps or so), and then 10 or 20 turns of smaller wire can read current down to a few amps with the same device. Such transducers are only about $10. Many require dual supplies, but some work on 5V or 12V.

In some cases absolute isolation is not really needed for voltage measurement, and a differential amplifier can be used. For line voltages up to 240 VAC and rectified voltages up to 350 VDC or so, 200k resistors limit current to safe levels (under 2 mA). It should be presumed that the control circuitry would be safety grounded and mostly protected from contact by the user. And non-isolated chargers such as the EMW device really should always be used with a GFCI source. 

The problem with the direct digital approach as you recommend is that it requires rather specific programming of the sending micro as well as the receiver, and it may be more efficient to make use of the many ADC channels that are usually available. Speed is probably comparable, but there is a lot less software overhead for a MUX and ADC than for serial channels and shift registers.


----------



## cts_casemod (Aug 23, 2012)

The topic was about opto-isolated gathering of analogue signals. Whenever the designer says isolation is not required or uses isolated devices such as hall sensors is probably off-topic.



PStechPaul said:


> The problem with the direct digital approach as you recommend is that it requires rather specific programming of the sending micro as well as the receiver


For the programmer it's just work as usual. I don't see any problem here?



PStechPaul said:


> And it may be more efficient to make use of the many ADC channels that are usually available. Speed is probably comparable, but there is a lot less software overhead for a MUX and ADC than for serial channels and shift registers.


 If anything offloading the ADC reading to the slave and requesting a burst transfer of SPI data at 4MHz when needed is faster than individually waiting for the ADC sampling as currently implemented.

If you can time how long currently takes, using the millis/micros function, I can do some programming and confirm.


----------



## PStechPaul (May 1, 2012)

The original proposition was in reference to the framework of the EMW charger and perhaps others that already have a fairly large installed base, and other reasons why a major change of hardware and software may not be possible or desired. There are always many ways to accomplish a particular task, but the choices become more limited when there are constraints. For a totally new design, all options are open, and the designer can make choices based on cost, performance, device availability, experience, available tools, and personal preference. But the EMW charger and many other DIY EV projects are geared toward the hobbyist and experimenter, and the KISS principle applies strongly. 

Whenever isolation is discussed, it is important to consider the degree of isolation necessary, as well as if it is actually required at all. There are always some pathways for current to flow from a high voltage point to the control circuit and the operator, whether from capacitance, leakage, or electromagnetic coupling. And there is the issue of degradation of insulating barriers that can result in increasing leakage and eventual possible total failure, compared to a very predictable, constant, and minimal amount of current using a differential amplifier. 

I can see where my idea of using PWM through an opto-isolator may not be very practical, but it is certainly superior to the original modified EMW design using a PC817 in a very non-linear and poorly specified area of its transfer function. I thought perhaps the addition of a few more inexpensive components might maintain the goal of simplicity and low cost while improving the reliability and performance. But something like the IL300 seems more elegant and "better" in most regards.


----------



## cts_casemod (Aug 23, 2012)

Last year or so, I remember there were a few attempts at redesigning the hardware for the EMW charger. I'm not up to date with this, were any of these ever completed?

Your idea makes perfect sense for the purpose of replacing what was in there and I am by no means saying it's not practical. The point I make is that perhaps it makes better sense to redesign the whole control board instead. It's none of my business how EMW sets their product, but as it currently stands I wouldn't purchase it and I have no intentions to patch what was already designed, when I can redesign something better from scratch, very likely cheaper as well.

I'm not sure you realized I'm looking for a 'beta tester' for my inverter, where I have many of the discussed features already implemented and working. I have a main control PCB that commands the charger/pre-charge and inverter so all the necessary features could be offered as small independent modules for whatever was needed.


----------



## PStechPaul (May 1, 2012)

Yes, about a year ago I made many suggestions for a redesign and Valery did make some significant improvements, but not what I considered sufficient. I asked him for some PCBs and parts, and all I got was a small box of old boards and prototypes. Meanwhile Crackerjackz sent me a working control board with a display, and two customers have sent me their complete non-working chargers to look at and fix, if possible, which is what I am doing now. Meanwhile Valery seems to have "left the building" again, probably working on his JuiceBox and perhaps an isolated charger design, but his website does not show any real progress over the past year.

There is another possibility for a somewhat improved and stupid simple voltage measurement means, using an opto-isolated JFET which acts as a current-to-resistance device at low signal levels and as a transconductance device at higher levels. The basic device is the H11F1/2/3, which costs about $2.50:

http://www.mouser.com/ProductDetail...=sGAEpiMZZMugPZL2oX39yI7jG0lGkOJrIGnGiSHg2Lk=

http://www.mouser.com/ds/2/149/H11F1M-185284.pdf

At 2 mA input the output current is 50 uA (25 uA/mA), and then from 6 mA to 14 mA it is from 33 to 39 uA/mA. This compares to the PC817 and the similar PS2501 which has a CTR that varies greatly and non-linearly with applied voltage and diode current from 50% to 400%. It would need to be calibrated, but so does the PC817, and it may be more stable and capable of fairly decent accuracy with a little curve fitting or even analog linearization techniques (parallel and series resistors). The big advantage of such a device is that no power supply or amplifiers are needed on either end, and it might essentially be a drop-in replacement on the EMW charger. However, it is an SO-6 device which would need to be adapted to a DIP-4 PCB footprint. 

I don't know if I could do the beta testing on your inverter, but I'm willing to help if I can. I am thinking about making a very simple inverter for low power applications (1-5 HP), but I'm not ready to do an EV car.


----------



## SirNick (Jun 14, 2015)

Just IMHO, after reading the couple thousand posts in the EMW thread, I don't see the point in maintaining compatibility with either the control board PCB or the software. I would guess that most current users with any standing issues would probably exchange the entire board for a better option without a second thought. I would.

It seems like this ought to be a problem that has been solved by now. Nearly any switching PSU will be communicating across a HV/LV barrier at 3-400VDC. Any reason what they're doing isn't sufficient for this? Granted they're using dedicated ICs with the most efficient point of measure so they can optimize the kind of data they have to transmit through the isolation barrier, but might it be possible to reuse some of that too?

The whole bit about trying to Rube Goldberg in a couple 555s, plus all that format conversion, strikes me as a last-ditch effort, or if for whatever reason avoiding micros at all costs is a primary design goal.


----------



## PStechPaul (May 1, 2012)

This thread started with a simple idea I had that I thought was interesting and possibly with some practical application, perhaps to replace a poor choice in the newer EMW chargers. The discussion revealed some alternate approaches that have advantages and drawbacks, and has been useful in that respect.

I agree that the control board (and the driver) of the EMW charger will need to be replaced, and good riddance. I was going to use a PIC instead of the Arduino, and possibly also a different display and a keypad instead of the two buttons, but I think I will keep those components and the same form factor so that it will fit the charger, and be programmable by those who built the kit.

As much as possible, I wanted to maintain hardware compatibility so the original software might still be usable, with some modification, but I think now I have had enough experience with the Arduino and the display that I can make a much better interface and a more reliable way to achieve the charging functions and other things presently implemented.


----------



## cts_casemod (Aug 23, 2012)

SirNick said:


> The whole bit about trying to Rube Goldberg in a couple 555s, plus all that format conversion, strikes me as a last-ditch effort, or if for whatever reason avoiding micros at all costs is a primary design goal.


I know, same with surface mount components - not ideal for the hobbyist. 
The goal is to make the PCB a black box to the user if he wishes so. The hardware/software will be implemented already and any savings from improving the manufacturing process could be used to professionally assemble the board. Perhaps a 50 piece batch is reasonable. 

And this would avoid the stresses I see about missing parts/wrong placement, dead boards altogether. In addition one could offer two versions: one without PFC and larger output power and one with PFC and slightly less output power, all else being equal.

This is a similar approach as I'm using for my inverter. Modular approach to meet needs or cost standpoint and full optimization. For the user it doesn't matter too much if the boards ship assembled and they can be purchased as modules according to needs.



PStechPaul said:


> I don't know if I could do the beta testing on your inverter, but I'm willing to help if I can. I am thinking about making a very simple inverter for low power applications (1-5 HP), but I'm not ready to do an EV car.


About that better to send me a PM to avoid hijacking this thread.

Basically my inverter is done. Given my personal circumstances now I don't have the space to make a full review. The idea is to putt altogether working, document the building process with what I provide and what the user needs to do, add some features as required and if there is enough demand make a batch of x boards. I want someone to do it as to see what difficulties people would have.

I currently don't include gate drivers so the power level & voltage are customizable, starting at 48V nominal. At a later stage I could offer some low cost drivers for 100-200A output.


----------



## cts_casemod (Aug 23, 2012)

Nearly forgot. Using an isolated ADC is also an option. 

This device:
http://dkc1.digikey.com/uk/en/tod/S...udio/Si890x-Isolated-10-bit-ADCs_NoAudio.html
is a SPI DAC with built in digital isolator, costs £2,5 ($4) and has 3 D/A channels.

Change a few lines of code on the master and voila


----------



## PStechPaul (May 1, 2012)

That seems like another good device (it has three channels of ADC not DAC), but it also requires a line side power supply and an SPI interface on the control side. I would agree that once the software "hooks" are in place, SPI is not hard to work with, but that would require major hardware changes to the EMW design. So I'd consider it for a new design, but not for the present project.

My original hope was to make a V-F converter in the form of a relaxation oscillator made from discrete components. I did a simulation using a model of an SCR and it works from 75V to 150V. This was originally for an LED flasher and the frequency is still rather low for convenient PWM filtering, but it may work into the kHz range and possibly a wider range of voltages as well, using a different SCR or maybe a UJT. It's also possible to replace the SCR with a tiny microcontroller that would monitor the voltage on the capacitor and then trigger the output to dump the voltage into the LED.


----------



## SirNick (Jun 14, 2015)

At the risk of repeating my earlier sentiment (really not trying to beat a dead horse here), why would you even care about the degree of hardware changes? Is it worth saving it?

The old design had HV and LV mixed up all over the place, reference voltages traversing boards with unshielded cabling terminated on chinsy 0.1" headers that don't even lock into place, or offer insertion polarity protection... Not to even speak of the questionable software architecture...

You wanna do the community a favor? Chuck the whole thing and start over. ;-) A fair (and perfectly workable) compromise would entail re-using the expensive bits (IGBTs, inductors, etc.) since those seem to be chosen with some degree of engineering effort behind them.

Existing users might like to retain their display, but if it were my design, I would make the box CAN bus operated with maybe a serial programming port, and offer an optional programmer with the LCD and all, which communicates over CAN and can be located anywhere. Then the charger can hang out in the trunk, hood, or wherever. Controls in the dash, glove box, or a plug-in hand-held unit.

While I'm throwing around unsolicited opinions... I really don't think Arduino is the platform to go with here. Yes, it lowers the barrier to entry for contributing coders, but ... and I'm sorry if this comes across snooty ... if your contributors can't figure out how to use a real dev environment and/or toolchain, do they have any business writing code that is responsible for containing the fury within a multi-hundred volt Li-Ion battery pack, with charging currents of 20-100A? This thing isn't a toy, you know? Maybe that's not fair, but I like the idea of knowing my firmware is written by someone that knows how to handle a pointer.

Outside of Arduino-land, Atmel AVRs are a perfectly fine chip, if not a little pricey for what you get. Their docs are fantastic. I'm not much of a PIC fan - I kinda feel like the only reason to use them for new work is if your dev team have been using them for 20 years and can't justify learning a new platform. Although, they have a good history of long-term availability. Admittedly, this is probably just personal bias, without any substantial meat to the argument.  They work and work well. Dev tools and licensing stuff sucks though.

IMO, the new fleet of ARM Cortex chips is where it's at. But, ultimately, you can get the job done with an 8-bit CPU, if you're more comfortable with look-up tables and fixed-point math than fast 32-bit int and floating-point arithmetic calculated on-the-fly.

Just my 2c, for what little that might be worth. Carry on.


----------



## cts_casemod (Aug 23, 2012)

PStechPaul said:


> That seems like another good device (it has three channels of ADC not DAC), but it also requires a line side power supply and an SPI interface on the control side. I would agree that once the software "hooks" are in place, SPI is not hard to work with, but that would require major hardware changes to the EMW design. So I'd consider it for a new design, but not for the present project.


 ADC it is, of course!

There is already a 15V HV_GND referenced power supply available to feed the IGBT gate driver. Drawing 5mA or so from it to power the circuit would not be an issue at all. Add a 78L05/ LM1117, two capacitors... done.

As to hardware I don't quite get the confusion. The TFT uses the SPI bus already, all that would be needed is a slave select line and for that the current analogue input can be used (configured as digital output). So that's zero hardware changes, and a few wires out, really.

I agree with SirNick in that re-using the power hardware and fitting in a drop in replacement control board would be my choice. I would replace the atmega328 with an AT90PWM (which has a hardware override to stop the PWM and its capable of cycle by cycle current limit), add gate drivers with built in desaturation detection, some sort of digital communication, for example to immobilize the inverter/gather data and a few optimized routines for PFC correction using buck PFC topology rather than a dumb buck converter. This would save the front end dc-link pre-charge, capacitors and allow a much smaller bridge rectifier, making newer units less expensive to initially purchase. 

As years passed I had to re-engineer many of my projects as new technologies emerged, that were available back then. This charger is a similar example. Today there are better approaches that require a complete redesign, allow more features and a smaller price tag. Why not take advantage of this?


----------

