Detect the presence of the power line PIC18F8720

Thread Starter

Noah96

Joined Apr 3, 2023
5
I am working on a control board for an elevator as part of my final year project. I am currently working on the safety aspect for the landing doors and cabin doors, and I am using Proteus to simulate my circuit.

I am working on the security part of my electronic card, which controls an elevator (i.e., a motor). If the landing doors and the cabin doors are closed, it means a closed circuit and the motor runs, and the elevator goes up or down depending on the operator's call. Imagine the doors as a switch. Since I am controlling an elevator in a four-story building, I need a voltage of 230V. As a workaround, I inserted an alternating voltage V2 in my circuit to isolate two parts of the voltage. The first part is 230V, and the second part is 5V so that I can work with the microcontroller.

I isolated the two sectors of 230v and 5v using an optocoupler, and at the output of the optocoupler, I added a low-pass filter (RC circuit) to maintain a 5V voltage level. The capacitor charges when the circuit is open and discharges when the circuit is closed. After that, I used a NAND logic gate to combine the three circuits. If all three circuits are closed, then the logic state of RB1 pin is high, otherwise, if any of these circuits is open, the logic state of the RB1 pin is 0.

I have not been able to detect the presence of voltage on pin RB1. My problem is that when all three circuits are closed, the color of the RB1 pin is yellow and I'm not sure why.

I would appreciate a response or another solution. I have uploaded the main.c code, hex file, and Proteus simulation to the link. I would appreciate your help with my project.

F.Simulation.pngS.Simulation .pngLINK FOR PROJECT
 

Jony130

Joined Feb 17, 2009
5,488
Have you tried to disable the pull-up resistors on port B? Or you are setting it as a output?
 
Last edited:

ronsimpson

Joined Oct 7, 2019
3,037
I think the NAND gate could be removed. If any opto is on then the output is low.
1682895776680.png
If you use ac "AC/DC" isolator then you do not need the bridge diodes, capacitor and more parts. Just use a resistor.

Speaking of resistors, small resistors cannot take 220VAC. Many are rated for 100 or 150V. You should use two or more resistors when high voltage is present.

RonS.

1682895955817.png
 

Jony130

Joined Feb 17, 2009
5,488
Try to use this hex file (attached) That I compiled in MPLAB X IDE.
And the only thing I changed in your code was here

C:
void __interrupt(high_priority) ISR_1(void) {
    if(INTCONbits.INT1IF){
     
        motor_stop() ;
       
    INTCONbits.INT1IF = 0; // Clear the interrupt flag
}
}
I change INTCONbits.INT1IF on to INTCON3bits.INT1IF

C:
void __interrupt(high_priority) ISR_1(void) {
   if(INTCON3bits.INT1IF){
     
        motor_stop() ;
       
    INTCON3bits.INT1IF = 0; // Clear the interrupt flag
}
}
Because INT1 bit is in INTCON3 register according to the datasheet.

And now in Proteus I have a "RED" on the RB1 pin when the NAND gate is in High state.
 

Attachments

Top