How to make an LED gradually and slowly get brighter and dimmer?


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: How to make an LED gradually and slowly get brighter and dimmer?

    Oh, for crying out loud, this was discussed in detail in the other thread. When you use HPWM you ARE using the CCP module. The frequency of the PWM signal has nothing to do with how fast or slow you fade the LED - as was discussed previously.

    The example posted by mark_s does exactly what you ask for, can't you at least try that.

    And PAUSE doesn't affect HPWM since HPWM uses the CCP module, ie it generates the PWM signal in hardware so in this case it does exactly what was asked.

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: How to make an LED gradually and slowly get brighter and dimmer?

    Quote Originally Posted by HenrikOlsson View Post
    Oh, for crying out loud, this was discussed in detail in the other thread. When you use HPWM you ARE using the CCP module. The frequency of the PWM signal has nothing to do with how fast or slow you fade the LED - as was discussed previously.

    The example posted by mark_s does exactly what you ask for, can't you at least try that.
    Having a bad groundhog day Henrik ? :-)

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: How to make an LED gradually and slowly get brighter and dimmer?

    Ah, not really but please accept my apologies.

    I just don't understand what the problem here, the issue was discussed in depth in the other thread but apparently there's some detail that doesn't make sense - and that's fine - but instead of asking about that detail we get a new thread with the same topic.

    And, regarding PAUSE, you're of course 100% correct with that comment but it doesn't really pertain to the HPWM command and may just make thing more confusing.

    Anyway, I'm sorry for being harsh, not my intention, shame on me.

    /Henrik.

  4. #4


    Did you find this post helpful? Yes | No

    Default Re: How to make an LED gradually and slowly get brighter and dimmer?

    Yup, for sure HPWM is the way to go unless you've already used those pins up, in which case you can go SPWM, but that chews up processing time. HPWM isn't "slow or fast" like Henrik says, you just change your duty cycle as quickly or slowly as you want to, you can test it with a pause loop, and then implement via a timed interrupt routine (which obviously has less overhead).

  5. #5


    Did you find this post helpful? Yes | No

    Default Re: How to make an LED gradually and slowly get brighter and dimmer?

    Quote Originally Posted by HenrikOlsson View Post
    Oh, for crying out loud, this was discussed in detail in the other thread. When you use HPWM you ARE using the CCP module. The frequency of the PWM signal has nothing to do with how fast or slow you fade the LED - as was discussed previously.

    The example posted by mark_s does exactly what you ask for, can't you at least try that.

    And PAUSE doesn't affect HPWM since HPWM uses the CCP module, ie it generates the PWM signal in hardware so in this case it does exactly what was asked.
    I started a new thread because I didn't really get anything that helped me last time, and I thought that was because I wasn't asking my questions correctly. There seemed to be some confusion about what I was trying to do, so rather than possible cause more confusion, I thought it was best to try again with a new thread and ask my question in a different way.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,653


    Did you find this post helpful? Yes | No

    Default Re: How to make an LED gradually and slowly get brighter and dimmer?

    The first problem is that I'm using a 16F886 and I can't seem to get this code to work with it. I've done some reconfiguring, and PBP will compile it for the 16F886, but I get an error message when I actually try to program the chip, so I'm clearly not doing something correctly.
    firstly there is not much point reposting my code , you need to post what you are using , my example is for a pic16f1825
    for a 16f886 things will be different
    osc is different, ccp1 and 2 pins are different , ansel settings are different, config word is different tris ..........


    Also, I really don't fully understand what is going on. I understand what the code is doing, but I don't understand the CCP module well enough to understand what setpwm is doing. Although the line "while pl" doesn't make any sense to me. Doesn't there need to be some sort of statement like "while pl < 99"?
    in nearly all computer languages false=0 anything else is true

    so "while pl" means while pl is true ie anything but 0


    CCPR1L = PW>>2;
    ccp1con=12|((PW&3)<<4); led2

    CCPR2L = Pl2>>2; led1
    ccp2con=12|((Pl2&3)<<4);
    10 bit pwm is high 8 bits =CPRxL , LOW 2 bits = CCPxCON bits 4,5

    so our 10 bit pwm value "PW" is deconstructed CCPR1L = PW>>2 moves high 8 bits into CCPR1L

    and with [ccp1con=12|((PW&3)<<4)] the low two bits "PW&3" are shifted to bit 4,5 posn and or(ed) into ccp1con
    Warning I'm not a teacher

Similar Threads

  1. my project Capacitive Sensing LED dimmer 12F1822 via PWM
    By Heckler in forum mel PIC BASIC Pro
    Replies: 42
    Last Post: - 12th May 2016, 07:48
  2. LED Dimmer
    By Ioannis in forum Off Topic
    Replies: 4
    Last Post: - 2nd December 2013, 09:33
  3. LED Dimmer - What should be used for Switching?
    By FromTheCockpit in forum Schematics
    Replies: 11
    Last Post: - 4th November 2012, 00:31
  4. How to move servo slowly?
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 15th April 2009, 13:50
  5. I can't even make an LED flash!
    By George in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 3rd April 2007, 06:39

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts