LED intensity adjustable

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
Hi all!

Please assist in the following:

Assume you have a set of LEDs (example 3) that turns on/ off via a pushbutton...

Now, suppose you want to control/adjust the intensity of this set using 2 pushbuttons (up and down) connected to two I/O pins!

My question are:
- what is the simplest theory/approach/ or method to use in order to acheive the above?
- Also how would u go for setting up the level of brightness?

I tried searching/reading similar problem form past threads but did not get much info...

Any comment would be really appreciated

Eric007
 

steveb

Joined Jul 3, 2008
2,436
Hi all!

Please assist in the following:

Assume you have a set of LEDs (example 3) that turns on/ off via a pushbutton...

Now, suppose you want to control/adjust the intensity of this set using 2 pushbuttons (up and down) connected to two I/O pins!

My question are:
- what is the simplest theory/approach/ or method to use in order to acheive the above?
- Also how would u go for setting up the level of brightness?

I tried searching/reading similar problem form past threads but did not get much info...

Any comment would be really appreciated

Eric007
The two common ways to adjust brightness are to use current control CC or pulse-width-modulation. It really depends on the application which is better to use. The method of using the pushbuttons to control the brightness also depends on what type of hardware you have, or are willing to use. Do you have a microprocessor in the system? If so, many of those have timers and PWM outputs available for a simple implementation. It could also be done with digital circuitry, or even analog circuits (in the old days).
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
@steveb: I'm using PIC16F690, breadboard, assembly language...
Can u please explain one of the 3 methods u mentioned? Like digital circuitry!

I'm new wit PIC microcontroller...any simple implementation? Please explain...
 

steveb

Joined Jul 3, 2008
2,436
@steveb: I'm using PIC16F690, breadboard, assembly language...
Can u please explain one of the 3 methods u mentioned? Like digital circuitry!

I'm new wit PIC microcontroller...any simple implementation? Please explain...
I'm not familiar with the PIC line, and there are many people here that can give you specific information about that particular chip and breadboard.

However generally speaking, you can wire up your pushbutton switches to be digital inputs to digital input lines on your processor. Then the next question is whether you have a PWM output line directly from the PIC. If so, this can go directly to a simple on/off control for an LED driver. The pushbuttons can control an up/down counter in your program and the duty cycle of the PWM can be set based on the counter value.

If you don't have a PWM output, you can easily program one up by doing bit-banging on any digital output line. So, it's simple programming and simple interfacing to a simple LED driver, if you do it that way.

Note that the PWM frequency must be fast enough so the eye does not see any flickering.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
The PIC I'm using have the PWM feature...but I'm still learning about PIC and not familiar with all the PIC feature yet...and I'm running outa time to make this work...

I would really appreciate it if u could explain ur last approach...I mean the logic behind it
and the interface...I'll code it myself...all I need is the reosoning...

Thanks Steveb
 

steveb

Joined Jul 3, 2008
2,436
The PIC I'm using have the PWM feature...but I'm still learning about PIC and not familiar with all the PIC feature yet...and I'm running outa time to make this work...

I would really appreciate it if u could explain ur last approach...I mean the logic behind it
and the interface...I'll code it myself...all I need is the reosoning...

Thanks Steveb
The logic behind bit banging is to do things as crudely as possible, which I don't recommend in general. However, if your processor doesn't need to do too many things anyway, then there is no reason to not do it, if it saves you time. Basically you can run a loop of NOPs (no operation commands) to do the timing on the PWM output. You simply determine when to turn your digital output line high and low with a crude timer you make out of a programming loop. You can also do the timing with the built in timers and interrupts, but that is more involved. The benefit is that it frees up your processing power and time to do other things. However, if you have a PWM output pin already built in, it's worth putting the time in to learn how to use it because it's going to do most of the work for you.
 

MrChips

Joined Oct 2, 2009
30,708
There seems to be a common pattern of newbies tackling what appears to be homework questions. Many sound solutions are provided but the op fails to follow through with trying out and the learning the concepts thoroughly, because the assignment is due tomorrow. Missed opportunity to learn. That's too bad.

BTW. PWM is a sound solution for dimming LEDs. And you do not require PWM features in the micro.
 

Thread Starter

Eric007

Joined Aug 5, 2011
1,158
@MrChips: u talking about missed "opportunity to learn... U might not be wrong BUT I REALLY LOVE PIC progrmming...and I'm all excited about learning errthing about PIC but for Now time not really on my side...

Even if I don't make it work it not a big deal...but soon or later I'll post here how one can make some LEDs intensity adjustable with different method...

I LOVE this forum!!! And will probably be here until I die...coz I wana know errthing and also get to a stage where I can now help other people with their problems!!!

@Steveb: Thanks again......
 
Well at least show up with something, like an interesting blinky program. The PICkit 2 programmer page at Microchip has some code to borrow for the 16f690, since it comes with the PICkit 2 starter kit.

Go there and download the PICkit 2 Starter Kit Lessons. There you will find asm lessons on the blinky led, get that going first. The led blinky is always the first thing to do, even for experienced users, so as to verify the programming, oscillator, configuration setup, etc. Have you got the led to blink???

Next, try the button debounce routine, which changes a variable based on button presses. This is one half of the ultimate solution. The variable "Display" can be used to increment the PWM duty cycle register CCPR1L.

Finally go to the Pic16f690 data sheet and look up chapter 11.3.7, it gives a step by step in on how to set up the PWM module. Add the initializing code of the PWM to the debounce routine. Instead of moving the Display variable to PortC, change it to CCPR1L, and you should have a button changing PWM.

Showing up with some meaningful code, and thoughtful questions, will beget more help.

EDIT: Of course the PWM would be on the CCP1 (RC5) pin now. Verify the frequency and duty cycle with a scope or meter if need be.
 
Last edited:
@MrChips: u talking about missed "opportunity to learn... U might not be wrong BUT I REALLY LOVE PIC progrmming...and I'm all excited about learning errthing about PIC but for Now time not really on my side...

@Steveb: Thanks again......
It can be quite amazing what you can get a pic to do.
I was a PIC consultant for 13 years and used from everything from wash/wipe systems for cars to using fast fourier transforms for processing vibrations.
Also did a state of the art cooker with a huge vacuum fluorescent display that used multi tasking software to control multiple ovens.
 
Top