Hi,
I just had weird problem that I can't really explain, hopefully someone else here can.
Basically I have an 18F2431 device. One of it's pin is used as an fault-input normally pulled high thru 4.7k and then two active LOW signal are OR'd thru diodes to this pin.
In my Main loop I had this (basically):
RunServo is a flag that gets set by a timer interrupt, currently at 1.5kHz.Code:Main: If Fault_Input = 0 THEN Fault_Flag = 1 GOSUB Abort EndIf If FaultFlag = 0 THEN If RunServo = 1 THEN GOSUB DoServo ENDIF Goto Main
This has worked fine for a very long time but a user has a problem where I suspect electrical noice is tripping the fault input. Therefor I thought I'd implement a simple filter and did this:Again, this is not exactly how it's done but the principle is the same.Code:Main: If RunServo = 1 THEN If FaultInput = 0 THEN Accumumlator = Accumulator + 1 If Accumulator = Limit THEN FaultFlag = 1 GOSUB Abort EndIf ELSE Accumulator = 0 EndIf If FaultFlag = 0 THEN GOSUB DoServo ENDIF Goto Main
To my surprise this didn't work. Well, it worked when the fault was triggered by one of the two OR'd signals but not by the other. The one that worked has a simple switch to GND making the voltage at the pin one diode drop (~0.6V). But the other input have a transistor (optoisolator output) as its "switch" to GND and there was about 0.55V voltage drop across that for a total "low" voltage at the pin of 1.15V.
This 1.15V is above the logic low thershold of the input which at Vdd=5V is about 0.75V. I fixed the problem by changing the diode to a schotky type with lower forward voltage drop and it now seems to be OK.
The big question I can't find the answer to is how and why it has worked before adding the filter code (there's been ano problem at all that I know of...). It doesn't matter if I set Limit to 1 which should make it trip the first time it sees the signal. The only difference with that is that it won't get checked untill the RunServo flag is set which happens 1500 times/second.
Anyone's got any ideas on what is happening here, it's clear that I was operating outside the electical specs but why does it matter WHERE in the code I actually check the input?
Thanks guys!
/Henrik.
Bookmarks