View previous topic :: View next topic |
Author |
Message |
NewSpace
Joined: 23 Sep 2003 Posts: 12 Location: South KOREA
|
I wanna use E-Stop (B0 Interrupt) |
Posted: Mon Jan 31, 2005 6:12 pm |
|
|
Dear Master.
I just finished StepMoter running program.
But I wanna Use E-Stop at B0...
I don't know how to use E-stop
When I push E-Stop Button than everything stop.
If turning motor also stop....
Please check my code....
Thank you~!
void reset()
{
E0 = ON;
E1 = ON;
delay_ms(1000);
E2 = ON;
}
#INT_EXT
ext_isr()
{
reset();
}
Full Code
#include <16F874.h>
#use delay(clock=4000000)
#fuses HS,NOWDT
// #use rs232(baud=9600,parity=N,xmit=P E2,rcv=P E1)
#zero_ram
#byte porta = 0x05
#byte portb = 0x06
#byte portc = 0x07
#byte portd = 0x08
#byte porte = 0x09
#bit A0 = porta.0 // IN 체결 회전 위치
#bit A1 = porta.1 // IN Tray 위치
#bit A2 = porta.2 // IN Tray 0점
#bit A3 = porta.3 // IN 체결 하강 위치
#bit A4 = porta.4 // IN Alram_tray
#bit A5 = porta.5 // IN Alram_cpruf
#bit B0 = portb.0 // IN 비상정지
#bit B1 = portb.1 // IN 체결동작 Start
#bit B2 = portb.2 // IN Tray Move
#bit B3 = portb.3 // IN O점 이동
#bit B4 = portb.4 //
#bit B5 = portb.5 //
#bit B6 = portb.6 //
#bit B7 = portb.7 //
#bit C0 = portc.0 //
#bit C1 = portc.1 //
#bit C2 = portc.2 //
#bit C3 = portc.3 //
#bit C4 = portc.4 //
#bit C5 = portc.5 //
#bit C6 = portc.6 //
#bit C7 = portc.7 //
#bit D0 = portd.0 //
#bit D1 = portd.1 //
#bit D2 = portd.2 //
#bit D3 = portd.3 //
#bit D4 = portd.4 // OUT tray_cw
#bit D5 = portd.5 // OUT tray_ccw
#bit D6 = portd.6 // OUT cpruf_cw
#bit D7 = portd.7 // OUT cpruf_ccw
#bit E0 = porte.0 // OUT Reset_cpruf
#bit E1 = porte.1 // OUT Reset_Tray
#bit E2 = porte.2 // OUT Ready
#define ON 1
#define OFF 0
#define ON_NPN 1
#define OFF_NPN 0
int Speed_CW, Speed_CCW, Speed_Home, Speed_Tray;
int16 i, j;
void reset()
{
E0 = ON;
E1 = ON;
delay_ms(1000);
E2 = ON;
}
#INT_EXT
ext_isr()
{
reset();
}
void Move_Home()
{
E2 = OFF;
while(A0 != ON_NPN) // 체결 센서 입력이 않될때 까지 이동
{
D7 = ON;
delay_us(speed_home);
D7 = OFF;
delay_us(speed_home);
}
while(A0 != OFF_NPN) // 센서 입력이 될때 까지 이동
{
D6 = ON;
delay_us(speed_home);
D6 = OFF;
delay_us(speed_home);
}
while(A1 != ON_NPN) // 센서 입력이 않될때 까지 이동
{
D5 = ON;
delay_us(speed_home);
D5 = OFF;
delay_us(speed_home);
}
while(A1 != OFF_NPN) // 센서 입력이 될때 까지 이동
{
D4 = ON;
delay_us(speed_home);
D4 = OFF;
delay_us(speed_home);
}
E2 = ON;
}
void cpruf()
{
E2 = OFF;
for(j=0; j<=1600; j++)
{
D6 = ON;
delay_us(speed_ccw);
D6 = OFF;
delay_us(speed_ccw);
}
while(A3 != ON) // 하강 리미트 입력시까지
{
D7 = ON;
delay_us(speed_cw);
D7 = OFF;
delay_us(speed_cw);
}
for(i=0; i <= 1600; i++)
{
D6 = ON;
delay_us(speed_ccw);
D6 = OFF;
delay_us(speed_ccw);
}
E2 = ON;
}
void move_tray()
{
E2 = OFF;
while(A2 != ON_NPN) // 센서가 감지 안 될때까지 이동
{
D4 = ON;
delay_us(speed_tray);
D4 = OFF;
delay_us(speed_tray);
}
while(A2 != OFF_NPN) // 센서가 감지 될때까지 이동
{
D4 = ON;
delay_us(speed_tray);
D4 = OFF;
delay_us(speed_tray);
}
E2 = ON;
}
void main()
{
setup_adc_ports(NO_ANALOGS);
ext_int_edge(0,L_TO_H);
enable_interrupts(int_ext);
enable_interrupts(global);
set_tris_a(0xFF); // IN
set_tris_b(0xFF); // IN
set_tris_c(0xFF); // IN
set_tris_d(0x00); // OUT
set_tris_e(0x00); // OUT
output_d(0x00);
output_e(0x00);
speed_home = 255;
speed_cw = 200;
speed_ccw = 100;
speed_tray = 100;
Move_Home();
while(1)
{
E2 = ON;
if(B0 == ON) reset();
else if(B1 == ON) cpruf();
else if(B2 == ON) Move_Tray();
else if(B3 == ON) Move_Home();
}
}
// main...
setup_adc_ports(NO_ANALOGS);
ext_int_edge(0,L_TO_H);
enable_interrupts(int_ext);
enable_interrupts(global);
_________________ Hello~?
This is South KOREA
My name is Sanghyouk Kim But Call me Nick
Sorry I'm poor English |
|
|
mkent
Joined: 09 Sep 2003 Posts: 37 Location: TN, USA
|
E-stop |
Posted: Mon Jan 31, 2005 7:04 pm |
|
|
Hello Nick,
I did not check your code but want to warn you to check your National Electrical Codes to see if it is legal to do an E-Stop function in software. Many countrys require E-Stop circuits to be hard wired. You must remove the power source from your motor with a relay. Good Luck, Mick |
|
|
Nick Guest
|
Thank you ... It' mean.... |
Posted: Mon Jan 31, 2005 7:44 pm |
|
|
Thank you for your refly.
So you mean... use the power?
I think when push the E-Stop Button than EXT Interrupt...
than Output Reset to Step Motor or Servo motor...
I need like this source code.
Thank you~! |
|
|
TSchultz
Joined: 08 Sep 2003 Posts: 66 Location: Toronto, Canada
|
|
Posted: Tue Feb 01, 2005 11:56 am |
|
|
What I have always done is to have the e-stop circuitry hardwired to the motor control. I then bring a digital signal back from this circuit to the micro so it "know's" the e-stop status.
This is what most safety codes require and is not that difficult to do, and much more reliable. Remember that the micro is not a safety certified component and does not fail safe. |
|
|
Nick Guest
|
Thank you~! |
Posted: Tue Feb 01, 2005 6:04 pm |
|
|
Dear all.
Thak you fo help....
I'll check code and H/W |
|
|
|