-1
\$\begingroup\$

enter image description here

Rewrite of the question

The circuit shown does not function correctly. The relay remains energized. Without Q5 RA4 behaves under influence of the code as wanted (open drain as mentioned in the specsheet table 5-1).

With Q5 is in place RA4 remains at 0,01 V all the time.

For a test Q5 was removed and replaced with a LED in on Q5be. Here a strange behaviour was detected. At the expected moment the LED lights up for a moment (pulse) but does not stay on.

After placing an emmiter follower in between to isolate RA4 the LED started to behave as expected.

In code RA4 is controlled with:

During init
MOVLW B'00100000'          ; Port RA5 input, others outputs
MOVWF TRISA                

During run
 BSF PORTA,OUTPUT   ;* Set OUTPUT RA4 (Counting not in Progress)
 BCF PORTA,OUTPUT   ;* Clear OUTPUT RA4 (Counting in progress)

It all ends in one single question:

Why does RA4 stay low at 0.01V,consequently keep the relay energized, when Q5 is in place instead of going up to 0,65V under influence of the instructions in the code.

\$\endgroup\$
15
  • \$\begingroup\$ If it worked on breadboard but now doesn't my immediate thought is regarding bypass/decoupling caps. I don't see any on your schematic, and you also don't show any code or confiig settings. The problem could be in any combination of these. What do you mean by RA4 and open drain? RA4 is push-pull, not OD. Do you mean you make it an input (high-Z)? \$\endgroup\$ Commented Jan 13, 2017 at 9:34
  • \$\begingroup\$ Ok, I see Table 5-1 now, I was looking at the wrong DS (PIC16F684 instead of 648A!), so RA4 is OD output. What about decoupling capacitor between Vdd and Vss? \$\endgroup\$ Commented Jan 13, 2017 at 10:09
  • \$\begingroup\$ Are you sure R15 is a 10K? \$\endgroup\$
    – HandyHowie
    Commented Jan 13, 2017 at 10:45
  • \$\begingroup\$ Can you remove the PIC from the circuit? If so, remove the PIC and measure the voltage at the RA4 pin. Should be about 0.65 Vdc. My first thought is that the transistor pinout or connections are wrong. \$\endgroup\$ Commented Jan 13, 2017 at 11:37
  • \$\begingroup\$ @DwayneReid. See my question. BE is indeed 0.65V. \$\endgroup\$
    – Decapod
    Commented Jan 13, 2017 at 11:43

4 Answers 4

3
\$\begingroup\$
During run
 BSF PORTA,OUTPUT   ;* Set OUTPUT RA4 (Counting not in Progress)
 BCF PORTA,OUTPUT   ;* Clear OUTPUT RA4 (Counting in progress)

Your circuit is fine, but this code gives a hint as to what is going wrong. I bet you are also using BSF and BCF to control Q1-Q4. These instructions are 'read/modify/write', which means they read the port, change a bit in it, then write the result back to the port.

On most 8 bit PICs the port's output latch and input buffer are at the same memory location - and any read operation reads the voltages on the pins, not the value stored in the output latch. Q5's Base holds the voltage down to 0.6V so RA4 always reads as a '0', which is then written back to the output latch when modifying other bits on PORTA.

The solution is to keep a 'shadow' variable in RAM that is a copy of the port's output latch. You set and clear bits in this variable, then write the entire byte to the port. With this technique you can set up several outputs sequentially and then write them to the port simultaneously.

The code could look something like this:-

cblock
PortA_latch            ; copy of PORTA output latch 
endc

BSF   PortA_Latch,RA4  ; to turn Q5 on
BSF   PortA_Latch,RA1  ; to turn Q2 on
MOVF  PortA_Latch,w   
MOVWF PORTA            ; write all output bits to port
\$\endgroup\$
2
  • \$\begingroup\$ I think I understand. I go give it a try. If ok it could reduce the complexity of the system \$\endgroup\$
    – Decapod
    Commented Jan 14, 2017 at 17:08
  • \$\begingroup\$ With your answer I will correct the code. However I need to stick to the complex version for 2 reasons. RA 4 is going high during sleep and I can not change this around because of the 12V needed for the relay. \$\endgroup\$
    – Decapod
    Commented Jan 14, 2017 at 17:46
0
\$\begingroup\$

enter image description here

Since the solution for the problem encountered was not received I had to continue on my own. The solution found was by selecting a pnp transistor connected to RA4. This makes that the base voltage on Q5 gets up to VDD level when RA 4 is set. When RA 4 is low Q5 conducts drives Q6 into conduction resulting in an energized relay RE1.

In the background there must be a coding condition causing RA4 to change back to low when the program is running. It should have to do with the interaction between the pin and latch of RA 4 but my knowledge of the pic and its programming is falling short to solve that at this moment. For that I have to study some more.

\$\endgroup\$
0
\$\begingroup\$

In your first schematic, you had no base resistor. I know you mentioned open drain, but are you sure you configured specifically for open drain?

If not, RA4 would have output an uncontrolled amount of current. This could partially collapse the internal power rail or cause an internal logic error and cause the MCU to reset. This could explain why you see the LED (repacing an LED for Q5) just "blip" for a tiny bit.

It would be safer to just add a single resistor to control Q5 base current in case RA4 was misconfigured.

Also, can you invert the RA4 logic so you only need Q6? If so, you would thus only need 1 transistor (or a simple Darlington if you need higher gain) and 1 resistor.

\$\endgroup\$
1
  • \$\begingroup\$ Appreciate your reaction. RA 4 is OD only. (Datasheet). The program kept working in spite of the problem. Only RA4 behaved strange. For now I need the VDD voltage level on RA4 when open ( high impediance). \$\endgroup\$
    – Decapod
    Commented Jan 14, 2017 at 15:28
0
\$\begingroup\$

I think that your 10k base resistors (pull up) in your original schematic were too high a value which will have given insufficient base current to switch Q5 on once connected to the PIC. In schematic in your answer, you have dropped the base resistor to 1k which you say is now working correctly.

Which transistor were you using for Q5?

\$\endgroup\$
4
  • \$\begingroup\$ The problem was not the 10k but the situation as indicated in the answer of Bruce Abbot. The transistor I used was a BC 457. \$\endgroup\$
    – Decapod
    Commented Jan 16, 2017 at 10:56
  • \$\begingroup\$ The reason that the layout in the answer is working has to do with the introduction of the emitter follower preventing RA4 going low again due to the Q5be voltage. \$\endgroup\$
    – Decapod
    Commented Jan 16, 2017 at 11:03
  • \$\begingroup\$ Initially you said that it was working fine on a breadboard, do you know why that was the case? \$\endgroup\$
    – HandyHowie
    Commented Jan 16, 2017 at 11:26
  • \$\begingroup\$ Yes. At that time I had only a LED in series with the resistance to RA4. That LED worked fine. At that moment I had no idea that a low Q5be at a later moment could cause a problem. \$\endgroup\$
    – Decapod
    Commented Jan 16, 2017 at 12:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.