16F877A won't keep relay on 100% of the time
I have a relay with 5V on one side of the relay's coil and the collector of a darlington transistor on the other side. I have a diode reverse-biased across the coil. I am using a 16F877A with PORTB as inputs (active low) with weak pull-ups enabled. On B0 I monitor whether a 12kHz square wave is present. The square wave is a good 5V-0V. If B0 has a 12kHz signal, I make A2 high, which is connected to the base of the darlington. This allows the relay's coil to find ground through the transistor and turn on.
However, although the relay turns on with the 12kHz signal present, every second for a split second the relay turns off and then back on and so on and so on. When a put a digital probe on A2 during this on-off cycle, the pin mimics the on-off cycle of the relay with a high-low cycle.
Is the problem with my code? If not, any suggestions?
MAIN:
COUNT PORTB.0, 1, Counter
IF (Counter >= 11) AND (Counter <=13) THEN
PORTA.2 = 1
ELSE
PORTA.2 = 0
GOTO MAIN
ENDIF
. . .
I forgot to answer the Watch Dog Timer question
I have this assembler code at the start of my program:
@ DEVICE HS_OSC, WDT_OFF, LVP_OFF, BOD_OFF, PWRT_ON, PROTECT_OFF
The "HS_OSC" is my change because I have a 20Mhz xtal, and yes, I have "OSC 20" in my "PIC Basic" code. The other line items are "Boiler Plate" I've found looking around the Forum. I'm quite certain the "WDT_OFF" turns the Timer off.
Sorry, but I did get some CCP and interrupt study
When I use a 12kHz TTL signal from my Function Generator, the relay works fine. However, when I use the 12kHz signal from Mach3, I get the spastic relay. I scoped the Mach3 signal after passing through the transceiver, it appeared to be a good 12kHz 5V to 0V signal.
I am going to run the Function Generator signal through the parallel port as if it's Mach3's, and thereby through the tri-state transceiver. I'm narrowing it down and will find it.
Thanks for letting me vent.
Can someone explain this to me
Function Generator 12.1kHz TTL 3V signal directly on B0 and the relay works great. Ditto when the Generator's signal is run through PC parallel port input and tri-state transceiver to boost to 5V square wave.
Mach3 PC software transmitting 3V TTL through parallel printer port. Signal placed directly on B0, spastic relay. Ditto when the signal is passed through the tri-state transceiver.
Both signals look exactly the same on an oscilloscope. Both signals find the same ground as the PIC, relay, transceiver, parrallel port and power supply.
I even took the signal directly from the parallel port attached to the PC in case the cable was defective.
Arghhhhh.....
BTW, I believe "CMCON = 7" would be a moot entry. "ADCON1 = 7" makes ports A and E digital I/O rather than analog.
Does the power supply sag?
From the symptoms described, I would be looking (with a scope) at the power supply. If the 5V relay draws slightly more current than the power supply can sustain then I would expect BrownOut Resets some short time after the relay energises.
Just a thought.
Brian