Wednesday, August 5, 2015

100MHz frequency counter

Couple of weeks ago I purchased from eBay one of these amazingly cheap an useful modules with MAX7219 LED driver and 8 digit LED display. It is ideal for frequency counter project. The problem was the absence of library for PIC microcontrolers. Luckily, I found a great library for Arduino and I reworked it to be compatible with PIC. The schematic of the frequency counter is actually almost the same as the previous . It uses PIC16F628A microcontroller with external 32.768kHz watch crystal attached to Timer1 to generate 1 second time base. Measured signal is fed to pin3 (RA4) which is counted by Timer0.



The program make short (0.125s) test of the input signal to determine the prescaler value. Next is the actual counting with the proper prescaler value and then the result is send to the display.

This is fast breadboard proof-of-concept project, and I don't intend to make a finished product, for now at least. Of course there must be some sort of preamplifier/protection in front of the frequency counter in order to be usable.

In the pictures below is shown the breadboard and five different quartz crystals generating different frequencies. The differences between the value on the display and the value on the oscilloscope are negligible. I tested the schematic also with frequencies above 90 MHz and even above 100Mhz and the results was accurate, but of course most significant digit was lost in case of 100+ MHz.

Link for downloading the code and .hex files: LINK
The code is compiled with MikroC Pro. RA5/MCLR must be configured as I/O or if not there must be 10k resistor connected between RA5 and +5V. When programming the microcontroler with PICkit 3 the option "Tools/Use VPP First Program Entry" should be selected and the schematic should be disconnected from the power supply.







28 comments:

  1. Very interesting project. Unfortunately, problem with hex. by a file - a processor after programming stops to be identified. Does the respected author can to help? 73! Vitaly

    ReplyDelete
  2. I used the program PICkit 2 v2.61 and "native" device. After failure, I have tried to use homemade JDM with program "PonyProg2000", factory "Triton". The Process occurs so: comptroller successfully "is flooded", afterwards, in an effort consider appears the message "device is not identified or faulty". I used undoubtedly worker 628 3 items - result same. Dear Hristo, but what program and device use you?.Thank you. Respectfully yours, Vitaliy

    ReplyDelete
    Replies
    1. I use the same program and my programmer is DIY clone of PICkit2. You can try this:
      First, in the program set "VDD PICkit2" to 5V.
      Second, in "Tools" check the option use "VPP First Program Entry".
      These steps should help the program to recognize the chip.

      Delete
  3. Hristo, thank you for consultation. I shall without fall try your advice, but first want to try the processor from the other parties - beside me doubts about marking product from chinese "friends". I have done quite a few designs, but such - first once. Respectfully yours, Vitaliy

    ReplyDelete
  4. Христо, большое спасибо за помощь. Действительно,с включением "VPP First Program Entry" все "зашилось" нормально. Хочу добавить входной формирователь на полевых транзисторах. У меня уже собран ГСС на AD9850, с индикацией на модуле MAX7219. Частотомер на том же модуле, как мне кажется, хорошо будет смотреться на передней панели универсального прибора. Еще раз спасибо за программу и помощь. С уважением, Виталий.

    ReplyDelete
  5. Hi,Dear Histro
    I was Loaded Your Hex file in my pic but it process failure and the pickit2 programmer do not recognize my pic after that.
    Is my PIC dead?

    ReplyDelete
    Replies
    1. Sorry to hear that. I don't believe it's dead.
      Try this: In the Pickit2 click on the "Tools" menu and check the option "Use VPP first program entry". After this it should recognize the chip.

      Delete
  6. this HEX does not work .. When recording on pic 16f628 hangs everything.
    I tried to compile the source code also did not work.
    could anyone make this work?

    ReplyDelete
  7. Hello Christo and friends!I also faced a similar problem,but did not give up,and decided this way:I filled the hex file with the wxpic program and a homemade JDM programmer on the Com port of the computer.Tried this chip to fill a different program for the hours put into a finished product,it works! How the chip in this product will behave-I do not know,yet I have not soldered.For me, the main thing is that the chip works, the rest is done -I do not see any obstacles.But in the program there's something,some kind of muck which cuts the initialization,when administered manually, then everything is in order and the program automatically determine the chip.PonyProg not zalivaee PIC, although both programs are being put on Win10.Good luck to everyone!73!

    ReplyDelete
  8. Somehow it turned out badly,I did not introduce myself.Andrew, UB3PCO

    ReplyDelete
  9. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. что нужно изменить чтобы использовать другой кварцевый резонатор, например на 16 мГц

      Delete
    2. You can connect crystal resonator 16 MHz to RA6 and RA7, and the microcontroller will run faster, but if you want to use that frequency for the time base, then you should remove the 32768 Hz crystal and rewrite the code so Timer 1 to use the internal clock (Fosc/4). I am not sure what benefit will that change give you, but it can be done.

      Delete

  10. Quartz at high frequencies have temperature compensation, so the frequency meter will more accurately measure the frequency.

    ReplyDelete
    Replies
    1. Кварцевый резонатор не имеет температурной компенсации. Кварцевие генераторы имеют такую, но они очень большие и потребляют больше тока.

      Crystal resonator doesn't have temperature compensation - crystal oscillator might have (usually abbreviated TCXO) but these are bulkier and consume more power. These are indeed more accurate and if you want to build something serious you could use one of these, but the code will need some changes.

      Delete
    2. I understand that there is a division coefficient to get 1 hertz. What and where do I need to change?

      Delete
    3. I don't have time to rewrite the program. Feel free to do it if you want :)

      Delete
  11. Hi! #define _XTAL_FREQ 4000000, but in your project 32768...

    ReplyDelete
    Replies
    1. No, the microcontroller runs at 4 MHz, only Timer1 runs at 32768 Hz.

      Delete
    2. Христо, you have a picture on a drawing of a crystal 32768 Hz, in an asm - 4 MHz.

      Delete
    3. As I said, the microcontroller runs with its own internal oscillator at 4 MHz. ONLY TIMER1 RUNS AT 32768 Hz.

      Delete
  12. Hello! Does the firmware contain security bits?

    ReplyDelete