Dimming LED's with no PWM pins from uC

Discussion in 'Embedded Systems and Microcontrollers' started by artmaster547, Nov 17, 2017.

  1. artmaster547

    Thread Starter Member

    Jan 6, 2016
    393
    7
    Hi All
    I am looking for an IC/Circuit schematic, that enables control of two LED's allowing them to be dim in and out (i.e. create a "breathing effect"), but I do not have any spare PWM pins on the uC but it is possible to use GPIO pins, I2C pins or SPI pins can anybody recommend what I could use?
    Any recommendations would be greatly appreciated.

    Kind Regards

    Art
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    6,861
    3,010
    You can simply do bit bang PWM.

    https://www.arduino.cc/en/Tutorial/SecretsOfArduinoPWM

    Just one of many, many examples. You need to provide more detail for more specific help. The microchip used for one.

    This is probably one of the most simple projects you can do. It is one step up from the "Hello World" turn on an LED project that you usually cover when learning microcontrollers.

    And this should be in the embedded forum.
     
    JohnInTX likes this.
  3. artmaster547

    Thread Starter Member

    Jan 6, 2016
    393
    7
    Hi the micro controller I am using is an LPC11c12, I know it's really simple with Arduino because a lot of libraries have already been written but I have not really tried to do anything from scratch so any assistance would be appreciated.
     
  4. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    6,861
    3,010

    This isn't that difficult of a project. You don't need a library aside from a delay. And if that does not exist then just write one.

    Why don't you first try reading the article and see how it is going to apply to your chip? This is probably one of the most basic of projects.



    Likely one one is gong to write code for you, especially for such an odd mcu.
     
  5. artmaster547

    Thread Starter Member

    Jan 6, 2016
    393
    7
    could you write the pseudo code by any chance the main thing is figuring out the timings for on and off I understand how to toggle the LED it's just figuring out the timings that seems to be the issue and the period of when it is on to get it to dim, tbh I understand how to add in delays and so on
     
  6. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    6,861
    3,010
    Start:

    Turn LED On
    Delay
    Turn LED off
    Delay

    Add to Delay
    If delay limit is reached reset delay

    Goto to start

    You will just need to experiment with the length of delay and how much it increases to see what looks good.
     
  7. artmaster547

    Thread Starter Member

    Jan 6, 2016
    393
    7
    Ok great thank you I see you just increment the delay in a loop that makes sense

    Thanks

    Art
     
  8. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    6,861
    3,010
    And you might want to decrease it too. Example increase in steps till delay reaches a certain high limit then decrease in steps till it is decreased to a certain low limit.

    You could also have a counter for how often it is increased or decreased.

    Turn LED On
    Delay
    Turn LED off
    Delay

    Add 1 to StepCount

    If StepCount > 10
    StepCount = 0
    Add to Delay
    If delay limit is reached reset delay
    Endif

    Goto to start


    This will slow the rate of growth.
     
  9. artmaster547

    Thread Starter Member

    Jan 6, 2016
    393
    7
    Great thank you appreciate the assistance I will play around with this thanks Art
     
Loading...