New to PIC, wish to build 3 offset freq counter - Page 1
Forum section: electronics / general

author: Wallace Gasiewicz
author_rank: Super Contributor
timestamp: September 07, 2023, 08:36:27 pm
content: I would like to make a 5 digit freq LED counter with three offsets, USB, LSB and AM for an HF receiver. Highest Displayed Freq would be 30 MHz Highest IF freq input would be less than 20 MHzI do need three offsetsI have seen these counters with one or two offsets. Some of the programs are available and can be used as base program to be modified.I have :a Minipro 866 that I have used for EPROM reprogramming. My hacking of existing EPROM went very well.Several PIC chips including the 16F628, 18F and others including PIC16C57 UV erasable chips.A cheap PIC programming board, don't know if it is even necessary having the Minipro?Various osc and xtals.Most of this stuff was given to me and I would like to see if I can make the freq counter out of my junk.Any advice on where to start? What software program to use?I use an old Win 7 computer for my EPROM stuff and I also use it for PCMCIA cards so I would like to stay in Win 7 land if possible. This computer is kinda dedicated to the Minipro and to Telnet and especially the PCMCIA cards since it has a PCMCIA slot.

author: gnuarm
author_rank: Super Contributor
timestamp: September 07, 2023, 08:44:52 pm
content: I'm not completely clear on what you are trying to do. I know what a frequency counter is, but I'm not familiar with "offsets" being applied. Are you saying you want to measure a frequency, then add or subtract some amount before displaying the number? Maybe someone else can help you with that?Measuring frequencies up to 30 MHz might be difficult with a PIC. They typically don't run very fast, but they often contain counters, which can run faster. Still, you would need to check the data sheet to see how fast the input to a counter can be.You have posted a question about using a PIC in an FPGA group, so maybe you are thinking of using a programmable logic device for this. I know some people call all MCUs "PICs" and maybe you are referring to the FPGA as a PIC?Programmable logic would be a much better candidate to do this job. They will easily run at 30 MHz. Have you worked with programmable logic before?

author: Wallace Gasiewicz
author_rank: Super Contributor
timestamp: September 07, 2023, 09:17:22 pm
content: I thought a PIC might be appropriate to talk about here, maybe I was wrong.You are correct, The freq counter counts the VCO freq which is less than 20 MHZ and then adds another freq, in this case the "carrier" which is minimally different in USB, LSB and AM, this is the number to be programmed in as an "offset". The only freq input is the VCO, the chip just has to be able to add three different set numbers to this by using three different inputs which are just hi lo. Probably three different pins.The PICs I have are used by others for this purpose quite nicely. In other words. the program is out there for the PIC free but just does not meet one of my needs, three different offsets.If another chip would be appropriate, I would be willing to try.I do have some other chips that are MCUsI have not done any real programming since 1969, Fortran 4, had to learn it myself, the profs at Uni did not know much. I then dropped out of engineering to other studies.Maybe a little Basic since then.

author: Ian.M
author_rank: Super Contributor
timestamp: September 07, 2023, 09:58:47 pm
content: Most PIC18 chips can accept up to 50 MHz clock on T0CKI, even though their Fosc (core clock) is significantly lower. With the addition of a fast D type flipflop with set and clear inputs (also needed to guarantee 50% duty cycle at T0CKI), its reasonable simple to implement a hardware gated 100MHz frequency counter.Seehttps://www.microchip.com/en-us/application-notes/an592for the principle of clocking through the count 'stuck' in the timer 0 prescaler at the end of the gate time by pulsing T0CKI.Windows 7 isn't an issue if you are using an older PIC (released at least a couple of years before Win7 EOL), as older IDEs and toolchains can be downloaded from the Microchip archives. If the old PC is a bit lacking in resources try to stick to PICs supported by MPLAB 8, as early releases of MPLAB X were a dog on underpowered PCs.

author: gnuarm
author_rank: Super Contributor
timestamp: September 07, 2023, 10:03:03 pm
content: I don't know enough about your radio stuff to understand what you are trying to do. If you want to measure the VCO frequency, what will be your reference frequency? Then it sounds like you want to add in some number before displaying the result.How do you plan to actually measure the VCO frequency? Do you understand how to do that?

author: Wallace Gasiewicz
author_rank: Super Contributor
timestamp: September 07, 2023, 11:05:48 pm
content: The commonly available PIC counters use a program that measures the input freq. They also use an external xtal oscillator as a reference rather than the PICs internal oscillator. You can buy the whole thing for $10. Including the LED. These things can have a provision for adding the "offset" but not having three offsets controllable by a switch. Commonly radios have a control signal that turns on stuff in the radio, obviously this signal goes different places in AM, Upper Side Band and Lower. The VCO freq is common to all Modes and the other Freq the "offset" is different in each different Mode, but only slightly. I could use these DC signals to switch the "offset" In Rx the radio does not generate the received frequency anywhere that can be directly measured, so you have to add the frequencies used yourself to get the working freq. There may be other modes in a radio, I am not worried about that now, I might just buy one of these ebay things and see if there is a way to get the three aforementioned offsets into the PIC.Just wanted advice on what program to use to manipulate the PIC so I could see if it is possible to add the customization I wish. The big problem I see is that there are not enough available pins left to put in three different "offsets"Here is a link to one of these gadgets:https://www.qsl.net/dl4yhf/freq_counter/freq_counter.html

author: BrianHG
author_rank: Super Contributor
timestamp: September 07, 2023, 11:36:08 pm
content: It sounds like someone who has 0 microcontroller programming experience is asking if the first project hey may do is a frequency counter. There is nothing wrong with the specs he laid out, the pic can do it as long as he input counting frequency is below the PIC's maximum allowable rate, 20 MHz on the simple PIC16xxx/PIC18xxx ones.So now, can he do it himself? Does he have the tools? I would say at least a scope and regular frequency counter would help. He will also need a PC with any windows from 7 and up, or even older windows if he wants to use an old version of MPLab.Also, besides using the RTC input pin, he may think about PICs with a timer capture and compare input.He will also have have to learn about interrupts and how to drive a seven segment displays, multiplexed, how to time and refresh them.He will also need to use binary to BCD conversion.Doing these things 1 step at a time, it is a possible hurdle to accomplish.

author: jpanhalt
author_rank: Super Contributor
timestamp: September 08, 2023, 07:24:33 am
content: I have an early morning trip to run off to and won't be back until Monday. I looked at the QSL link and notice it uses quite an old (16F628) chip. I did a 17-bit (to get 99,999 decimal) counter several years ago on a more recent 8-bit chip and would like to take a stab at this, but I don't have time.I did not see the code used by the author of that link. Can you post a direct link to it or tell us where it is in the article. I am very short of time right now.John

author: gnuarm
author_rank: Super Contributor
timestamp: September 08, 2023, 10:37:30 am
content: Quote from: Wallace Gasiewicz on September 07, 2023, 11:05:48 pmWhat is the output of these programs? When you say "measure", I expect it will produce a digital number. Is that correct?QuoteSo, you will have how many oscillators in YOUR design?QuoteWhat is the nature of this control signal? Is it a DC signal with different voltages for each of the settings? Is this an input to the radio from the device you are building, or an output from the radio to the device you are building?QuoteWhat DC signals??? Are you talking about separate signals for AM, USB and LSB?QuoteSorry, I have no idea what you are talking about. I thought you were measuring the VCO frequency???QuoteBy all means tell us about the parts you have no interest in. But first, tell us about the parts youareinterested in!Here's an idea. Stop telling us all the details of your radio. Just describe the device you want to build. We don't need to know all the details of what the radio does. We just need to know...Inputs...Outputs...What it does between inputs and outputs...Everything else is just going to confuse the issue.QuoteHere's a question. Why are you posting this in an FPGA group?

author: Wallace Gasiewicz
author_rank: Super Contributor
timestamp: September 08, 2023, 12:13:16 pm
content: Maybe this is the wrong place to post. Perhaps I will find help elsewhere.To attempt to answer some questions here is what I am attempting to build (I already linked this)https://www.qsl.net/dl4yhf/freq_counter/freq_counter.htmlThisunit uses 7 segment LEDs for readout, others use common LCDs. I would like to use the version with 5 LEDs.Here is a link with LOTS of other links to the code:https://github.com/StarNiell/PIC16F628A_AS_DL4YHF.XThe unit Measures one frequency (the VCO Freq), uses one oscillator (different people have implemented different oscillator frequencies) and then can add or subtract numbers (offsets) to come up with the actual frequency being received by the radio. This is very common in modern radio design and these units were built by amateurs to get a digital readout of old radios and project radios that did not have digital readouts. This design uses the PIC and can be also a stand alone freq counter. Modern radios use other chips that are integrated into the other functions of their products. The process of getting to the displayed frequency is similar.I wish to implement this build and accommodate three different offsets. In other words the displayed freq would be the VCO + offset, but I want to be able to use a switch (some sort of input) to change the offsets to one of three set numbers. In my case the radio has easily accessible DC voltages (about 8 V) that can be used to indicate the different offsets.The "offsets" represent another oscillator in the radio that is "set" to three freq that only differ a little. Plus 1.5 KHz for USB, Minus 1.5 KH for LSB and the center AM Freq.Again, these offsets are not freq inputs but just numbers. They do vary from radio to radio.I cannot find a unit that has the capability for three offsets. Current units let you plug in offset from a table,Just wanted some advice on what computer program to get to manipulate the existing code and wondering if there were any suggestions about implementing my wish for three different offsets in the PIC. Again perhaps I am in the wrong place. Thank you for your time.

author: gnuarm
author_rank: Super Contributor
timestamp: September 08, 2023, 12:33:52 pm
content: Quote from: Wallace Gasiewicz on September 08, 2023, 12:13:16 pmIf you are asking about a tool for programming the PIC, why are you telling us the life history of the design??? You could have eliminated everything in your post up to the final paragraph. The more you tell us about the project, the less we know about the actual problem you wish to solve. Sometimes the problem is a lack of information about a project, but in this case, the additional information is irrelevant and distracting. Just provide the MCU part number and ask your question about the programming tools.This is an FPGA group. Many people here also know about programming MCUs. But why not post this thread in the MCU area here???

author: Ian.M
author_rank: Super Contributor
timestamp: September 08, 2023, 01:16:41 pm
content: The original DL4YHF code was written for Microchip MPASM assembler, which was bundled with MPLAB 8 and older MPLAB X versions. (IIRC MPASM support was dropped from MPLAB X as of v 5.40). The link to Antonio's (StarNiell's) Github you provided is a version ported to pic-as, the XC8 assembler, and will require a recent MPLAB X and XC8 installed, neither of which are likely to run well, if at all on a legacy Win7 PC. IMHO ignore Antonio's port, which adds very little functionality, install MPLAB v8.92:https://ww1.microchip.com/downloads/en/DeviceDoc/MPLAB_IDE_8_92.zipand base your version on the code from DL4YHF's site or one of the links he provides to others' versions of his counter from 2018 or earlier.However the PIC16F628 is a very old 18 pin PIC, without an ADC, so freeing up enough pins to encode three different offset selections would be difficult - the original design even had to resort to a diode/transistor NAND gate to drive the fifth digit's cathode. (If it had an ADC, you could use a resistor ladder to encode the offset selection as an analog level on a single pin.)How experienced are you with PIC assembler? Are you good enough to port the code to a PIC with more pins? e.g. the PIC16F883,(which has 28 pins (24 I/O pins), more RAM, twice the program memory and is debug capable under MPLAB 8 with a PICkit 2 or 3)to allow you to simplify the automatic offset selection by having an individual select pin for each stored offset.Personally I no longer regard rooting around in other's MPASM assembly code (even if very well commented) as a worthwhile use of my time. The price of larger faster MCUs has dropped so much that for one-off or small run projects, if the code need more than minor tweaks, its cheaper, quicker, and easier to re-implement the algorithm in C, on a sufficiently more capable MCU to get comparable performance.N.B. Microchip dropped MPLAB 8 compatibility from the 8 bit PIC C compiler XC8 as of v1.34. There is a workaround for later XC8 v1.xx:https://forum.microchip.com/s/topic/a5C3l000000MRNlEAO/t335317but by the final v1.45 they'd also stripped the required MPLABXC8.dll. Don't even think about using any XC8 V2.xx version under MPLAB 8!

author: gnuarm
author_rank: Super Contributor
timestamp: September 08, 2023, 01:32:51 pm
content: No ADC is required to encode three choices. One pin, with a resistive pull up for USB, a resistive pull down for LSB and left open otherwise, gives three choices. The MCU alternately pulls the pin up, releases it and measures it after a short time (probably requires no actual delay, other than reading the pin). Then pull down, release and measure after a short time. If the MCU driven state remains in both cases, that's the open circuit (AM). If the pin goes low in both cases, that's LSB. If the pin goes high in both cases, that's USB.One pin, three values. No hassle. You just need a pair of resistors and maybe transistors, depending on what the drive circuit is like.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: September 08, 2023, 08:25:06 pm
content: QuoteThere seems to be a lot of prior art, so find some that is close,and modern, and with source code you can understand.Post #11 is great advice.Old tool chains have their own 'creepage' problems, so you want to find somethingactive in 2023, and with source code you can understand.If code already has two offsets, it should not be hard to modify that to do 3 offsets.Do not focus too much on 'PIC', eg maybe someone has done this on Pi PICO ?Addit : here for example, on this website !https://www.eevblog.com/forum/projects/pico-frequency-counter-using-rp2040/

author: jpanhalt
author_rank: Super Contributor
timestamp: September 10, 2023, 07:32:46 pm
content: Quote from: Wallace Gasiewicz on September 08, 2023, 12:13:16 pmPerhaps it is...I refuse to waste half an hour or more messing with github to find the code you reference. All of the code I currently write is with MPASM MPLab 8.92. Good luck.