Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - A question about pins with negate output

(you are viewing a thread; or go back to list of threads)

A question about pins with negate output (by antares)
Hi.
I am testing the LDmicro with a 16f876A in a board with relays that are switched on by putting the corresponding output pin at low level and I find the following problem:
After loading the .hex in the PIC I can hear a brief activation / deactivation of the relay. And it lasts what it takes the LDmicro to initialize the pin as output by setting it low and going to the execution of the first line (rung) of my program where I have that pin declared as a coil of the negated type.
I have managed to solve it by generating the code in 'c' for HI-TECH and inserting an instruction Write1_Ub_Yrele1 () just after the declaration of pins with PORTX TRISX in void setupPlc (void). Compiling and then loading the .hex that HI-TECH generates.
I would like to know if there is a more direct way to do it from the LDmicro.

Thank you
Mon Dec 3 2018, 14:30:01
(no subject) (by MGP)
I think that this is a hardware problem because at startup all pins are input.
Can you post the schematic of your project?
Tue Dec 4 2018, 02:13:56
(no subject) (by MGP)
Avoid PORTB as output pins because of the pull-up resistors at startup but I think that a relay is too slow to see that and that something is wrong with your schematic.
Tue Dec 4 2018, 03:52:30
(no subject) (by antares)
This is a part of the board schematic. The pins that control the 6 relays are RA0 to RA5, all the same.
Simulating this simple program in HI-TECH with the 16f876A at 10MHz, the RA3 pin that controls the relay 1 takes 10 milliseconds to get high (relay OFF) since it is declared as an output and set low (relay ON) in "setupPlc"

LADDER DIAGRAM:
|| ||
|| Xbtn2 Rr1 ||
0001||-------]/[--------------(S)-------||
|| ||
|| ||
|| Xbtn3 Rr1 ||
0002||-------]/[--------------(R)-------||
|| ||
|| ||
|| Rr1 Yrele1 ||
0003||-------] [--------------(/)-------||
|| ||
|| ||
|| ||
3||------[END]-----------------------||
|| ||
|| ||

I/O ASSIGNMENT:
Name | Type | Pin | Port | Pin name
----------------------------+--------------------+-----+------+-----------
Xbtn2 | digital in | 22 | RB1 |
Xbtn3 | digital in | 23 | RB2 |
Yrele1 | digital out | 5 | RA3 |
Rr1 | int. relay | | |





void setupPlc(void) {
// Set up I/O pins direction, and drive the outputs low to start.
PORTA = 0x00;
TRISA = 0xF7; //RA3 is declared as output. Now I have a low level in this pin (Relay ON)
PORTB = 0x00;
TRISB = 0xFF;
PORTC = 0x00;
TRISC = 0xFF;
Tue Dec 4 2018, 04:18:55, download attachment prueba2.jpg
(no subject) (by MGP)
Sorry, but I need the full schematic, including the power supply, the inputs are OK.
I still think it's a hardware fault.
Tue Dec 4 2018, 05:18:17
(no subject) (by antares)
Sorry. But I do not have permission to put the full scheme.
The simulation of the LDmicro program that I put above is done with MPLAB-SIM. Hardware does not influence at all because is a software simulation. And you can see that the output remains low for 10 milliseconds.
But supposing that it was a hardware failure, how is it solved in this way?

void setupPlc(void) {
// Set up I/O pins direction, and drive the outputs low to start.
PORTA = 0x00;
TRISA = 0xF7; //RA3 is declared as output.
PORTA = 0b00001000; //But now I have a HIGHT level in RA3 (Relay OFF)
PORTB = 0x00;
TRISB = 0xFF;
PORTC = 0x00;
TRISC = 0xFF;

My opinion is that LDmicro should initialize at high level the outputs that are declared as negated.
Tue Dec 4 2018, 06:21:58
(no subject) (by MGP)
The reason why I ask the full schematic is that the optocoupler in your schematic works on 3.6V and an 16F876a does not work on 3.6V, you need a 16LFxxx for that.
Tue Dec 4 2018, 06:46:19, download attachment 16F87xA.jpg
(no subject) (by antares)
In a software simulation, the power supply does not matter. In real life, the 16F876/16F876a at 10 MHz works correctly at 3.6v.
Tue Dec 4 2018, 07:10:03
(no subject) (by antares)
I send you a capture of the simulation. Putting a breakpoint where the relay is set to high (RELE OFF), the stopwatch shows 10.029200 milliseconds. This is the time that the RA3 output remains low (RELE ON). It is not a hardware problem.
Tue Dec 4 2018, 07:25:23, download attachment Capture-1.jpg
(no subject) (by MGP)
I cannot help you with MPLAB and/or simulation software, I do not have any of those on my computer.
Tue Dec 4 2018, 08:09:50
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):