HPWM question


Closed Thread
Results 1 to 6 of 6

Thread: HPWM question

  1. #1
    Join Date
    May 2009
    Posts
    3

    Default HPWM question

    I am trying to write a program for my aquarium to control a 'sunrise' effect for high power LED lights. I am good with the driver side of the circuit but need a little help with the pic pwm signal.

    I have read about the HPWM function in PBP, but don't really understand how to set up the configuration. I have a 16F887 (with 4 channels) and want to use something like...

    DutyCycle var byte
    TRISD= $00000000 ' for P1B output pin, or TRISC if P1A

    For DutyCycle=0 to 255
    HPWM 1,DutyCycle,1250
    Pause 15000
    DutyCycle=DutyCycle+1
    Next

    End

    Will this produce a gradual increase in perceived brightness up to the max after around an hour, then maintain the max output until power is turned off ?

    Are all declarations made ?

    Is it possible to use a different output channel, ie. P1B instead of P1A, how would this be coded ?

    Thanks.

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    The best way to know is to try, that for sure

    Your code would work... but you're not going to have a 60 minutes ramp up but ~32 minutes instead. Remove the
    Code:
    DutyCycle=DutyCycle+1
    line and you'll have a 64 minutes ramp-up.

    Wanna make sure the PIN stay high? No big deal,

    CCP1CON=0
    HIGH PORTC.2

    And nope, you can't use an alternative PIN alone, check the datasheet under CCP1CON section (pdf p126) & Enhanced Mode p134.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    May 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mister_e View Post
    The best way to know is to try, that for sure

    Your code would work... but you're not going to have a 60 minutes ramp up but ~32 minutes instead. Remove the
    Code:
    DutyCycle=DutyCycle+1
    line and you'll have a 64 minutes ramp-up.

    Wanna make sure the PIN stay high? No big deal,

    CCP1CON=0
    HIGH PORTC.2

    And nope, you can't use an alternative PIN alone, check the datasheet under CCP1CON section (pdf p126) & Enhanced Mode p134.
    Thanks for the quick reply, so is this the right placing of your suggested code...

    DutyCycle var byte
    CCP1CON=0
    TRISC= $00000000

    For DutyCycle=0 to 255
    HPWM 1,DutyCycle,1250
    Pause 15000
    Next

    HIGH PORTC.2

    End

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Wink

    Hi, SJ

    The light changes are perceived in an exponential evolution ...

    1,2,4,8,16 ... etc

    so, just multiply the Dutycycle per 2 for each loop instead of adding 1 ...

    May be you'll have to use little trickery to increase the allowable steps number. i.e use LONGs and scale them down to 8 or 10 bits ( HPWM10 from Darrel's goodies ! )


    the changes will then be smoother ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Have a look at Darrels' MIBAM code;
    http://www.picbasic.co.uk/forum/showthread.php?t=10564

    This will give you a very smooth fade in/out effect, and it's easy to use.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    May 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default

    Guys, thanks for the replies - I now have my 16F887 pwm ramping an led just the way I want it !!

    A follow-up question...

    Keeping in mind this is for an aquarium, I would like to be able to have the pwm start at a specific time every morning and turn off at a specific time at night (probably with a ramp-down, prior to shutdown). The timer on/off times will be coded in the program (and not require external input).

    I have read close on 20 different timer-related threads and I'm struggling to see how you can have a timer running concurrently with the pwm code.

    Any help, much appreciated.

Similar Threads

  1. Multiple HPWM question
    By Johan in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th October 2007, 13:00
  2. sound command & music
    By trying in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 26th May 2006, 14:14
  3. HPWM and A to D interaction question 18F252
    By tcbcats in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 10th May 2006, 03:50
  4. 3 HPWM channels
    By docwisdom in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 4th April 2006, 02:43
  5. HPWM question
    By Squibcakes in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 24th June 2004, 23:27

Members who have read this thread : 1

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