LED intensity adjustable

Discussion in 'Embedded Systems and Microcontrollers' started by Eric007, Aug 26, 2011.

  1. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    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
     
  2. steveb

    Senior Member

    Jul 3, 2008
    2,433
    469
    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).
     
  3. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    @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...
     
  4. steveb

    Senior Member

    Jul 3, 2008
    2,433
    469
    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.
     
  5. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    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
     
  6. elec_mech

    Senior Member

    Nov 12, 2008
    1,513
    193
    Hi Eric007,

    There is someone else currently trying to do something similar here:

    http://forum.allaboutcircuits.com/showthread.php?t=58194&page=2

    Read posts #11 and #14. #11 gives you an idea on using the PIC to generate a PWM signal. #14 shows you how to connect from the PIC to the LEDs depending on the number and current draw.
     
  7. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    Thanks Elec mech!!!!
     
  8. steveb

    Senior Member

    Jul 3, 2008
    2,433
    469
    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.
     
  9. MrChips

    Moderator

    Oct 2, 2009
    12,432
    3,360
    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.
     
  10. Eric007

    Thread Starter Senior Member

    Aug 5, 2011
    1,044
    33
    @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......
     
  11. nickelflipper

    Active Member

    Jun 2, 2010
    280
    35
    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: Aug 27, 2011
  12. nigelwright7557

    Senior Member

    May 10, 2008
    487
    71
    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.
     
Loading...