View Full Version : HPWM question
sjmusic2
- 18th May 2009, 20:01
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.
mister_e
- 18th May 2009, 20:27
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
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.
sjmusic2
- 18th May 2009, 20:42
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
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
Acetronics2
- 19th May 2009, 08:46
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
Bruce
- 19th May 2009, 17:03
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.
sjmusic2
- 20th May 2009, 19:50
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.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.