{"id":21244749,"url":"https://github.com/bjorng/avr-frequency-counter","last_synced_at":"2025-03-15T04:25:49.709Z","repository":{"id":22093370,"uuid":"25423152","full_name":"bjorng/avr-frequency-counter","owner":"bjorng","description":"Frequency counter software for an Atmel ATTiny84A micro-controller.","archived":false,"fork":false,"pushed_at":"2014-10-30T06:45:55.000Z","size":160,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-21T20:12:51.525Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bjorng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-19T09:49:56.000Z","updated_at":"2021-12-05T14:39:50.000Z","dependencies_parsed_at":"2022-08-19T05:10:06.700Z","dependency_job_id":null,"html_url":"https://github.com/bjorng/avr-frequency-counter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorng%2Favr-frequency-counter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorng%2Favr-frequency-counter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorng%2Favr-frequency-counter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bjorng%2Favr-frequency-counter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bjorng","download_url":"https://codeload.github.com/bjorng/avr-frequency-counter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243684430,"owners_count":20330859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-21T01:30:07.548Z","updated_at":"2025-03-15T04:25:49.689Z","avatar_url":"https://github.com/bjorng.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"avr-frequency-counter\n=====================\n\nIn my home electronics lab, I thought that a frequency counter would\nbe a nice thing to have, but not essential. Therefore I decided to\nbuild a frequency counter myself instead of buying one. In the end, I\nhave probably spent more money than if I would have bought a\nfrequency counter, but I have learned a lot while building it.\n\nHere is the software for the frequency counter. I don't have a CAD\nprogram yet and I also think that my hardware needs some more work,\nso I will not provide detailed schematics for the construction, but\nI will provide an overview of the hardware setup below.\n\nMy Requirements And How To Meet Them\n------------------------------------\n\nI wanted to be able measure even low frequencies accurately (down to\n0.1 Hz) and I didn't want any manual setup for different frequency\nranges.\n\nThe obvious way to count frequency is to count the number of events\nduring a fixed time period (for example one second) and then divide\nthe number of events by the length of the time period. But for low\nfrequencies the time need to be long to achive good resolution. For\nexample, if the time period is one second while we are measuring a\nsignal with a frequency of about 1Hz, the measured frequency could be\neither 0, 1, or 2, depending on how the events fall in our measurement\nperiod. So for low frequencies, we would need long measurement periods\n(several minutes).\n\nThe way around that problem is to use reciprocal counting. We measure\nthe time for a fixed number of events and calculate the frequency as\nthe number of events divided by the measured time period.  The error\nin the measurement is independent of the frequency being measured, and\nonly depends on the frequency of the clock we use for measuring. As\nlong as the frequency being measured is less than the frequency of the\nclock being used for measurement reciprocal counting is always better\nthan direct counting.\n\nThe clock we use for measuring the time is the CPU clock divided by\n64, or 312.5kHz. We continue to use reciprocal counting also above\n312.5kHz. To ensure that we get 4 significant digits, we choose the\nnumber of events sufficiently high so that the length of the time\nperiod will be at least 10000 clock ticks.\n\n\nHardware Setup\n--------------\n\nThe software is written for the Atmel ATtiny84A. It should work\nwithout modifications on an ATtiny44A.\n\nThe ATtiny84A should run at 20MHz (which implies that it must be\npowered by a 5V supply). If you choose run at a lower clock frequency,\nit will **probably** work if you change the value of **CLOCK** in the\nMakefile (but is not tested by me).\n\nThe signal to be measured should be a square wave from 0V to 5V, and\nbe connected to both pin 5 (INT0/PB2) and pin 9 (PA4/T1). While you\ncould connect external signals directly to those pins, I recommend\nsome sort of input protection and signal conditioning, as a minimum a\n74HC14 (an inverting buffer with a schmitt-trigger).\n\nThe display is an [DOGM 081][3]. It has one line by 8 characters. The code\nfor controling the display is at the end of main.c. If you want to use\nsome other display, you'll just need to provide alternative\nimplementations for the functions **lcd\\_init()**, **ldc\\_home()**, and\n**lcd\\_putc()**.\n\nThe display should be wired up for SPI mode (see the [data sheet][3]). The\npins should be connected like this:\n\n* PA0 to SI\n* PA1 to CLK\n* PA2 to CSB\n* PA3 to RS\n\nReferences\n----------\n\nIt seems that Hewlett-Packard pioneered the concept of reciprocal\ncounting.\n\n* [Fundamentals of Electronic Counters][2]. An App Note from\n  Hewlett-Packard about frequency counters.\n\n* [Hewlett-Packard Journal from May 1969][1]. The entire issue is\n  about frequency counters.\n\n  [1]: http://www.hpl.hp.com/hpjournal/pdfs/IssuePDFs/1969-05.pdf\n  [2]: http://cp.literature.agilent.com/litweb/pdf/5965-7660E.pdf\n  [3]: http://www.lcd-module.com/eng/pdf/doma/dog-me.pdf\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjorng%2Favr-frequency-counter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbjorng%2Favr-frequency-counter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbjorng%2Favr-frequency-counter/lists"}