Qaisar Azeemi
Full Member level 5
- Joined
- Feb 11, 2011
- Messages
- 315
- Helped
- 16
- Reputation
- 32
- Reaction score
- 15
- Trophy points
- 1,298
- Location
- Peshawar, Pakistan, Pakistan
- Activity points
- 3,829
void main()
{
// CONFIGURING SFRs:
cnt=0;
TMR0=0; // loading vlaue of timer0 interrupt
OPTION_REG=0x87; // for timer 0; presscaller 1; 256
ADCON1=0x07; // adc reg initialization ; changes port a to digital I/O
INTCON=0xA0; // for timer0 ; interrupt reg initilization
// OUTPUTS:
TRISB.f2 = 0; //led out put
TRISE.F2=0; // gen cont output
TRISC=0x00; // portC output For LCD
PORTC=0X00; // initilization port c
TRISB.f0 = 0; //led out put
// INPUTS:
TRISB.f7 = 1; //temp
TRISB.f6 = 1; // oil
TRISD.F0=1; // ENTER
TRISD.F1=1; // RESET
TRISD.F2=1; // UP
TRISD.F3=1; // DOWN */
TRISA = 0xFF; // port A as input
TRISD = 0x0F; // Lower nibble of port D as input
T1CON.TMR1ON=1;
PIR1.TMR1IF=0;
TMR1L=0X00;
TMR1H=0X00;
ADC_Init();
if(mains==P) // if main is Present.
{
lcd_init();
start();
}
start:
lcd_init();
Delay_ms(500);
while(1)
{
if(mains==A) // if main is absent.
{
Lcd_Cmd(_LCD_CLEAR);
Lcd_Out(1,1,CopyConst2Ram(msg,mna)); //mains not available
Delay_ms(4000); // wait for 4 seconds to ensure power failure
if(mains==P) //check again
continue;
//Delay_ms(1000);
Lcd_Cmd(_LCD_CLEAR); // Clear display
//Delay_ms(600);
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mna)); //mains not available
Lcd_Out(2,1,CopyConst2Ram(msg,sg)); //starting genset
Delay_ms(1000);
gen();
}
else // if main is present .........
{
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Out(1,1,CopyConst2Ram(msg,mok)); // Write text in first row
Lcd_Out(2,1,CopyConst2Ram(msg,mol)); // mains overload
Delay_ms(2000);
//gen_cont=0; //Turn off generator contactor
//main_cont=1; //Turn on main contactor
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Out(1,3,CopyConst2Ram(msg,st)); // Write text in first row
Lcd_Out(2,4,CopyConst2Ram(msg,pl)); // pvt ltd
Delay_ms(1000);
}
for(i=0; i<96; i++)
{
Lcd_Cmd(_LCD_SHIFT_RIGHT);
Delay_ms(t);
if (enter==0)
i=96;
if ((enter==1) && (reset==0) && (up==1) && (down==1)) //press reset to exit
{
Delay_ms(ms); // wait for switch debounce
i=0;
goto start
}
if(mains==A)
{
i=96;
}
}
} // while
} // main
gen()
{
if(frq==1) //on timer 1 interrupt
{
k++;
if(k==155) // after 16 interrupts = 1sec
{
// l2=~l2;
shortToStr(G,op);
Lcd_Out(2,2,op);
Lcd_Out_CP("Hz");
Delay_ms(200);
G=0;
k=0;
}
T1CON.TMR1ON=1;
frq=0;
}
if (oil !=0 || tmp!=0)
{
ADCON1 =0x00;
tmp = ADC_Read(4);
Delay_ms(ms);
shortToStr(tmp,op);
Lcd_Out(2,10,op);
Lcd_Out_CP("V");
Delay_ms(ms);
ADCON1 = 0x07;
}
}
This project is risky because you are allowing mains power to contact your device which is meant for low voltage.
Did you test that a low DC voltage can be read across the 100 uF capacitor? Does your meter show any AC component?
Did you test your pic with a stable DC voltage, to make sure it can convert analog volt levels?
Your project has several parts to it. Right now you must test each part, and make certain each is doing a reliable job. Later you can combine the separate sections.
Sorry, I am not familiar with pic programming, so I am of little help with your code.
the LCD displays constantly and swiftly changing values form -128 to +127 but didn't display the true and fix value.
In binary these values are 11111111 and 01111111. (Zero is in the middle.)
I believe your display shows the least significant byte. It suggests that your values are really much larger. Is the variable dimensioned to occupy one or two or four bytes?
Then there is the issue that the value is changing rapidly. It should be DC.
So it seems that AC must be getting into the circuitry somehow. Perhaps it is because mains AC is connected. Even if you connected a high resistance at each incoming wire, there is still a chance the high voltage has enough effect to create unstable readings.
You may end up needing to use a step-down transformer.
you mean voltage values must be too small to apply to the micro? i applied less then one volt to micro.... should it be in milivolts?
here situation is that if i turn the resistor to provide 0V to the micro's pin i.e; ground it... still it shows variable values...
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?