Picproje Elektronik Sitesi

DERLEYİCİLER => CCS C => Konuyu başlatan: necati - 22 Ocak 2012, 11:23:22

Başlık: Frekansmetre
Gönderen: necati - 22 Ocak 2012, 11:23:22
Nicin 1Mhz den fazlasını sayamiyorum
http://www.4shared.com/rar/fB4ddlVG/Frekansmetre.html
#include <18f252.H>//mindar hayvan kovucu için 20khz 30khz frekansmetre
#use   delay(clock=4000000)//16f876 dac4921 lm331 tda1050 Tweeter
#fuses NOPROTECT,NOWDT,PUT,noBROWNOUT,noLVP,xt
/***entegreterbiyecisi@yahoo.com***/
// LCD STUFF
#define LCD_RS      PIN_b0
#define LCD_EN      PIN_b1
#define LCD_D4      PIN_b2
#define LCD_D5      PIN_b3
#define LCD_D6      PIN_b4
#define LCD_D7      PIN_b5
#define FIRST_LINE  0x00
#define SECOND_LINE 0x40
#define CLEAR_DISP  0x01
#define CURS_ON     0x0e
#define CURS_OFF    0x0c
/***entegreterbiyecisi@yahoo.com***/
#use standard_io (a)
#use standard_io (b)
#use fast_io     (c)
/***entegreterbiyecisi@yahoo.com***/
// proto statements
void LCD_Init        ( void );
void LCD_SetPosition ( unsigned int cX );
void LCD_PutChar     ( unsigned int cX );
void LCD_PutCmd      ( unsigned int cX );
void LCD_PulseEnable ( void );
void LCD_SetData     ( unsigned int cX );
/***entegreterbiyecisi@yahoo.com***//***entegreterbiyecisi@yahoo.com***/
/*************************entegreterbiyecisi@yahoo.com******************************/
int32 ab=0;
float hz=0,khz=0,mhz=0;
int1 aa=0;
int32 sayi=0,tr=20;
/*************************entegreterbiyecisi@yahoo.com******************************/
#int_timer1 //1sn gelen pals lari say
void tas(){
ab++;
}
#int_timer0 //1sn uret
void sn(){
set_timer0(15591);//(65535-15591)*20=1000000us=dahili 1sn icin
if(tr){ tr--;}
else{
      disable_interrupts (global);
      disable_interrupts(int_timer0);
      disable_interrupts(int_timer1);
      sayi=get_timer1();
      hz=(float)(65536*ab)+sayi;
      tr=20;
      output_bit(pin_a0,0);
      aa=1;
                              }}
/*************************entegreterbiyecisi@yahoo.com******************************/
   void   main() {

      setup_timer_1 (t1_external|t1_div_by_1);
      setup_timer_0 (RTCC_INTERNAL|RTCC_DIV_1);//16bit
      enable_interrupts(int_timer0); // timer0
      enable_interrupts(int_timer1);
      enable_interrupts(global);
      lcd_init();
      SET_TRIS_A (0b00100000);
      SET_TRIS_B (0b11000000);
      SET_TRIS_C (0b11111111);
      set_timer0 (15600);
      set_timer1 (0);

      LCD_SetPosition(first_LINE+0);
      printf(lcd_putchar,"\NECATi KIYLIOGLU ");
      LCD_SetPosition(second_LINE+1);
      printf(lcd_putchar,"\ 0532 613 65 87");
      delay_ms (500);
      LCD_PutCmd ( CLEAR_DISP );
     
      LCD_SetPosition(first_LINE+1);
      printf(lcd_putchar,"\FREQUENCYMETER     ");
     
      sayi=0;
      hz=0;
/*************************entegreterbiyecisi@yahoo.com******************************/
while(true){
if(aa==1){
//////////////////////////////////////////////////////
if(hz<1000){
      LCD_SetPosition(second_LINE+1);
      printf(lcd_putchar,"\FRQ=%fHz            ",hz);
      delay_ms (500);}
//////////////////////////////////////////////////////     
if(hz>1000 && hz<1000000){
      khz=(float)hz*.001;
      LCD_SetPosition(second_LINE+1);
      printf(lcd_putchar,"\FRQ=%3.3fKhz          ",khz);
      delay_ms (500);}
//////////////////////////////////////////////////////
if(hz>1000000){
      mhz=(float)hz*.000001;
      LCD_SetPosition(second_LINE+1);
      printf(lcd_putchar,"\FRQ=%3.3fMhz            ",mhz);
      delay_ms (500);
      }
//////////////////////////////////////////////////////
      set_timer1(0);
      output_bit(pin_a0,1);
      enable_interrupts(int_timer0);
      enable_interrupts(int_timer1);
      enable_interrupts (global);
      aa=0;
      ab=0;
      //sayi=0;
      //hz=0;
      //khz=0;
      //Mhz=0;
      }
             }}
/***entegreterbiyecisi@yahoo.com***/ //lcd basla
void LCD_Init ( void ){
    LCD_SetData ( 0x00 );
    output_low ( LCD_RS );
    LCD_SetData ( 0x03 );   // init with specific nibbles to start 4-bit mode
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_SetData ( 0x02 );   // set 4-bit interface
    LCD_PulseEnable();      // send dual nibbles hereafter, MSN first
    LCD_PutCmd ( 0x2C );    // function set (all lines, 5x7 characters)
    LCD_PutCmd ( 0x0C );    // display ON, cursor off, no blink
    LCD_PutCmd ( 0x01 );    // clear display
    LCD_PutCmd ( 0x06 );    // entry mode set, increment
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_SetPosition ( unsigned int cX )
    {
    // this subroutine works specifically for 4-bit Port A
    LCD_SetData ( swap ( cX ) | 0x08 );
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );
    LCD_PulseEnable();
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PutChar ( unsigned int cX )
    {
    // this subroutine works specifically for 4-bit Port A
    output_high ( LCD_RS );
    LCD_SetData ( swap ( cX ) );     // send high nibble
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );     // send low nibble
    LCD_PulseEnable();
    output_low ( LCD_RS );
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PutCmd ( unsigned int cX )
    {
    // this subroutine works specifically for 4-bit Port A
    LCD_SetData ( swap ( cX ) );     // send high nibble
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );     // send low nibble
    LCD_PulseEnable();
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_PulseEnable ( void )
    {
    output_high ( LCD_EN );
    delay_us ( 100 );
    output_low ( LCD_EN );
    delay_ms ( 5 );
    }
/***entegreterbiyecisi@yahoo.com***/
void LCD_SetData ( unsigned int cX )
    {
    output_bit ( LCD_D4, cX & 0x01 );
    output_bit ( LCD_D5, cX & 0x02 );
    output_bit ( LCD_D6, cX & 0x04 );
    output_bit ( LCD_D7, cX & 0x08 );
    }
/***entegreterbiyecisi@yahoo.com***/ //lcd son




Başlık: Ynt: Frekansmetre
Gönderen: Kabil ATICI - 23 Ocak 2012, 11:22:07
Donanım ile ilgili sınırlamalar
http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf (http://ww1.microchip.com/downloads/en/DeviceDoc/39631E.pdf)
sayfa 349 üzerinde anlatılmış.
Daha yüksek frekans için harici entegreler ile ön bölücü kullanarak yapabilirsin. Bu kadar yüksek frkanslarda  bir kaç Hz ölçüm hatası kabul edilebilir.
Başlık: Ynt: Frekansmetre
Gönderen: Erol YILMAZ - 23 Ocak 2012, 12:29:19
Sinyal, Timer1'e girerek 50 mhz e kadar ölçmek mümkün diye biliyorum.

Geçen gün arkadaşım aynı yöntemle 25 Mhz sinyali saydırdı gördüm....

Timer1 taştıkça da başka bi 16 bit lik değişkeni artırıyordu kısaca...

Güncelleme :
Sizin probleminiz  SENKRON sinyal girişi olabilir mi ?

4 Mhz clock frekansınız bunu destekliyor....