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 1rintf(lcd_putc,"\f30%%");
break;
case 2rintf(lcd_putc,"\f29%%");
break;
case 3: printf(lcd_putc,"\f28%%");
break;
case 4rintf(lcd_putc,"\f27%%");
break;
case 5: printf(lcd_putc,"\f26%%");
break;
case 6rintf(lcd_putc,"\f25%%");
break;
case 7: printf(lcd_putc,"\f24%%");
break;
case 8rintf(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
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 1rintf(lcd_putc,"\f30%%");
break;
case 2rintf(lcd_putc,"\f29%%");
break;
case 3: printf(lcd_putc,"\f28%%");
break;
case 4rintf(lcd_putc,"\f27%%");
break;
case 5: printf(lcd_putc,"\f26%%");
break;
case 6rintf(lcd_putc,"\f25%%");
break;
case 7: printf(lcd_putc,"\f24%%");
break;
case 8rintf(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