PWM circuit to dim an LED

jayanthd

Joined Jul 4, 2015
945
Okay thank you Jayanthd. There is no hurry as I cant do anything practical for a few days. (Have to earn a quid).

I have already looked at chips to buy online (not purchased any); and downloaded this as a quick introduction: https://www.instructables.com/id/Intro-to-PIC-Microcontrollers/

I will do the PM now
As you need only one ADC and one PWM pin for controlling the brightness of the LEDs (Parallel driven by a MOSFET) you need an 8 pin PDIP PIC12F1840.

PIC12F1840 has Internal 4 MHz Oscillator and there is no need for External Crystal or Loading capacitors for it.


Jayanth D
 
Last edited:

cmartinez

Joined Jan 17, 2007
8,799
Hello, Mellisa. Maybe you'd like to also take a look at the PIC10F322, it's a tiny chip with a very small instruction set, an excellent option to start learning MCU programming. And yes, it does have PWM generation capabilities, plus ADC, complementary waveform and other interesting features. It also has a configurable internal oscillator. Take a look at this thread I started last year, you may find it interesting.
 

jpanhalt

Joined Jan 18, 2008
11,087
For PWM control of the LEDs, there are 3 common ways to do it:

1) Discrete components, like the LM555, other inverters, or comparators. See: http://www.4qdtec.com/pwm-01.html for several examples. No programming is required.

2) A discrete, purpose-designed chip (e.g., TPIC 2101, http://www.ti.com/lit/an/slit110/slit110.pdf ), which can be analog controlled with a potentiometer (e.g., TPIC2101) or digitally controlled. No programming is required per se, but for the digital solution, you will need a data signal.

3) A microcontroller as has been suggested. That solution requires a small amount of code that you can write or get examples from here and elsewhere. If you are new to coding, I would recommend learning in either C (or its variants like the Arduino uses) or Assembly. Basic is also used, but the pool of available helpers appears to be smaller for that language.
 

Thread Starter

Mellisa_K

Joined Apr 2, 2017
391
GH600-C031 COB LED 4-5 volts.png Hello @jayanthd ,

I’m sorry I’ve been offline and unable to answer you.

The original “Big LED” I brought to this forum post is pictured in Image 1 in this post. However, this has obscure pedigree as I hacked it out of a cheap Chinese piece of kitsch and couldn't find much information on it. (Notwithstanding research by @ci139 ). The specs in Image 1 are mine, inferred from its housing (Volts); and my measurement of I; and my W (from arithmetic).LED

A post from @crutshow (see #25) showed me a better option, LXHL—BW02 which is a 1 watt https://www.luxeonstar.com/assets/downloads/ds23.pdf . This has been discontinued and this one should suffice https://www.luxeonstar.com/lxhl-bw02-white-luxeon-emitter-led-45lm as a replacement. I think this is the way to go because it’s a documented product with a datasheet and readily available without hacking. Here is its datasheet https://www.luxeonstar.com/assets/downloads/sp-05.pdf

I haven't obtained any of these LEDs but I will order some asap. A 1 watt version of this would be sufficient and I will probably settle for a “warmer” light output in the final production of our dimmer.

Small componentry and low power requirements (1.5 volts to 4.5 volts using batteries) are the main design criteria for this project.

I am expecting to go through a round of prototyping iterations before finally settling on the right configuration of the full circuitry regarding power, physical size etc. However I have settled on 1w of power for the LED.

Please note that I am not proficient at SMD soldering - even though I have referred you to SMD diode options above. This is not deliberate. I would prefer to use components with legs to at least develop the prototypes. I just don’t know enough about where to find such components vis a vis SMD versions of the same thing in the time available to answer your question.

Hope this helps.

Regards,

Mellisa
 

Thread Starter

Mellisa_K

Joined Apr 2, 2017
391
Hello, Mellisa. Maybe you'd like to also take a look at the PIC10F322, it's a tiny chip with a very small instruction set, an excellent option to start learning MCU programming. And yes, it does have PWM generation capabilities, plus ADC, complementary waveform and other interesting features. It also has a configurable internal oscillator. Take a look at this thread I started last year, you may find it interesting.
Hello @cmartinez
Looks like a great idea. I'm so excited at the prospect of learning about PIC technology. it sounds perfect for my current project - especially since i have in passing learnt about a 555 solution and am currently learning about a comparator X 2 solution. I didnt know of this PIC technology until @jayanthd told me in a post here.

BTW @cmartinez and @jayanthd given your knowledge of what I want to achieve and my background in this field, could you please recommend a book i can download on my kindle to get a good grounding in this PIC stuff. I wan tto invest in a good introductory text and in PC to micro-controller platforms (I have done some work on arduino (under the very helpful tutelage of @dendad . My programming experience has come from professional applications like VBA in MS Excel (an object language) as well as plenty of experience in sequential (non object oriented) "languages" like SPSS and SAS which are powerful statistical packages similar I am told to Fortran or Cobol except at a much higher level of abstraction.
 

jayanthd

Joined Jul 4, 2015
945
If the Led module requires a 4.5V min power supply then you can use a PIC12F1840 which runs from 5V and you can use a 2N7002K Logic Level Mosfet to drive the Led Module.

Use the PIC12F1840's internal 4 MHz oscillator.

POT connected to RA0 input.

The 2N7002K can handle max drain current of 380mA.

Or you can use NTF3055L108 N-Channel Mosfet which is a SOT23 package Mosfet and can handle max 3A current.

Find the attached circuit.

Code coming soon.


5V Power supply.

LED requires 4.5V an dso 0.5V has to drop across a series resistor.

LED current is 350mA.

So, Rseries = (V - Vled) / Iled = (5V - 4.5V) / 350mA = 1.43R

Choose 1.5R.

Wattage?

P = I * I * R

0.35A * 0.35A * 1.5R = 0.18W

Use a 1.5R 0.25W 1% resistor.
 

Attachments

Last edited:

Danko

Joined Nov 22, 2017
2,199
My aim is to variably dim this LED using something other than a variable resistor.
Hello @Mellisa_K,
Take a look at this neat stuff:
It can work from one cell and high efficiency PWM dimming changes LED current from 350mA to zero.
"Dimming Function.
During normal operation with the CTRL/SHDN pin connected to VIN, the LED drive current is controlled at 350mA. The drive current can be reduced by changing the voltage on the CTRL/SHDN pin. For VIN • 0.2 < VCTRL < VIN • 0.9, the LED current is proportional to VCTRL/VIN. This allows a simple potentiometer from VIN to control the current without sensitivity to the battery voltage."

upload_2019-8-25_12-29-24.png
 
Last edited:

jpanhalt

Joined Jan 18, 2008
11,087
Maybe there are other dedicated LED dimmer chips.
You mean like this device: https://www.jkllamps.com/pdfs/ZDM-01.pdf

There are also PWM controller chips designed for N-mosfets configured as discussed so far that can be controlled with a pot or digitally. The TPIC2101 is just one such device.

My impression is that Melissa wants to build her own using an MCU. Instead of a pot, she might want to consider a rotary encoder, which would avoid the need for an ADC.
 

jayanthd

Joined Jul 4, 2015
945
You mean like this device: https://www.jkllamps.com/pdfs/ZDM-01.pdf

There are also PWM controller chips designed for N-mosfets configured as discussed so far that can be controlled with a pot or digitally. The TPIC2101 is just one such device.

My impression is that Melissa wants to build her own using an MCU. Instead of a pot, she might want to consider a rotary encoder, which would avoid the need for an ADC.
Yes.
 

TeeKay6

Joined Apr 20, 2019
573
I guess she needs a LED dimmer as the thread topic says. LTC3490 is boosting the 1.2V to 4V fixed @ 350mA. It cannot provide a variable duty PWM to control the brightness of the LEDs.

Maybe there are other dedicated LED dimmer chips.
@jayanthd
According to the portion of the LTC3490 datasheet posted by @Danko, the chip can indeed provide dimming via voltage on a control pin.

In the schematic you posted in post#66, what is the purpose of R3 & R4? Cannot the PWM output be directly connected to the MOSFET gate (and without voltage division)?
 
Last edited:

Thread Starter

Mellisa_K

Joined Apr 2, 2017
391
I guess she needs a LED dimmer as the thread topic says. LTC3490 is boosting the 1.2V to 4V fixed @ 350mA. It cannot provide a variable duty PWM to control the brightness of the LEDs.

Maybe there are other dedicated LED dimmer chips.
Please be aware that my comment eschewing a pot was only in the context of a voltage divider in a simple battery / LED circuit not in the context of controlling a PWM output
 

cmartinez

Joined Jan 17, 2007
8,799
So I did some searching for books that might help you get started with MCU programming, and I've got bad news and good news.

The bad news is that I couldn't find any book that I would deem as satisfactory for a newbie to start programming projects with. Most of the books I found either dealt with high-end architectures that were a bit too complicated for the neophyte, or that would nudge you into the nefarious Arduino world. My advice, whatever you do, is do NOT go down that path. IMHO, Arduinos are nothing but toys designed to draw curious crowds into the tent. They might actually teach you some pretty good programming techniques, but they will do almost nothing in terms of learning real electronics. They're like bottled baby Gerber food that is very hard to wean off once you start consuming it.

The good news is that there are a bunch of extremely capable guys in this place that are willing to go out of their way to help you out in your learning endeavor. What I suggest is that you start learning with simple 8 bit PIC MCU and then grow from there. Personally, I'm an expert in the 8051 architecture, but unfortunately that family of chips have been phased-out in the last couple of decades and, although I'm sure that support for them will stay steady for a long while still, I suggest you embrace the most recent products in the market.

For instance, here's the datasheet for a chip I've been learning to use for a year now. Have a look at page #148. It shows that this chip in particular has a very small, but powerful, instruction set. All you have to do to get started is get familiarized with its internal architecture, and study only 35 instructions. Trust me, it's not that hard, and it's very satisfying to watch your first led flash on and off after you've written and run your first program.
 

danadak

Joined Mar 10, 2018
4,057
Look at post # 5 here - https://forum.allaboutcircuits.com/...odulation-with-555-timer.162257/#post-1425728

Basically you learn by programing in a block language, the tool converts that to Arduino code.

Kids are using this to program robots, 6'th grade level on.

The project takes a V reading off a pot and converts that to PWM duty cycle.
You can then drive a low current, 20 mA ish kind of part, directly, or use a MOSFET
to drive a high power LED.

You can look at Arduino code generated to start getting a "feel" for C type language.

You can work with a Arduino Nano or Uno board, both cheap. There are videos on
web.

There are variants of block language, each with common blocks and also with unique
blocks. Like building a talking voltmeter trivial -

https://forum.allaboutcircuits.com/threads/talking-arduino.161537/#post-1413429

Lots of fun, videos on web on block languages and projects.

Take a look at this thread also on block variants -

https://forum.allaboutcircuits.com/threads/need-help-with-led-controller-ideas.162376/#post-1423288


Regards, Dana.
 

jpanhalt

Joined Jan 18, 2008
11,087
I feel this discussion is going to devolve into an Assembly v. C (and C derivatives) debate. I started with Assembly and stayed with it. It is a non-ending argument and not worth repeating. Since you have experience with SAS, which I barely was able to comprehend, you may want a higher level language.

As for which chip(s) to start with, if you start with C, it may not matter much, except for the initialization. If you start with Assembly, while I agree in principle with @cmartinez, I would recommend starting with the 12F or 16F enhanced midrange. They are available in DIP (one of your criteria) and have a lot of peripherals. Why not 10F3xx? There is really not much difference, except physical size, and since you want to use DIP's, then there is no advantage.
 

cmartinez

Joined Jan 17, 2007
8,799
Why not 10F3xx? There is really not much difference, except physical size, and since you want to use DIP's, then there is no advantage.
I'm with you on the matter of Assembly being a better starting point for learning programming. As for your remark regarding the 10F3XX, I'm not sure what you meant, unless you're not aware that that chip also sells in an 8-DIP package.

Then again, if the 12F or 16F series (I confess I'm not familiar with neither) are more popular, then yes, perhaps it would be a better platform to begin with, unless their instruction set is way too large for a noobie.
 

jayanthd

Joined Jul 4, 2015
945
In my circuit in #66 R3 should be 1k. The Mosfets that I have chosen are Logic Level Mosfets and can be driven by 3.3V or 5V Logic. R3 just limits the Gate current but I know that Mosfets are Voltage operated devices and not current operated devices like BJTs.

R4 is a pull-down to keep the Gate from floating if PWM pin gets damaged.
 

TeeKay6

Joined Apr 20, 2019
573
In my circuit in #66 R3 should be 1k. The Mosfets that I have chosen are Logic Level Mosfets and can be driven by 3.3V or 5V Logic. R3 just limits the Gate current but I know that Mosfets are Voltage operated devices and not current operated devices like BJTs.

R4 is a pull-down to keep the Gate from floating if PWM pin gets damaged.
@jayanthd
I was indeed misreading the value of R3, it is marked 10R (10Ω I believe), not 10K as I misread. Thanks for the correction.
 
Top