Ladies and Gents,
I'm trying to use a 12F683 to control a fan motor. I want to be able to push a button and have the fan cycle through speeds from off to high in 3 steps.
The problem is I can't figure out how to use PWM indefinitely.
This is my program. I've got the push button on GPIO.3 and the fan currently on GPIO.5. It works kinda but the selected speed only lasts for the length of time PWM is set. During that time you can't select another speed.
Your thoughts would be appreciated.
clear
define osc 4
@ device mclr_off 'the input will be through GPIO.3
ansel = 0 'all ports digital
cmcon0 = 7 'turn off comparators
adcon0 = 0
touchnumber var byte 'count the number of touches
outTOfan var gpio.5 'LED symbolizing fan speed
trisio = %001111
touchnumber = 0
starthere:
outtofan = 0
If gpio.3 = 1 then goto main
goto starthere
main:
touchnumber = touchnumber + 1
if touchnumber =4 then touchnumber = 0
select case touchnumber
case 0
gpio.5 = 0
case 1
pwm gpio.5, 60,1000
case 2
pwm gpio.5,150, 1000
case 3
pwm gpio.5, 255, 1000
end select
goto starthere
end
Bookmarks