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

EX_FREQC.C maximum frequency

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



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

EX_FREQC.C maximum frequency
PostPosted: Mon Jan 23, 2017 3:55 pm     Reply with quote

Hi,

I'm trying to understand EX_FREQC.C example. What is the maximum frequency that can be measure and how to make it measure 1GHz frequency.


Code:


#include <16F877.h>
#fuses HS,NOWDT,NOLVP
#use delay(clock=20000000)    //one instruction=0.2us
#use rs232(baud=9600, xmit=PIN_c6, rcv=PIN_c7)
#bit t1_overflow=0x0C.0

// #bit t1_overflow=0xF9E.0  (PIC18, Reminder)

void main() {
   int cycles8, cycles;
   int32 freq;
   long freqc_high;
   long freqc_low;

   while (TRUE) {
      cycles8=0;
      cycles=0;
      freqc_high=0;
      t1_overflow=0;
      set_timer1(0);
      setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);
/* ___ wait one second ___  */
      while (cycles!=0xFF) { //true=3, false=4
       cycles8=0; //1 cycle
       //start inner loop
       while (cycles8!=0xFF) { //true=3, false=4
         if (t1_overflow)//true=2,false=3             //----|
            {t1_overflow=0;freqc_high++;}//6 cycles   //    |
         else                                         //    |-- 8 cycles
            {delay_cycles(5);}                        //----|
         delay_cycles(62); //x
         cycles8++; //1
 ///2 cycles to jump to top
 //math: end inner loop
 //math: total inner loop=((3+8+x+1+2)*255 + 4)*255
 //math: if x=62.87781 then inner loops takes 5mil instructions
 //math: if x=62 then inner loop takes 4942920, have to fill 57080 cycles
  }
 delay_cycles(216);      //y
 cycles++;          ///1 cycle
 ///2 cylces to jump to top
 //math: outer=(3+1+y+1+2)*255+4=57080
 //math: y=(57080-4)/255)-(3+1+0+0+1+2)
 //math: if y=216.827450980392156862745098039216 then outer loop cylces is 57080
 //math: if y=216 then outer loop cycles is off by 211 cycles.  z=211
}
      delay_cycles(211);   //z
/* ___ end waiting 1 second ___ */
      setup_timer_1(T1_DISABLED);   //turn of counter to prevent corruption while grabbing value
      if (t1_overflow)            //check one last time for overflow
          freqc_high++;
      freqc_low=get_timer1();      //get timer1 value as the least sign. 16bits of freq counter
      freq=make32(freqc_high,freqc_low);   //use new make32 function to join lsb and msb
      printf("%LU Hz\r\n",freq);      //and print frequency

   }
}

PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 23, 2017 4:37 pm     Reply with quote

art wrote:

how to make it measure 1GHz frequency.

Before you get too far in this, you need to look in the Electrical
Characteristics section of the PIC data sheet. For the 16F877, it is called:
Quote:
TABLE 15-4: TIMER0 AND TIMER1 EXTERNAL CLOCK REQUIREMENTS

Then you look at "T1CKI input period, asynchronous". That's the Timer1
external input signal period. It lists 60 ns, minimum period. Take the
reciprocal of that to get the frequency and you get 16.666 MHz max input
frequency. That's not even close to 1 GHz. PICs can't accept 1 GHz input
signals.
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Mon Jan 23, 2017 7:22 pm     Reply with quote

Hi PCM,

Thank you very much PCM for the guidance. I've just check on PIC18 series, the minimum period is also same 60ns. So, I have to think to use other method to measure 1GHz signal instead of using PIC.

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 24, 2017 6:07 am     Reply with quote

The EASY easy to get a PIC, almost any PIC to read such high frequencies is to use a 'prescaler' chip between the input signal and the PIC. This prescaler is just a chip that divides the input down to say 1/64th the input frequency. Same principle as the prescaler inside the PICs for timers and counters.
Now, the HARD part.... to accurately measure any and all frequencies about a few KHz , you MUST use proper RF designs ! PCB layout, power supply, shielding, etc. ALL must be 100% according to the 'book'.
You cannot just slap some parts onto a perfboard like you do for a PWM LED project, this counter WILL require 'attention to details'.
Breakdown the project into smaller sections. Start with getting a PIC to capture and display a 1MHz signal, then 10MHz. Several PICs can do this. Then source out a 'prescaler' that will convert 1GHz down to 10MHz.


Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Wed Jan 25, 2017 2:46 am     Reply with quote

Do a web search for SAB6456.
This is a Phillips prescaler for VHF tuners. I've used it with a PIC some time ago to make a system able to measure frequencies up to 1GHz.
Beware that it will oscillate if there is no input.
In /64 mode, it is ideal. Brings 1GHz down to just under 16Mhz.
art



Joined: 21 May 2015
Posts: 181

View user's profile Send private message

PostPosted: Wed Jan 25, 2017 7:38 am     Reply with quote

Hi Ttelmah,

I've just such SAB6456 and i found a very nice webpage about 1Ghz counter at:
http://www.pira.cz/counter.htm

Thanks Ttelmah and others for the ideas.
Ttelmah



Joined: 11 Mar 2010
Posts: 19551

View user's profile Send private message

PostPosted: Wed Jan 25, 2017 8:57 am     Reply with quote

The current version of the chip can go to 2.5GHz if I remember correctly. Smile

Now you have the fun of learning about just how difficult VHF layout can at times be...
temtronic



Joined: 01 Jul 2010
Posts: 9246
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jan 25, 2017 9:35 am     Reply with quote

That chip can either /64 or /256 ! Based on the MC pin info on the datasheet.
Layout is CRITCAL ! Encased in mumetal would be nice though.


edit. that circuit uses the /256 option allowing a 4MHz PIC to be used !

Jay
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