PDA

View Full Version : pulsin fails in real world



peu
- 5th March 2005, 21:39
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

mister_e
- 6th March 2005, 10:32
i didn't check your whole code but, have you try with a pulse generator instead of the switches?? if so, what are the results?

did you use a scope to see PWM and Switches signal. What about your supply line (again and again)