• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

A2D to PWM Circuit Review

Status
Not open for further replies.

1998chevy1500

New Member
Hello all,

I am attempting to design a circuit that will take an analog input and output a PWM signal. The circuit is going to be used in an automotive application, so I need to make it relatively robust so that voltage spikes and weird EMF do not cause problems with it.

Attached is the schematic. Please look it over and let me know what you think. In the mean time, I will fill you in on the application for it.

The device is intended to be installed to replace the voltage controlled dash illumination dimmer found in most automobiles with a PWM control. This is to go along with replacing the bulbs in the interior with LEDs. The 5-12v variable voltage is the voltage coming from the dimmer control. The load (the LEDs and incandescent bulbs) are high side switched, thus the need for a PNP transistor.

The reason for the Vref pin is that the vehicle voltage will vary from 11.5v to 14.5v. Therefore the voltage on the Vref pin will vary from 3.68v to 4.63v. When the dimmer is at full brightness, it will be at the same voltage as the battery, and the AN3 input will be at the same voltage as the Vref pin. This will make sure that the ADC register is at 0xFF (full value) This value is then passed to the PWM converter, which will run at 100% duty cycle.

The reason for the 4148 diodes is to bleed off any crazy voltage spikes that appear on the input pins. I am not sure if they are needed, I saw them in a schematic I found and thought that they couldn't hurt to have. If you feel they are unnecessary, or there is a better solution, I am all ears. :D

The PWM pin goes from 0-5v, when it is 0v, the NPN transistor is off, and so is the PNP transistor. When the PWM pin is at 5v the NPN transistor is on and so is the PNP transistor. I am a little unsure about applying BJTs properly, so the 1k resistors shown on the output schematic may be completely wrong. If anyone has some links for me to research the values I should be using, that would be great.

I hope I covered everything, please let me know if I forgot to clarify anything.

Thanks,
Conrad
 

Attachments

kpatz

New Member
Looks good at first blush. A simpler, no-microcontroller-needed way to get PWM from your dimmer control is with a ramp generator and a comparator. Then you won't need to worry about converting everything to a 5-volt circuit and back.

I don't think you'll need the 4148 diodes, as the PIC has internal clamping diodes on the I/O pins already. You may want to use bigger resistors in place of the 1K, like 2.2K, to ensure the clamping current stays well below 20mA.

You could use a P-channel MOSFET in place of the two transistors to simplify the output part of your circuit.
 
Last edited:

1998chevy1500

New Member
First off, thank you for the fast reply.

Looks good at first blush. A simpler, no-microcontroller-needed way to get PWM from your dimmer control is with a ramp generator and a comparator. Then you won't need to worry about converting everything to a 5-volt circuit and back.
I seem to really struggle with anything that involves analog circuits. So, unless someone already has a circuit drawn up that is supposed to do exactly what I am intending to do, I will stay in the digital world.:D

That, and I can compensate for the light output of an LED being non-linear in relationship to current by having the ADC value map to a lookup table, which then outputs the appropriate PWM value. :D

I don't think you'll need the 4148 diodes, as the PIC has internal clamping diodes on the I/O pins already. Just use bigger resistors in place of the 1K, like 2.2K, to ensure the clamping current stays well below 20mA.
That is good to know. Is there any theoretical limitation on how high of a value I can replace the 1k resistors with? What I mean is, that if I put in say a 10k will that restrict the charging of the ADC input pin such that the ADC is slow to react to a changing input voltage?

You could use a MOSFET in place of the two transistors to simplify the output part of your circuit.
Correct me if I'm wrong, but if I were to replace the transistors with a MOSFET, I would have to use a P-channel MOSFET because the load is high-side switched? And while turning on a P-channel MOSFET is easy (just ground the gate pin), turning it off would require taking the gate to ~12v?

If I were to use a logic level P-channel MOSFET, then I could connect the gate directly to the micro-controller. Unfortunately I do not have a logic level P-channel MOSFET on hand, and I would like to continue on with the build.

I am still trying to read up on the how, when and where to apply MOSFETs and transistors. So I may be completely going about this design the wrong way. Any links to some good reading about applying MOSFETs and transistors in circuits would be greatly appreciated.
 

crutschow

Well-Known Member
Most Helpful Member
Last edited:

kpatz

New Member
I just modeled your transistor circuit in LTSpice and it seems to work perfectly. So forget my MOSFET suggestion, with a high-side switched load that'll be difficult to implement.

As for the input resistors into the PIC, 10K is the maximum Microchip recommends for accurate A/D conversions. It's a matter of balancing accuracy vs. protecting the chip against transients, and for converting a dimmer switch voltage into PWM, you don't need a super-precise conversion. So the larger resistor should be fine.

BTW, what kind of dimmer does your car have? Does it actually output a voltage or is it a rheostat (which limits current)? An easy way to find out is to disconnect the dimmer from the lights and then measure the voltage and see if it still reads 5-12V depending on the knob position. If it turns out to be a current based device like a rheostat, you'll need to wire it into a voltage divider with a power resistor to get a voltage out of it.

If the knob appears to be a pot, check to make sure there isn't already a PWM circuit there. You might find there is and you don't need this circuit at all.

If it's a pot into a voltage control circuit, you could eliminate that circuit entirely and rewire the pot into your 5V power driving the PIC, and you could then eliminate the voltage dividers and the Vref. Or find a pot that will fit in the stock position with the stock knob, and eliminate the dimmer module completely.
 
Last edited:

1998chevy1500

New Member
I have attached an updated schematic, the changes are in red.

crutschow,
Are you thinking something along the lines of what I have attached?? Where any type of voltage surge would be bleed off through the zener. What about on the output of the circuit? Do I also need a similar setup there as well?

Thank you for the link to the automotive design pdf, I am reading it as we speak. Lots of stuff to take in.:eek:
 

Attachments

1998chevy1500

New Member
I just modeled your transistor circuit in LTSpice and it seems to work perfectly. So forget my MOSFET suggestion, with a high-side switched load that'll be difficult to implement.
That is good to know. ;)

As for the input resistors into the PIC, 10K is the maximum Microchip recommends for accurate A/D conversions. It's a matter of balancing accuracy vs. protecting the chip against transients, and for converting a dimmer switch voltage into PWM, you don't need a super-precise conversion. So the larger resistor should be fine.
Well, I don't need super accurate A/D conversions so looks like 10K here I come. ;)

BTW, what kind of dimmer does your car have? Does it actually output a voltage or is it a rheostat (which limits current)? An easy way to find out is to disconnect the dimmer from the lights and then measure the voltage and see if it still reads 5-12V depending on the knob position. If it turns out to be a current based device like a rheostat, you'll need to wire it into a voltage divider with a power resistor to get a voltage out of it.

If the knob appears to be a pot, check to make sure there isn't already a PWM circuit there. You might find there is and you don't need this circuit at all.

If it's a pot into a voltage control circuit, you could eliminate that circuit entirely and rewire the pot into your 5V power driving the PIC, and you could then eliminate the voltage dividers and the Vref. Or find a pot that will fit in the stock position with the stock knob, and eliminate the dimmer module completely.
That, is a very good question... and something that I had not thought of.:eek: It looks like someone (me) should doing some more research to see if I am even using the right part for the job. I will be getting back to you guys on what I find. :)
 

1998chevy1500

New Member
Sorry it took me so long to respond. It took a while to find enough free time to go tear the truck apart to get the measurements.

First off, I believe that it is a potentiometer(it is not a rheostat, you can measure a varying resistance between ground and the illumination pin as well as between +12v and the illumination pin. If I had to guess, it seems to be around a 10-15Ω potentiometer). However, it does not scale as much as I would like it to without any load on it. See my little table below to see what I mean

Code:
No Load Voltage   Loaded Voltage   Amps   Calculated Ohms   Calculated Power
12.14v                11.14v               2.2A    5.06Ω                  24.51W
11.64v                 7.60v                1.4A    5.42Ω                 10.64W
The no load voltage was measured with the illumination load removed from the dimmer switch. The loaded voltage was measured with the illumination load connected to the dimmer switch. The amps were measured between the switch and the lighting load. And finally, the ohms of the load and the power dissipated in the load were calculated based on the amps and loaded voltage.

I am thinking that I could probably get by with something like a 10Ω 10W wire-wound resistor (I have one laying around). Although I really need something closer to 10Ω 20W to be safe. Then I would just tweak the code on the micro controller based on what the max and min voltages end up being until I am satisfied with range of illumination of the LEDs in the dash.

Another option, is to install the LEDs and then just put a load resistor between the illumination wire and ground. That way there is enough load on the potentiometer so that the voltage will still change as you adjust the dimmer. It may not give as much as of a light intensity adjustment as using PWM, but it may be satisfactory for what I am intending to do.

Hmmmmm, decisions decisions decisions.

For now, I am going to assume that this circuit looks good?
 

Ubergeek63

Well-Known Member
ummm....NO

a ramp generator (sawtooth) and a comparator is all you need. the output is high untill the ramp passes the input voltage giving you a PWM output.

Dam
 

kpatz

New Member
Can you take apart the dimmer module to see what lurks inside? You might discover there is a PWM circuit already in there. Or connect it to a scope?

If it's a pot and it's controlling current (which it seems to be at least to some degree based on your readings) there is probably some kind of driver circuit in there. If you take apart the module perhaps you can use the pot from it directly in your circuit.

Have you tried connecting the dimmer switch to some LEDs with a current limiting resistor (no parallel load resistor) to see what you get? If the unit already does PWM it might work without any additional circuitry.
 

1998chevy1500

New Member
ummm....NO

a ramp generator (sawtooth) and a comparator is all you need. the output is high untill the ramp passes the input voltage giving you a PWM output.

Dam
Analog circuits and me just never really got along in school. I would much rather just avoid them. :D That and a digital circuit seems to be easier to tweak minor changes on, and I can do things like have the input voltage map to an exponential curve before going to the PWM, that way I can compensate for the logarithmic output of the LED and make the input voltage match linearly to the output brightness.

Can you take apart the dimmer module to see what lurks inside? You might discover there is a PWM circuit already in there. Or connect it to a scope?

If it's a pot and it's controlling current (which it seems to be at least to some degree based on your readings) there is probably some kind of driver circuit in there. If you take apart the module perhaps you can use the pot from it directly in your circuit.

Have you tried connecting the dimmer switch to some LEDs with a current limiting resistor (no parallel load resistor) to see what you get? If the unit already does PWM it might work without any additional circuitry.
I have not tried tearing the switch apart yet, I think I will try and do that today. But, judging from looking at the switch I doubt that PWM is involved. The potentiometer is connected to a big heat sink inside the switch (you can see it through the vents), so I imagine that it is for cooling the potentiometer and thus I doubt there is PWM setup from the factory.

I do not have a o-scope. The best I can do is a DMM with a %duty cycle measurement and a frequency measurement. A crude tool at best. I would be willing to pick up a o-scope, but for what little amount of electronic tinkering I do it would probably have to be under $100 for it to really be worth it for me.
 

Boncuk

New Member
Hi Chevy,

I'm not worried about PWM, since there are lots of suggestions already.

Here is my suggestion for spike and EMF protection:

Use a Transil-diode rather than a zener. Transil-diodes switch much faster than a z-diode and can stand several tens of amps for a short time, and they have been developed for automotive applications.

Attached is the datasheet of the 1,5KE-series of Transil-diodes (ST).

Those diodes are available as unidirectional and bidirectional types with varying breakdown voltages, starting at 5.8V and ending at 376V.

Boncuk
 

Attachments

Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top