Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help for programming 16F877

Status
Not open for further replies.

MARWEN007

Junior Member level 2
Joined
Apr 16, 2011
Messages
24
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,481
Hi, I calculated the phase shift between two sine (50 Hz) and displayed on an LCD, I compile my prog on picc the problem is I can not calculate the phase shift for low frequency (0.05 Hz) had good results by cons for 50 Hz are obtained false values ​​of phase shift here is my source code and the diagram on isis
*

#include <16f877.h>
#device ADC=10
#fuses xt,nowdt,NOPROTECT,noput
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)
#include <lcd.c>
#include <math.h>


int32 n=0;


#int_timer0
void timer0_isr()
{
n++;
}


void main ()
{
int1 test_1, test_2;
//***********programme de dephasage******************//
//float a,b,c,e,f,g,R,X;
//float tens_max,courant_max,dephasage,Veff,Ieff ;

float temps, dephasage;
float tens_****_10,tens_****_1,tens_num_1,tens_num_2,tens_****_2,tens_****_20;
int8 Iter;
float Freq=10;

tens_****_10 = 0.1;
tens_****_20 = 0.1;

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
enable_interrupts(int_timer0);
enable_interrupts(GLOBAL);


disable_interrupts(int_timer0);
clear_interrupt(int_timer0);

setup_port_A(all_analog);
setup_adc(adc_clock_internal);


while(true)
{
while(!input(pin_C0))
{
test_1=1;
test_2=1;
set_adc_channel(0);
delay_us(10);

while(test_1==1)
{
tens_num_1 =read_adc();
tens_****_1 = (tens_num_1 *(0.0048876)*2)-5;


lcd_init();
printf(lcd_putc,"Tens1=%2.5f\r",tens_****_1);
//printf("T1=%2.3f\r",tens_****_1);

if ((tens_****_1>=0) && (tens_****_10<0))
{
set_timer0(0);
n=0;
clear_interrupt(int_timer0);
enable_interrupts(int_timer0);
test_1=0;
tens_****_10=tens_****_1;
//lcd_init();
//printf(lcd_putc,"Tens1=%2.5f\r",tens_****_1);
printf("Detected Tens1=%2.5f\r",tens_****_1);
}
else
{
tens_****_10 = tens_****_1;
}
}

set_adc_channel(1);
delay_us (10);

while (test_2==1)
{
tens_num_2=read_adc();
tens_****_2 = (tens_num_2 *(0.0048876))-2;

lcd_init();
printf(lcd_putc,"Tens2=%2.5f\r",tens_****_2);
//printf("T2=%2.3f\r",tens_****_2);

if ((tens_****_2>=0) && (tens_****_20<0))
{
Iter=get_timer0();
disable_interrupts(int_timer0);
clear_interrupt(int_timer0);
temps = 0.0000512*n+Iter*0.0000002;
dephasage =2*PI-((2*PI*Freq)*temps);
test_2=0;
tens_****_20=tens_****_2;

//lcd_init();
//printf(lcd_putc,"Tens2=%2.5f\r",tens_****_2);
printf("Detected Tens2=%2.5f\r",tens_****_2);
printf("temps=%3.5f\r",temps);
}
else
{
tens_****_20=tens_****_2;
}
}
lcd_init();
printf(lcd_putc,"Deph=%3.5f deg\r",dephasage*57.295779513);
printf("Deph=%3.5f deg\r",dephasage*57.295779513);
}
}
}


the isis diagram https://obrazki.elektroda.pl/8_1303829582.png
 

There'a lot of time consuming actions (LCD related, float arithmetic) interleaved with measurement and timer actions, I can't see, that these critical code parts are precisely timed.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top