|
|
View previous topic :: View next topic |
Author |
Message |
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
star delta starter |
Posted: Wed Jul 15, 2009 11:37 pm |
|
|
Hi this is my program which I am working for.
This program is used for automatic star delta starter”” there will be two buttons ‘start’ and ‘stop’.
There will be three contactors MAINS, DELTA, STAR.
When I press start button :::::: the contactors MAINS and STAR should switch ON.
After a delay of 10sec the STAR should be OFF and DELTA should be ON.
When I press stop button :::::::: all the contactors should be switched OFF.
This is the algo.
This is my program:
Code: |
#include <16F88.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=14000000)
#use fast_io(b)
#use fast_io(a)
#define mains pin_b0
#define star pin_b1
#define delta pin_b2
int start, stop;
void off() {
output_low(mains);
output_low(delta);
output_low(star);
}
void pinread() {
start=input(PIN_b7);
stop=input(pin_b6);
}
void on() {
output_high(star);
output_high(mains);
delay_ms(10000);
output_low(star);
output_high(delta);
}
void main() {
set_tris_a(0x00);
set_tris_b(0xF0);
while (1) {
start:
pinread();
if(start==1) { on(); }
else { off();
goto start;
} //searching for start button to ON the motor
stop:
pinread();
if(stop==0) {off(); }
else { goto stop; } //searching for STOP button to stop the motor
}
} |
It successfully runs the motor switching from star to delta.
But my question is when changing STAR contactor to DELTA i.e 10sec time delay. Here when I press STOP button the contactors should go OFF. But according to this code it con’t happen. Because during 10 sec delay no inputs will accepted by controller.
I don’t know about software and hardware interrupts. I know the concept of interrupt but I don’t know coding of interrupts.
So I need help for making this successful. During the delay 10sec if I press STOP all the contactors should go off. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Jul 16, 2009 5:22 pm |
|
|
There is some interrupt-driven button code here:
http://www.ccsinfo.com/forum/viewtopic.php?t=31849
It doesn't have a button buffer, so you would only see the latest button
press, if you don't check the status for 10 seconds.
Here's an improved version that has a button buffer. See the code below.
The code for the "button.c" file is at this link:
http://www.ccsinfo.com/forum/viewtopic.php?t=23837
If I press one key and hold it down, and then release it and hold down
the other, and then hold both down at the same time, this will be the
output on the terminal window:
Quote: |
Set
Set
Set
Set
Select
Select
Select
Select
Set
Select
Set
Select
Set
Select
Set
|
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include "button.c"
//----------------------------
// DEFINES
#define SELECT_BUTTON 1
#define SET_BUTTON 2
// Button pins
#define SELECT_BUTTON_PIN PIN_B0
#define SET_BUTTON_PIN PIN_A4
// The preload value below gives an RTCC interrupt rate of
// about 100 Hz (10 ms period) with a 4 MHz crystal.
#define RTCC_PRELOAD (256 - 39)
//----------------------------
// GLOBAL VARIABLES
// These are the "Bvar" variables required by Button.c.
// There is one variable for each button.
int8 Bvar_select = 0;
int8 Bvar_set = 0;
// Variables used by button buffer code.
#define BUTTON_BUFFER_SIZE 16
int8 button_buffer[BUTTON_BUFFER_SIZE];
int8 next_in = 0;
int8 next_out = 0;
#define button_ready (next_in!=next_out)
//---------------------------------------------------
// The buttons are read in this Timer0 (RTCC) isr.
#int_rtcc
void rtcc_isr(void)
{
int t;
set_rtcc(RTCC_PRELOAD + get_rtcc());
// Check if the Select button was pressed.
// If so, put it in the buffer.
if(button(SELECT_BUTTON_PIN, 0, 50, 10, Bvar_select, 1))
{
button_buffer[next_in] = SELECT_BUTTON;
t = next_in;
next_in = (next_in+1) % BUTTON_BUFFER_SIZE;
if(next_in == next_out)
next_in = t; // Buffer full !!
}
// Check if the Set button was pressed.
// If so, put it in the buffer.
if(button(SET_BUTTON_PIN, 0, 50, 10, Bvar_set, 1))
{
button_buffer[next_in] = SET_BUTTON;
t = next_in;
next_in = (next_in+1) % BUTTON_BUFFER_SIZE;
if(next_in == next_out)
next_in = t; // Buffer full !!
}
}
int8 get_button(void)
{
int8 c;
while(!button_ready);
c = button_buffer[next_out];
next_out = (next_out+1) % BUTTON_BUFFER_SIZE;
return(c);
}
//================================
void main()
{
int8 button;
printf("Start \n\r");
setup_counters(RTCC_INTERNAL, RTCC_DIV_256);
set_rtcc(RTCC_PRELOAD);
clear_interrupt(INT_RTCC);
enable_interrupts(INT_RTCC);
enable_interrupts(GLOBAL);
while(1)
{
if(button_ready)
{
button = get_button();
if(button == SELECT_BUTTON)
printf("Select \n\r");
if(button == SET_BUTTON)
printf("Set \n\r");
}
}
} |
|
|
|
mutthunaveen
Joined: 08 Apr 2009 Posts: 100 Location: Chennai, India
|
|
Posted: Thu Jul 16, 2009 11:59 pm |
|
|
thank u very much.... but is too complicated to understand....
i will try to understand |
|
|
Haudi Guest
|
|
Posted: Mon Nov 23, 2009 4:01 am |
|
|
Somehow I'm getting a get_button function value 25.
And I'm getting it only once because of if function (button_ready).
Code: |
while(1)
{
if(button_ready)
{
button = get_button();
button = a;
printf("Button value %u \n\r",a); // a value is 25 ?
printf("Select button %u \r\n",SELECT_BUTTON); //1
printf("Set button %u \r\n",SET_BUTTON);//2
if(button == SELECT_BUTTON)
printf(lcd_putc,"Select \n\r");
if(button == SET_BUTTON)
printf("Set \n\r");
}
}
|
Also I've included a main function code.
Code: |
#include "C:\Documents and Settings\Viktor\Application Data\PICC\Projects\LCD proov 3 1602\main lcd proov 3.h"
//#include <18F4520.H>
//#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
//#use delay(internal = 8000000)
#include <button.c>
#define SELECT_BUTTON 1
#define SET_BUTTON 2
// Button pins
#define SELECT_BUTTON_PIN PIN_D0
#define SET_BUTTON_PIN PIN_D1
// The preload value below gives an RTCC interrupt rate of
// about 100 Hz (10 ms period) with a 4 MHz crystal.
#define RTCC_PRELOAD (256 - 39)
//----------------------------
// GLOBAL VARIABLES
// These are the "Bvar" variables required by Button.c.
// There is one variable for each button.
int8 Bvar_select = 0;
int8 Bvar_set = 0;
// Variables used by button buffer code.
#define BUTTON_BUFFER_SIZE 16
int8 button_buffer[BUTTON_BUFFER_SIZE];
int8 next_in = 0;
int8 next_out = 0;
#define button_ready (next_in!=next_out)
#define RTC_SDA PIN_C4
#define RTC_SCL PIN_C3
//int8 D0 = 0; // For the button on pin A4
//int8 D1 = 0; // For the button on pin B
#use I2C(MULTI_MASTER,sda=RTC_SDA, scl=RTC_SCL)
#use delay(internal=8M)
#use rs232(uart1, baud=9600)
//#use i2c(master,SDA=PIN_B7, SCL=PIN_B6)
#include <flex_lcd.c>
#include <stdlib.h>
#include <DS1307.c>
#include <muutmine.c>
#include <ADCfunktsioonid.c>
#include <nupud.c>
#int_rtcc |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|