
Originally Posted by
markedwards
Hi Mengckid,
You did't mention which PIC you were using or what application.
Here is code that I use with hardware pwm (HPWM).
My application requires 5 speeds and a 60% minimum speed setting.
You can add more comparisons or calculate speed settings based on AD1.
There are 2 lines that control acceleration & de-acceleration
I like the hardware pwm best, it runs consistent speed
while your program executes other code. It will work with PWM if you change the last line.
ADCIN 1,AD1 'read channel 1...AN1
AD1 = AD1 >> 6 'justify data
ADJUSTFAN:
IF AD1 < 2 then FANSPEED = 153 '60% min speed
IF AD1 >= 3 then SPEED = 178 '70%
IF AD1 >= 5 then SPEED = 204 '80%
IF AD1 >= 7 then SPEED = 229 '90%
IF AD1 >= 9 then SPEED = 255 '100%
IF SPEED > SPD THEN SPD = SPD + 1 'accelerate
IF SPEED < SPD THEN SPD = SPD - 1 'de-accelerate
hpwm 2,SPD,32760 ' PWM 20,000 Hz
Mark
Bookmarks