Hello,
I am new to this NG, but my question seemed more appropriate here than on SED.
I'm using a PIC18F242 for an SCR controller, and programming it in assembly with MPLAB 7.30. I am using RA4 as an Output On indicator, driving an LED and an optoisolator through a series resistor to +5VDC. I use RA5 to drive a status LED, low for green and high for red.
Everything worked fine when I had the target board connected to a prototype test setup, but when it was installed in a piece of equipment, the Output On indicator would latch on sometimes, but would then sometimes work OK when the output was turned on and off, so it was not a latch-up of the device. RA4 was being driven low (or not driven high) in software. I found a few places in my code that could possibly be a loop where the state of RA4 might not be set high, but I cleaned it up so there was no longer any possibility, and yet the light still latched on.
I spent hours trying to find the problem, and sometimes I could get it to latch up on my test board, but it was always worse in the actual unit where it was to be installed. I tried removing the 480 VAC supply to the SCRs, and also powered the board from external 120 VAC power, but the problem persisted. I also added electrical and software filtering to the initiate input line, to no avail.
Finally, I decided to implement a debug version of code that used the RA5 indicator as a gauge for ISR overhead, setting it at the interrupt and resetting at exit. I could see that the overhead was OK, on the bench. I put it in the unit, and also saw no excessive overhead. But the crazy thing is that now the Output On indicator worked perfectly!
So, I just set a flag in a file variable in main line code where I wanted to set or reset the Status LED, and added a check in the ISR to actually drive the RA5 line. The Output On indicator was still driven as it had been in the main code loop.
It works now, but I don't know why. I did not see anything special about RA4, except that it is open drain and can be connected to a timer. RA5 seems to be quite ordinary. I am using RA3 as an analog input. I configure PORTA:
movlw B'11001011' ;RA output movwf TRISA ;W=>TRISA
Any ideas will be most appreciated. I may make a service ticket to Microchip unless anyone can point out a cause for this. I may upgrade to a PIC18F2420, which is similar and recommended for new designs. Maybe there is a flaw in the 242?
Thanks,
Paul E. Schoen