KhaledOsmani
Full Member level 6
80mS is overkill, most switches will settle in <10mS but how long is needed in the program depends on when the switch is next checked. The debounce is only important if there is a risk of the the input being read more rapidly than the contacts settle and it being seen as in the wrong state during the bounce period.
Khaled, look at table 19-2 on the data sheet, it tells you the bits you have to set in ADCON1 to make the pins analog or digital. They default to analog when the PIC is reset for safety reasons.
Brian.
Hello Brian and thank you!
What I intend to is having the response of the system as fast as it can be achieved whenever the user has pressed the push button.
If user presses push then directly go to the destined loop
here is the code:
Code:
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "Press Red Button"
Lcdcmdout LcdLine2Home
Lcdout "To Continue"
If PORTD.3 = 1 Then //I've added so many fragments of this code, because i want the system to react directly when the user presses the red push button. If I don't do this perhaps the user presses the push button but the system ignores it because it hasn't seen it yet
Goto capbankcalc
Else
WaitMs 1400
If PORTD.3 = 1 Then //same reason
Goto capbankcalc
Endif
Lcdcmdout LcdClear
Lcdcmdout LcdLine1Home
Lcdout "Vinput: ", #x, "V"
If PORTD.3 = 1 Then //same reason
Goto capbankcalc
Endif
Lcdcmdout LcdLine2Home
Lcdout "I(load)= ", #allcurrent, "A"
Lcdcmdout LcdLine3Home
Lcdout "Power: ", #pow, "W"
If PORTD.3 = 1 Then
Goto capbankcalc
Endif
Lcdcmdout LcdLine4Home
Lcdout "pf: ", #pf
If PORTD.3 = 1 Then
Goto capbankcalc
Endif
WaitMs 1000
If PORTD.3 = 1 Then //same reason
Goto capbankcalc
Else
Goto here
Endif
Endif
capbankcalc:
Lcdcmdout LcdClear
Lcdout "The input pf"
Lcdcmdout LcdLine2Home
Lcdout "is: ", #pf
If pf > 0.85 Then
Lcdcmdout LcdLine3Home
Lcdout "pf is optimal"
WaitMs 1000
Goto prog_end
Else
Lcdcmdout LcdLine3Home
Lcdout "Correcting..."
WaitMs 1000
Endif
//to be continued later
prog_end:
End
Perhaps this problem can be solved by making an ISR for the pushbutton?? Whenever pressed directly go to the desired loop, but what I fear of is what if the user presses this button at the beginning of the program, but can this be solved by marking a flag at almost the end of code such that even if the user pressed it, before a flag is marked 1 for example no ISR routine will make effect because its if/else condition were not satisfied?