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.

Swirch casr issue and period conversion using ccp1 and timer for high frequency

Status
Not open for further replies.

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Activity points
0
hello every body,I am trying to red the period of a given signal and then take decision basing on the period reads,but with period of frequency between 100Khz and 1000Khw (1Mhz) there is no problem but for frequency above 1Mhz the system is reading the same as some of the frequencies I held in the range of 100KHZ to 1000KHz;I think the problem is conversion can you plz help me to convert those period so that for example
100Khz has a period of 100ms
1000Khz has a period of 10ms
1200ms might have a period of 8.5ms;but it shows on the lcd 17ms and this is period of 560Khz so I want to print on the lcd the real period
1400ms might have a period of 7.1ms;but it shows on the lcd 14ms


I am using PIC16F877A with ccs c compiler and lcd 16*2

see some of my codes:
#include <16F877A.h>
#DEVICE ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "lcd.c"

void tempdisplay();
void kagaba();
void messagedisplay();


int1 flag;
float voltsf,MR;
float rise1, rise2;
int period;
unsigned int adc_value, volts;


#int_ccp1
void isr()
{
if (flag==0)
{
rise1 = CCP_1;
flag=1;
}
else if (flag==1)
{
rise2 = CCP_1;
period=(rise2-rise1);
if(period<10)
{
period=period/2;

}
flag=0;
}
}

void tempdisplay()
{
//volts = 0;
adc_value = read_adc();
volts = ((float)(adc_value * 500)/1023.0);
delay_ms(10);

// voltsf = volts/5;
voltsf=(volts*1.8)+32;

}

for taking decisions see below:
while(true){

if(input(PIN_B4)==0)
{
tempdisplay();


switch(period){

case 1:printf(lcd_putc,"\f30%%");
break;

case 2:printf(lcd_putc,"\f29%%");
break;

case 3: printf(lcd_putc,"\f28%%");
break;

case 4:printf(lcd_putc,"\f27%%");
break;
case 5: printf(lcd_putc,"\f26%%");
break;

case 6:printf(lcd_putc,"\f25%%");
break;
case 7: printf(lcd_putc,"\f24%%");
break;
case 8:printf(lcd_putc,"\f23%%");
break;
case 9: printf(lcd_putc,"\f22%%");
break;


CCP1 and Timer1 configuration codes:

setup_ccp1(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16); // Configure CCP1 to capture rise
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // Start timer 1
enable_interrupts(INT_CCP1); // Setup interrupt on risining edge
enable_interrupts(GLOBAL);



delay_ms(300);
printf(lcd_putc, "\f%3.0d", period);
delay_ms(2000);


plz help.

Thanks
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#int_ccp1
void isr()
{
if (flag==1)
{
 
rise2 = CCP_1;
period=(rise2-rise1);
if(period<10)
{
period=period/2;
 
}
flag=0;
}
else if (flag==0)
{
rise1 = CCP_1;
flag=1;
 
}
flag=0;
}
}

 

Re: Swirch case issue and period conversion using ccp1 and timer for high frequency


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#int_ccp1
void isr()
{
if (flag==1)
{
 
rise2 = CCP_1;
period=(rise2-rise1);
if(period<10)
{
period=period/2;
 
}
flag=0;
}
else if (flag==0)
{
rise1 = CCP_1;
flag=1;
 
}
flag=0;
}
}


Hello man,this code is giving period =0.0

check I tested using proteus 7.7
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top