I have this program for pic 12F683, I resumed the program for the relevant parts (of course all variables are properly defined):
@ device INTRC_OSC_NOCLKOUT
DEFINE OSC 4
DEFINE PULSIN_MAX 65535
ansel=0
trisio=%00100000
pulso VAR WORD
boton VAR GPIO.5
LED VAR GPIO.2
pwmduty VAR BYTE[7] '
pwmduty[0]= 16
pwmduty[1]= 32
pwmduty[2]= 64
pwmduty[3]= 127
pwmduty[4]= 150
pwmduty[5]= 192
pwmduty[6]= 255
prendido=0
pwmstat=6
frecu=250
testigo=0
LOOP:
tdp=2
PulsIn boton, 0, pulso
Pause 10
IF pulso >0 Then
IF pulso > 20000 Then
TDP=3
Else
tdp=1
EndIF
EndIF
Select Case tdp
Case 1
IF prendido =1 Then
prendido =0
HPwm 1,0,frecu
Else
prendido=1
HPwm 1,pwmduty[pwmstat],frecu
EndIF
Case 3
GoSub spwm
End Select
tdp=2
GoTo loop
the program is the main loop for a multilevel light, the subroutine sets the pwm duty cycle.
well it simulates ok, but in the real world, the circuit behaves totally erratic
Im guess the problem is in the switch, but I'm completelly lost. Or maybe the Hardware PWM is not working ok?
What can I do?
thanks in advance
Bookmarks