Thanks Dave, I see now that I made a terrible mistake when typing in the example, the Accumulator gets reset when RunServo is 0 and not when FaultInput is 1, this is of course wrong. That, however, is not the case in my real system. Here's the exact code, cut and pasted from my program:This works fine now that I've changed the diode so the voltage at the pin is within specs. If I change it back to the 1N4148 it does not work, the input is not seen. But WHY does it see it before, when the checking of the input was outside the IF RunPID THEN construct? Here's how it looked before which has worked fine for years:Code:If ServoFault = 1 then Goto OverRunPID 'General fault flag set - don't run servo loop. '------------------------------------------------------------------------------- If RunPID then 'Time to run the servo-loop? '----------------------------- Added 2011-06-03 ----------------------------------- If ip_Fault_Input = 0 THEN 'External fault input is "active" FaultFilterAccumulator = FaultFilterAccumulator + 1 'If so we increment the accumulator for the filter If FaultFilterAccumulator = FaultFilterConstant THEN 'Have we reached the filter limit? ExternalFault = 1 'Set the FAULT Flag BlinkPattern = Pattern_Ext_Fault 'Change the pattern for the status LED GOSUB AbortServo 'Abort the servo loop. ENDIF ELSE FaultFilterAccumulator = 0 ENDIF '---------------------------------------------------------------------------------- op_LED = 1 'Drive LED on the module. GOSUB DoServo 'Rune the servo loop RunPid = 0 'Clear flag op_LED = 0 'Turn off LED on the module. ENDIF OverRunPid:If I run this version, with the original diode in place it works just fine and both versions above works now that the voltage level on the pin is within specs. But why does one work and not the other when the voltage is slightly out of spec? I wouldn't be surprised if neither worked but the original code have worked, with the original hardware, "for years".Code:If ip_Fault_Input = 0 THEN 'External fault input is "active" ExternalFault = 1 'Set software flag indicating fault BlinkPattern = Pattern_Ext_Fault 'Select the "blink pattern" for the FW-LED GOSUB AbortServo 'Abort servo operation. ENDIF If ServoFault = 1 then Goto OverRunPID 'General fault flag set - don't run servo loop. '------------------------------------------------------------------------------- If RunPID then 'Time to run the servo-loop? PortA.0 = 1 'Drive LED on the module. GOSUB DoServo 'Rune the servo loop RunPid = 0 'Clear flag PortA.0 = 0 'Turn off LED on the module. ENDIF '------------------------------------------------------------------------------- OverRunPID:
The only thing I can think of is that previously the input could get checked tens of thousand of times per second depending on what else was done thru the main loop. Perhaps some capacitive coupling or whatever made the voltage go down to within specs for a short time making the PIC pick it up. But now, when it's "only" checked 1500 times per second that isn't working any more....I don't know...
/Henrik.
Bookmarks