helmut
- 27th August 2007, 12:08
hi everyone here
i need some help on hpwm
my code is as below:
DEFINE OSC 4
DEFINE CCP1_REG PORTC
DEFINE CCP1_BIT 2
DEFINE CCP2_REG PORTC
DEFINE CCP2_BIT 1
trisb = %11111111
trisc = %00000000
CCP1CON = %00001100
CCP2CON = %00001100
T2CON = %00000100
i var byte
a var byte
L VAR BYTE
M VAR BYTE
main:
L = 0
m = 80
hpwm 1,0,1000
hpwm 2,0,1000
if portb.0 == 1 then
pause 1000
goto LED
endif
goto main
end
LED:
IF PORTB.1 == 1 THEN
pause 500
gosub ledincrease
endif
if portb.2 == 1 then
pause 500
gosub leddecrease
endif
if portb.0 == 1 then
pause 1000
goto motor
else
goto LED
endif
MOTOR:
if portb.1 == 1 then
pause 500
gosub motorincrease
endif
if portb.2 == 1 then
pause 500
gosub motordecrease
endif
if portb.0 == 1 then
pause 1000
goto led
else
goto motor
endif
ledincrease:
L = L + 16
IF (L < 255) THEN
HPWM 1,L,1000
else
if (l >= 255) then
L = 255
hpwm 1,L,1000
endif
endif
return
leddecrease:
L = L - 16
if (l > 0) then
hpwm 1,l,1000
else
if (l <= 0) then
L = 0
hpwm 1,L,1000
endif
endif
return
motorincrease:
m = m + 11
IF (m < 255) THEN
HPWM 2,m,1000
else
if (m >= 255) then
M = 255
hpwm 2,M,1000
endif
endif
return
motordecrease:
m = m - 11
if (m > 0) then
hpwm 2,m,1000
else
if (m <= 0) then
M = 0
hpwm 2,M,1000
endif
endif
return
this program is used to control intensity of 2 application - led or motor
when i high portb.1, the hpwm will increase
and when i high portb.2, the hpwm will decrease.
the problems i face is the hpwm will go from 100% to 0% when i further HIGH portb.1
i wish the hpwm will stop at 100% until i decrease it.
thank for your help~
i need some help on hpwm
my code is as below:
DEFINE OSC 4
DEFINE CCP1_REG PORTC
DEFINE CCP1_BIT 2
DEFINE CCP2_REG PORTC
DEFINE CCP2_BIT 1
trisb = %11111111
trisc = %00000000
CCP1CON = %00001100
CCP2CON = %00001100
T2CON = %00000100
i var byte
a var byte
L VAR BYTE
M VAR BYTE
main:
L = 0
m = 80
hpwm 1,0,1000
hpwm 2,0,1000
if portb.0 == 1 then
pause 1000
goto LED
endif
goto main
end
LED:
IF PORTB.1 == 1 THEN
pause 500
gosub ledincrease
endif
if portb.2 == 1 then
pause 500
gosub leddecrease
endif
if portb.0 == 1 then
pause 1000
goto motor
else
goto LED
endif
MOTOR:
if portb.1 == 1 then
pause 500
gosub motorincrease
endif
if portb.2 == 1 then
pause 500
gosub motordecrease
endif
if portb.0 == 1 then
pause 1000
goto led
else
goto motor
endif
ledincrease:
L = L + 16
IF (L < 255) THEN
HPWM 1,L,1000
else
if (l >= 255) then
L = 255
hpwm 1,L,1000
endif
endif
return
leddecrease:
L = L - 16
if (l > 0) then
hpwm 1,l,1000
else
if (l <= 0) then
L = 0
hpwm 1,L,1000
endif
endif
return
motorincrease:
m = m + 11
IF (m < 255) THEN
HPWM 2,m,1000
else
if (m >= 255) then
M = 255
hpwm 2,M,1000
endif
endif
return
motordecrease:
m = m - 11
if (m > 0) then
hpwm 2,m,1000
else
if (m <= 0) then
M = 0
hpwm 2,M,1000
endif
endif
return
this program is used to control intensity of 2 application - led or motor
when i high portb.1, the hpwm will increase
and when i high portb.2, the hpwm will decrease.
the problems i face is the hpwm will go from 100% to 0% when i further HIGH portb.1
i wish the hpwm will stop at 100% until i decrease it.
thank for your help~