sahu
Advanced Member level 2
- Joined
- Oct 9, 2009
- Messages
- 516
- Helped
- 68
- Reputation
- 130
- Reaction score
- 62
- Trophy points
- 1,308
- Location
- Uttar pradesh (INDIA)
- Activity points
- 3,876
There is only 4 relays. Other is LED (rc4) and it starts blinking when out of range. If you connect a relay to this pin, it will start to do "tic tic".
I change port also . as I shown in pin configuration .,
///////////////// 03124002221 lahore pakistan
#include <16f676.h>
#device adc=10
#use delay(clock=4000000)
#fuses intrc_io
#fuses NOWDT,PUT,NOPROTECT,BROWNOUT,NOMCLR
/////////////////////pins lables///////////////////
#define relay1 pin_a1 //main change
#define relay2 pin_a2 //main change
#define relay3 pin_c0 //outputchange
#define relay4 pin_c1 //output on off
#define led pin_c2 //led for indication of timer
#define sw pin_a3 //active low
#define low_limit 1550 // limit for low voltage
#define high_limit 2450 // limit for high voltage
#define low_ok 2100 // value for main low function compleate
#define high_ok 2440 // value for main high function compleate
#define on output_high
#define off output_low
////////////////////////////////////////////////////
unsigned int32 main_v=1000;
unsigned int8 step=1,time=0,x;
int1 fault=0;
unsigned int8 delay=30;
////////////////////////////////////////////////////
void adc_read (void);
void relay_Set (void);
void main_high (void);
void main_low (void);
void initialize(void);
void start_up (void);
/////////////////////timer1 isr//////////////////////
#int_timer1
void timer1_subrutine(void)
{
set_timer1(65536-62500); // after 0.5S interrupt will rise
time++;
output_toggle(led);
if (((time>delay)||(input(sw)==0)) && (fault==0))
{
time=0; // for next round
on(led);
on(relay4);
disable_interrupts(int_timer1);
disable_interrupts(global);}
}
////////////////////////////////////////////////////////
void main()
{
initialize();
WHILE(true)
{
start_up();
////////////////////normal loop///////////////////////////////
do
{
for(x=0; x<20; x++) //loop to perform voltage stabalization function
// if gap is larg then only one step can not stabal voltage
{
adc_read();
if(main_v>2410)
{step--; if(step<1)step=1; relay_set();} //239V
else if(main_v<1630) //200V
{step++; if(step>6)step=6;relay_set();}
else;
}
}
while((main_v<high_limit)&&(main_v>low_limit)); // check the limits
/////////////////////under over section///////////////////////
fault=1;
time=0; // reset timer if it was running
if(main_v>=high_limit) main_high(); // call relevent function
else if(main_v<=low_limit) main_low(); // call relevent function
disable_interrupts(int_timer1); // reset timer and interrupt
disable_interrupts(global);
fault=0;
}
}
///////////////////////////////////////////////////////////////
void main_low (void)
{
enable_interrupts(int_timer1);
enable_interrupts(global);
off(relay4);
off(relay3);
off(relay2);
off(relay1);
delay_ms(500);
while(main_v<low_ok)
{
time=0;
adc_read();
}
}
///////////////////////////////////////////////////////////////
void main_high (void)
{
enable_interrupts(int_timer1);
enable_interrupts(global);
off(relay4);
on(relay1);
on(relay2);
on(relay3);
delay_ms(500);
while(main_v>= high_ok)
{
time=0;
adc_read();
}
}
///////////////////////////////////////////////////////////
void adc_read (void)
{
delay_ms(20);
main_v =read_adc();
main_v=main_v*5000/1023;
}
////////////////////////////////////////////////////////////////////////////////
void initialize (void)
{
off(relay4);
on(relay1);
on(relay2);
on(relay3);
/////////////input output setting////////////////////
set_tris_a(0b11110001);
set_tris_c(0b11111000);
output_float(pin_a0);
setup_adc(adc_clock_div_64);
SETUP_ADC_PORTS(sAN0 ) ;
}
///////////////////////////////////////////////////////////////////////////////////
void start_up (void)
{
delay_ms(100);
adc_read();
setup_timer_1(t1_internal | t1_div_by_8);
enable_interrupts(int_timer1);
set_timer1(65536-62500); //initialize for correct time
enable_interrupts(global); //unmasked interrupts enable
}
///////////////////////////////////////////////////////////
void relay_set (void)
{
if(step==1)
{ on(relay1);
on(relay2);
on(relay3);}
else if(step==2)
{on(relay1);
on(relay2);
off(relay3);}
else if (step==3)
{on(relay1);
off(relay2);
on(relay3);}
else if (step==4)
{on(relay1);
off(relay2);
off(relay3);}
else if (step==5)
{off(relay1);
off(relay2);
on(relay3);}
else if (step==6)
{off(relay1);
off(relay2);
off(relay3);}
else;
}
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
/////////////////////timer1 isr//////////////////////
#int_timer1
void timer1_subrutine(void)
{
set_timer1(65536-62500); // after 0.5S interrupt will rise
time++;
output_toggle(led);
if (((time>delay)||(input(sw)==0)) && (fault==0))
{
time=0; // for next round
on(led);
on(relay4);
disable_interrupts(int_timer1);
disable_interrupts(global);}
}
////////////////////normal loop///////////////////////////////
do
{
for(x=0; x<20; x++) //loop to perform voltage stabalization function
// if gap is larg then only one step can not stabal voltage
{
adc_read();
if(main_v>2410)
{step--; if(step<1)step=1; relay_set();} //239V
else if(main_v<1630) //200V
{step++; if(step>6)step=6;relay_set();}
else;
}
}
while((main_v<high_limit)&&(main_v>low_limit)); // check the limits
Hi,Mr irfanstart up delay can be changed using variable named "delay".
currently it is 15 second for checking purpose.
#define sw pin_a3 //active low
I think a3 pin in 16f676 is Mclr pin, so how it work as sw?
how i change the operating voltage range of relay under the program?
adc_read();
if(main_v>2410)
{step--; if(step<1)step=1; relay_set();} //239V
else if(main_v<1630) //200V
{step++; if(step>6)step=6;relay_set();}
else;
}
}
while((main_v<high_limit)&&(main_v>low_limit)); // check the limits
stabilizer is not designed for high voltage .
variable is erased in this code
here is new code and hex file
I understand the function. I just want help to understand program stepping which you write. I have another question that is this program work properly? I mean to say is it tested practically with transformer?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?