CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

help with frecuency meter

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
carlos barillas
Guest







help with frecuency meter
PostPosted: Thu Jan 11, 2007 5:57 pm     Reply with quote

hello. i trying to make a frecuency meter in ccs
i want to measure from 1Hz to 15Mhz. i create all this code but the lcd show me a wrong result....
some commentaries are in spanish because i`m from venezuela.
thanks for all....
-------------------------------------------------------------------------------------

#include "C:\dise�o pic\ejercicios\sistemas_2_frecuencia.h"
#byte ccpr1l=0x15 // definimos como variable de 8 bits la parte baja dell ccp1
#byte ccpr1h=0x16 // definimos como variable de 8 bits la parte alta dell ccp1+
int seg[19]={0x3F,0x6,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,
0x39,0x5E,0x79,0x71,0x54,0x79,0x50};
float periodo;
int16 frecuencia, unidad, centena, decena, time;

#int_CCP1
CCP1_isr()
{
*(&time)=ccpr1l;
*(&time+1)=ccpr1h;
periodo=(time*.000008); // 8micros tarda el timer en incrementarse y
//dividimos entre tres para octener un solo periodo ya que cada cuatro flancos pasan tres ciclos de onda=tres periodos
frecuencia=(int16)(1.0/periodo);
set_timer1(0);
}

void main()
{
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);// Si dividimos entre 8 el overflow seria a 524.288ms, verificar lo siguiente:
//1/524.288ms= 1.9 Hz si queremos medir desde un herz el periodo debe ser de un segundo
setup_ccp1(CCP_CAPTURE_RE); // capturamos cada cuatro flancos de subida lo que nos daria el periodo de tres ciclos completos
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);

while(1)
{
/////////////////////// Para Mostrar frecuencias//////////////////////////////

output_low(pin_d0), output_high(pin_d1), output_low(pin_d2), output_low(pin_d3);
centena=frecuencia/100;
output_b(seg[centena]);
delay_ms(5);
output_low(pin_d1),output_low(pin_d2),output_low(pin_d3);

output_high(pin_d2);
decena=((frecuencia-centena*100)/10);
output_b(seg[decena]);
delay_ms(5);
output_low(pin_d1),output_low(pin_d2),output_low(pin_d3);

output_high(pin_d3);
unidad=(frecuencia-centena*100-decena*10);
delay_ms(5);
output_low(pin_d1),output_low(pin_d2),output_low(pin_d3);
}

}

----------------------------------------------------------------------------------
end
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group