Hi everyone,
I want to apply the soft stop technology in my project by using PWM, and PIC16F877A.
It mean I want to control the closing door box to a smooth impact.
But I am lack of C but I am trying to learn it.
Attached here is the model of my project.
Here is my MicroC code. Still under construction,only have a basic movement.
My problem is when i simulate using ISIS proteus, the motor run without selected any button.
System Operation
Here are 3 boxes of cabinet. Box 1 is fixed box while another 2 boxes is moveable box. The user can select either PB1 or PB3 “Right Button” or PB2 OR PB 4 “Left Button” at any box. For example; if the users select the PB2 of box 2, both motor (M1 and M2) will run to left side until the motor 1 detect the proximity sensor and motor 2 reached a limit switch. When the user step in the aisle between the box 2 and box 1, the both motor will stop since the PIR sensor will automatically detect the user. So, automatically whole the system operation will stop and all illuminated push button will blink. When the sensors clear the interrupt (no obstacle), the user can continue the current operation by select either “Right Button” or “Left Button” at any box again. IR sensor used to detect user and Proximity sensor used to keep the safe distance between tow boxes.
I want to apply the soft stop technology in my project by using PWM, and PIC16F877A.
It mean I want to control the closing door box to a smooth impact.
But I am lack of C but I am trying to learn it.
Attached here is the model of my project.
Here is my MicroC code. Still under construction,only have a basic movement.
Code:
//define motor1 ports
sbit motor1a at RD0_bit;
sbit motor1b at RD1_bit;
//define motor2 ports
sbit motor2a at RD2_bit;
sbit motor2b at RD3_bit;
//define sensor ports
#define SENSOR PORTA
//define switches ports
#define PB1 PORTB.F0
#define PB2 PORTB.F1
#define PB3 PORTB.F2
#define PB4 PORTB.F3
unsigned short toggle = 0;
void main(){
TRISA = 0XFF; //Configure all bit of PORTA as input
TRISB = 0XFF; //Configure all bit of PORTB as input
TRISD = 0X00; //Configure all bit of PORTD as output
PORTA = 0X00; //Clear bits to zero
PORTB = 0X00; //Clear bits to zero
PORTD = 0X00; //Clear bits to zero
CMCON=0X07; //or CMCON register = 0X00000111
ADCON1=0X07; //Configure ADCON1, or ADCON1=0X06;
while(1){
if((SENSOR & 0x07) == 0x00)
{
if(PB1 == 1) //If the push button 1 is pressed
{
Delay_ms(50); // Delay 100 ms
if(PB1 == 1)
{
motor1a = 1; // Motor 1 clockwise
motor1b = 0;
motor2a = 1; // Motor 2 clockwise
motor2b = 0;
}
}
else
if (PB2 == 1) //If the push button 2 is pressed
{
Delay_ms(50); // Delay 100 ms
if(PB2 == 1)
{
if(PB2 == 1)
motor1a = 0; // Motor 1 counter clockwise
motor1b = 1;
motor2a = 0; // Motor 2 counter clockwise
motor2b = 1;
}
}
else
if (PB3 == 1) //If the push button 3 is pressed
{
Delay_ms(50); // Delay 100 ms
if(PB3 == 1)
{
motor1a = 1; // Motor 1 clockwise
motor1b = 0;
motor2a = 1; // Motor 2 clockwise
motor2b = 0;
}
}
else
if (PB4 == 1) //If the push button 4 is pressed
{
Delay_ms(50); // Delay 100 ms
if(PB4 == 1)
{
motor1a = 0; // Motor 1 counter clockwise
motor1b = 1;
motor2a = 0; // Motor 2 counter clockwise
motor2b = 1;
}
}
}
else if(((SENSOR & 0x07) == 0x01) || ((SENSOR & 0x07) == 0x02) || ((SENSOR & 0x07) == 0x04))
{
motor1a = 0; // Motor 1 stop
motor1b = 0;
motor2a = 0; // Motor 2 stop
motor2b = 0;
}
}
}
My problem is when i simulate using ISIS proteus, the motor run without selected any button.
System Operation
Here are 3 boxes of cabinet. Box 1 is fixed box while another 2 boxes is moveable box. The user can select either PB1 or PB3 “Right Button” or PB2 OR PB 4 “Left Button” at any box. For example; if the users select the PB2 of box 2, both motor (M1 and M2) will run to left side until the motor 1 detect the proximity sensor and motor 2 reached a limit switch. When the user step in the aisle between the box 2 and box 1, the both motor will stop since the PIR sensor will automatically detect the user. So, automatically whole the system operation will stop and all illuminated push button will blink. When the sensors clear the interrupt (no obstacle), the user can continue the current operation by select either “Right Button” or “Left Button” at any box again. IR sensor used to detect user and Proximity sensor used to keep the safe distance between tow boxes.