gebepic said:The internal oscillator is calibrated and has the calibration recorded .
A good programmer read the value before reprogramming and reestablishes it
If you have a factory programmer it will be so .
[code]
#include "D:\CURRENT_PROJECTS\UPS\pp676.h"
#define BttlowInd PIN_C5
#define RelayBttChrg PIN_C2
#define UPSLED PIN_C3
#define LEdWapda PIN_A4
#define PUSH PIN_C4
#define PULL PIN_C1
#define WapdaIn PIN_A5
#define Buzzer PIN_A3
#define FAN PIN_C0
#define BttCh 1
#define MainCh 0
int1 Flg,WapdaFlg=0,FlgChrg,FlgUps=0,chrgFlg=0,tflg = 0,jOflg = 0,shutFlg = 0,sflg=0,BFLG1=0,BFLG2=0,bFlg3=0;
int16 BttVolt,DelayTime,DTT=2400,Ltime=0,dt,chrgCounter=0,d,sCounter = 0,shutcounter=0,bcounter=0,blCounter=0;
INT8 BUZZFLG = 0;
void SetBttVolt(void);
void WapdaCheck(void);
void doWapdaAbsent(void);
void doWapdaPresent(void);
void SetDelayTime(void);
void doShutDown(void);
#int_TIMER1
void TIMER1_isr(void)
{
scounter++;
d++;
if((WapdaFlg==0) && (FLgUps==1)){ // WAPDA IS ABSENT BUT UPS IS WORKING DUE TO BATT VOLTAGE ABOVE 2.0
// printf("%ld,%ld\r",ltime,dtt);
if (LTime==0)
LTime = 1;
dt = dTT - 3000;
if(dTT >= 3000){
output_high(PUSH);
delay_us(dt);
}
output_low(PUSH);
delay_us(Ltime);
delay_us(100); //dead gap at end of c2
output_low(PULL);
delay_us(Ltime);
delay_us(100); //dead gap at end of c2
output_high(PULL);
delay_us(2000); // fix 5ms high time
delay_us(dT);
output_low(PULL);
delay_us(Ltime);
delay_us(100); //dead gap at end of c2
delay_us(Ltime);
delay_us(100); //dead gap at end of c2
output_high(PUSH);
}
else{
output_low(PUSH);
output_low(PULL);
}
set_timer1(63533); // fix 3ms delay
IF(BUZZFLG>0)
{
BUZZFLG--;
OUTPUT_HIGH(BUZZER);
bflg1 = 1;
bflg2 =1;
bflg3 = 1;
}ELSE{
OUTPUT_LOW(BUZZER);
bcounter++;
//printf("%ld\r",bcounter);
}
}
void main()
{
int16 i=0;
Flg = 0;
FlgUps=0;
WapdaFlg = 0;
set_tris_a(0b100011);
output_c(0);
output_low(pin_a2);
output_low(pin_a3);
output_low(pin_a4);
setup_adc_ports(sAN0|sAN1|VSS_VDD);
setup_adc(ADC_CLOCK_DIV_32);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
setup_comparator(NC_NC);
setup_vref(FALSE);
output_high(LEDWAPDA);
// output_high(UPSled);
//output_low(pin_a4);
If(!input(WAPDAIN)){
wapdaFlg = 1;
Flgups = 0;
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
}else{
wapdaFlg = 0;
Flgups = 1;
SetDelayTime();
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
while(d<100){
SetDelayTime();
}
}
/* for(i=10;i>1;i--){
SetBttVolt();
WapdaCheck();
if (WapdaFlg){
doWapdaPresent();
}else{//if waPDA IS ABSENT
doWapdaAbsent();
}
delay_ms(1);
Ltime = 2400;
dTT = 5000;
}*/
while (1){
SetBttVolt();
WapdaCheck();
if(shutFlg == 0){
if (WapdaFlg){
doWapdaPresent();
bflg1=0;
//bflg3=0;
}else{//if waPDA IS ABSENT
doWapdaAbsent();
bflg2=0;
}
}else
{
doShutDown();
}
SetDelayTime();
}//while
}
void SetDelayTime(){
int16 t;
INT16 Tempf;
set_adc_channel(MAINCH);
delay_us(20);
t = read_adc();
If (t <= 327){ // 1.0v for 9.8ms pulse
DelayTime = 9800;
}Else if (t >= 491){ // 2.0v for 3.0ms pulse
DelayTime = 3000;
}Else{
t = 491 - t;
TempF = t * 41; // conversion for 245 to 6800ms
DelayTime = 3000 + TempF;
}
DTT = DELAYTIME;
LTIME = (9800 - DTT)/2;
// printf("%ld\r",dtt);
}
void WapdaCheck(){
If(!input(WAPDAIN)){ // 'Wapda present
while( d < 100 && !input(WAPDAIN)){
// printf("%ld\r",d);
}
if(d>=100){
WapdaFlg = 1;
flg = 0;
output_low(PUSH);
output_low(PULL);
output_Low(BttLowInd);
output_LOW(LedWapda);
shutFlg = 0;
d=101;
// printf("-----------0\r");
}
}Else{
WapdaFlg = 0;
d=0;
output_Low(RelayBttChrg);
output_HIGH(LedWapda);
output_low(FAN);
// printf("-----------1\r");
}
}
void SetBttVolt(){
set_adc_channel( BTTCH );
delay_us(20);
BttVolt = read_adc();
}
void doWapdaAbsent(){
if(bflg1==0)
{
buzzflg = 500;
}
jOflg = 0;
chrgcounter=0;
output_Low(RelayBttChrg);
output_LOW(UPSLED);
output_high(FAN);
chrgflg = 0;
chrgCounter=0;
FlgUps = 1;
// printf("-----------b\r");
If (BttVolt < 368){ // 'Battery is too low. At 10v (on ADC 1.8) shutdown UPS
shutcounter++;
if(shutcounter>100){
shutcounter=0;
output_HIGH(UPSLED);
output_low(buzzer);
shutFlg = 1;
}
}else if(BttVolt < 409 ){ // '21v (on ADC 2.1v) Low battery indication
blcounter++;
if(blcounter>100){
blcounter=0;
output_high(BttLowInd);
shutcounter=0;
if(bflg3==0)
{
buzzflg = 500;
bcounter = 0;
}else if(bcounter > 1000)
{
bcounter=0;
bflg3=0;
}
}
}else{
shutcounter=0;
blcounter=0;
}
}
void doWapdaPresent(){
if(bflg2==0)
{
buzzflg = 250;
}
output_High(UPSLED);
// printf("-----------c,%ld\r",bttvolt);
If (BttVolt > 572){ // 'Voltage exceeds 27v (on ADC 2.7v) then cut charging
output_Low(RelayBttChrg);
output_low(FAN);
chrgflg==0;
}
Else If (BttVolt < 491 && joFlg ==1 ){ // 'Voltage 12v when charging starts
output_High(RelayBttChrg);
output_high(FAN);
output_low(BttLowInd);
chrgflg=1;
}Else If (BttVolt < 572 && joFlg ==0 ){ // 'Voltage 26v when charging starts
chrgCounter++;
// printf("**chc = %ld\r",chrgCounter);
if(chrgflg==0 && chrgCounter>10000){
output_High(RelayBttChrg);
output_high(FAN);
output_low(BttLowInd);
chrgFlg=1;
jOflg=1;
chrgcounter=10001;
}
}
}
void doShutDown(){
FLgUps=0;
jOflg = 0;
chrgcounter=0;
shutcounter=0;
if(sflg == 0 && scounter > 100)
{
output_high(bttLowInd);
scounter = 0;
sflg = 1;
//printf("-----------\r");
}else if(sflg == 1 && scounter > 100){
output_low(bttLowInd);
scounter = 0;
sflg = 0;
// printf("***************\r");
}
}
The above is the complete code for a ups opreation.
But my questin was bit general in a sense that may be
1 - I dont know how to use internall oscilator or How to calibrate it.
2 - If i use Timer1 interrupt to generate fixed interval interrupt for generating 50Hz flip folp pulses. Is it possible in 16f676 with internall oscilator or not.
Because
3- I have used the same code in 16f877a with external crystal oscialator and results are seme with evey chip, But this is not the case while is use 16f676 and internall oscillator. So where i am doing wrong.
dani said:gebepic said:The internal oscillator is calibrated and has the calibration recorded .
A good programmer read the value before reprogramming and reestablishes it
If you have a factory programmer it will be so .
My programmer alway asks me to write 34 hex value for calibration. and not any other value i donot know why.
dani said:Sory to bother you again, but sir i am still unable to figure out the solution.
If writing 0x34 is destroying the factory value, what to write then. If read before programming the chip then it gives 34 thats why i write 34.
If i get fresh chip without code and i read the calibiration what should i get, and should i write that value every time or this value will be new every time depending upon the configuration fuese.
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?