Large diffs are not rendered by default.

Large diffs are not rendered by default.

@@ -1,10 +1,10 @@
S011000046726571436F756E742E737265637C
S113000010C02AC029C077C027C026C025C024C07C
S113001022C122C021C020C01FC01EC01DC01CC0E0
S113001033C122C021C020C01FC01EC01DC01CC0CF
S11300201BC011241FBECFE5D2E0DEBFCDBF10E060
S1130030A0E6B0E0E8E9F9E002C005900D92AA3626
S1130040B107D9F720E0AAE6B0E001C01D92A038BC
S1130050B207E1F725D19EC4D3CF0F93CF93DF939B
S1130030A0E6B0E0EEE9FAE002C005900D92AC361D
S1130040B107D9F720E0ACE6B0E001C01D92A338B7
S1130050B207E1F736D121C5D3CF0F93CF93DF9306
S11300600F7DE1E0F0E00D3439F49FEF940F02C00E
S1130070EE0FFF1F9A95E2F7A1E0B0E0ED0102C098
S1130080CC0FDD1F6A95E2F7BE015C2F6095ED0190
@@ -17,141 +17,157 @@ S11300E081608EBD609A08958BB780628BBF80B5A6
S11300F0846080BD08951F920F920FB60F92112451
S11301008F929F92AF92BF92CF92DF92EF92FF9223
S11301102F933F934F935F936F937F938F939F930B
S1130120AF93BF93EF93FF9396B38CB5CDB492FD89
S113013079C0D12CDC2CCC24C80ED11C81E0809356
S113014079008091730090917400019690937400EB
S113015080937300E12CF12C8091750090917600CE
S1130160A0917700B0917800DC01992788278C0D45
S11301709D1DAE1DBF1D80349244AF40B10508F4EF
S113018051C01DBC86E28CBD6091730070917400F7
S113019080E090E0DED24B015C01C701B601D9D208
S11301A025E93FEB46E553E38AD36B017C0160917B
S11301B07500709176008091770090917800C9D293
S11301C025E93FEB46E55BE37AD39B01AC01C7012C
S11301D0B601C3D19B01AC01C501B40126D29B0178
S11301E0AC0160936E0070936F00809370009093E5
S11301F0710060E070E080E89FE317D260936A00CA
S113020070936B0080936C0090936D001092740057
S1130210109273001092750010927600109277007D
S113022010927800FF91EF91BF91AF919F918F91C0
S11302307F916F915F914F913F912F91FF90EF903C
S1130240DF90CF90BF90AF909F908F900F900FBE94
S11302500F901F9018951F920F920FB60F921124B2
S11302608F939F93AF93BF93809175009091760085
S1130270A0917700B09178000196A11DB11D8093E3
S1130280750090937600A0937700B0937800BF91A7
S1130290AF919F918F910F900FBE0F901F90189563
S11302A0BA98D39AD59AD49ADB98DD98DC98789446
S11302B016DF1ADFC0E0D0E0C12CD12CE12CF12CE8
S11302C0AA24A394B12C80917900882309F4EBC06B
S11302D026E0E216F10408F4B3C010916E00009118
S11302E06F00F0907000E090710080906A00909030
S11302F06B00D0916C00C0916D0020E034E244E7C3
S113030059E4612F702F8F2D9E2DD5D287FD10C0FB
S113031020E034E244E759E4612F702F8F2D9E2DA5
S113032084D1162F072FF82EE92EC0E0D0E02CC080
S113033020E030E040E85FE3612F702F8F2D9E2D89
S1130340BAD287FF19C020E030E040E752E4B4019C
S11303508D2F9C2F66D1181694F420E030E040E7EE
S113036052E4B4018D2F9C2F60D1162F072FF82E45
S1130370E92EC3E0D0E008C0C1E0D0E005C0182DEC
S1130380092D7E01C2E0D0E0412C84E2582E84E79E
S1130390682E89E4782E99249A94A3019201612FFE
S11303A0702F8F2D9E2D87D287FD03C08FEF981657
S11303B021F095E09915B0F101C0912C292C312C34
S11303C0A3019201612F702F8F2D9E2D2ED195D1D7
S11303D0862E70E080E090E0BCD1A30192016FD240
S11303E09B01AC01612F702F8F2D9E2DB5D0162F40
S11303F0072FF82EE92EE82DF0E0E05AFF4F808019
S113040020E030E040E85FE3C301B2010AD1F1012A
S1130410E658FF4F882311F0808203C0882D80683E
S11304208083939420E030E040E251E4C301B201C0
S1130430FCD02B013C0126E09212AFCFE12CF12C31
S113044095010E2C02C0220F331F0A94E2F70DE629
S113045048E063E085E001DE2091720030E044E092
S113046063E085E0FADD95010C2E02C0220F331FF4
S11304700A94E2F744E063E085E0EFDDF701E65833
S1130480FF4F208130E048E063E085E0E6DDDC9862
S1130490DC9A8FE097E20197F1F700C000009FEF2C
S11304A0E91AF90A10CF28E0C216D10428F08FEF18
S11304B0E81AF80AC12CD12C96E0E916F10418F0D8
S11304C02196E12CF12CC430D10510F0C0E0D0E02D
S11304D00DE620E030E042E063E085E0BEDD95011A
S11304E00E2C02C0220F331F0A94E2F746E063E0A9
S11304F085E0B3DD20E030E041E063E085E0ADDDA0
S11305002091720030E043E063E085E0A6DD9501D0
S11305100C2E02C0220F331F0A94E2F744E063E07A
S113052085E09BDD95010C2C02C0220F331F0A9439
S1130530E2F748E063E085E090DDDC98DC9A9FE335
S11305402DE083E0915020408040E1F700C000009E
S11305509FEFC91AD90AB7CE5058BB27AA270ED085
S113056070C161D130F066D120F031F49F3F11F4B5
S11305701EF456C10EF4E095E7FB4CC1E92F72D18D
S113058080F3BA17620773078407950718F071F4AC
S11305909EF58AC10EF4E0950B2EBA2FA02D0B0107
S11305A0B90190010C01CA01A0011124FF27591BB4
S11305B099F0593F50F4503E68F11A16F040A22FBA
S11305C0232F342F4427585FF3CF4695379527952B
S11305D0A795F0405395C9F77EF41F16BA0B620B2A
S11305E0730B840BBAF09150A1F0FF0FBB1F661F71
S11305F0771F881FC2F70EC0BA0F621F731F841FB4
S113060048F4879577956795B795F7959E3F08F0D9
S1130610B3CF9395880F08F09927EE0F9795879598
S11306200895D4D008F481E008950CD00AC102D111
S113063040F0F9D030F021F45F3F19F0EBC05111D4
S113064034C1EEC00FD198F39923C9F35523B1F304
S1130650951B550BBB27AA2762177307840738F02D
S11306609F5F5F4F220F331F441FAA1FA9F333D08C
S11306700E2E3AF0E0E830D091505040E695001C40
S1130680CAF729D0FE2F27D0660F771F881FBB1FFC
S1130690261737074807AB07B0E809F0BB0B802DD6
S11306A0BF01FF2793585F4F2AF09E3F510568F022
S11306B0B1C0FBC05F3FECF3983EDCF386957795C1
S11306C06795B795F7959F5FC9F7880F911D969524
S11306D0879597F90895E1E0660F771F881FBB1F80
S11306E0621773078407BA0720F0621B730B840B2D
S11306F0BA0BEE1F88F7E0950895BCD088F09F5799
S113070090F0B92F9927B751A0F0D1F0660F771F59
S1130710881F991F1AF0BA95C9F712C0B13081F039
S1130720C3D0B1E00895C0C0672F782F8827B85F81
S113073039F0B93FCCF3869577956795B395D9F79A
S11307403EF490958095709561957F4F8F4F9F4FA4
S11307500895E89409C097FB3EF4909580957095B0
S113076061957F4F8F4F9F4F9923A9F0F92F96E9F9
S1130770BB279395F695879577956795B795F1116E
S1130780F8CFFAF4BB0F11F460FF1BC06F5F7F4F0B
S11307908F4F9F4F16C0882311F096E911C077231D
S11307A021F09EE8872F762F05C0662371F096E826
S11307B0862F70E060E02AF09A95660F771F881FF5
S11307C0DAF7880F9695879597F90895990F000899
S11307D0550FAA0BE0E8FEEF16161706E807F9070F
S11307E0C0F012161306E407F50798F0621B730BAA
S11307F0840B950B39F40A2661F0232B242B252B2B
S113080021F408950A2609F4A140A6958FEF811DCD
S1130810811D089597F99F6780E870E060E008956E
S11308209FEF80EC089500240A9416161706180604
S11308300906089500240A941216130614060506E0
S11308400895092E0394000C11F4882352F0BB0F71
S113085040F4BF2B11F460FF04C06F5F7F4F8F4FD4
S11308609F4F089557FD9058440F551F59F05F3F0F
S113087071F04795880F97FB991F61F09F3F79F0BE
S113088087950895121613061406551FF2CF469540
S1130890F1DF08C0161617061806991FF1CF8695C2
S11308A07105610508940895E894BB2766277727A6
S11308B0CB0197F908958ADF08F48FEF08950AD0E1
S11308C0C0CFB1DF28F0B6DF18F0952309F0A2CF2E
S11308D0A7CFEBCFC7DFA8F39923D9F35523C9F3E7
S11308E0950F50E0551FAA27EE27FF27BB270024AA
S11308F00894679520F4E20FF31FB41F0A1E220F19
S1130900331F441FAA1F6695A9F7779530F4F30F98
S1130910B41F0A1E121E08F46395330F441FAA1F46
S1130920221F769599F7879520F4B40F0A1E121E9C
S1130930631F440FAA1F221F331F8695A9F7862F12
S1130940712D602D11249F5750408AF0E1F08823C7
S11309504AF0EE0FFF1FBB1F661F771F881F9150C1
S11309605040A9F79E3F510570F054CF9ECF5F3F92
S1130970ECF3983EDCF3869577956795B795F795F4
S1130980E7959F5FC1F7FE2B880F911D969587957C
S10B099097F90895F894FFCFD4
S10D09983F065B4F666D7D077F6725
S1130120AF93BF93EF93FF9336B32CB5CDB48091C7
S1130130770090917800A0917900B0917A0032FD17
S113014082C0D12CDC2CCC24C20ED11C21E0209303
S11301507C0020917500309176002F5F3F4F3093E3
S1130160760020937500E12CF12CDC019927882777
S11301708C0D9D1DAE1DBF1D80349244AF40B10552
S113018028F480917B00813009F051C01DBC86E2C7
S11301908CBD609175007091760080E090E05CD336
S11301A04B015C01C701B60157D325E93FEB46E596
S11301B053E308D46B017C0160917700709178005F
S11301C08091790090917A0047D325E93FEB46E589
S11301D05BE3F8D39B01AC01C701B60141D29B019B
S11301E0AC01C501B401A4D29B01AC0160937000C1
S11301F070937100809372009093730060E070E0DC
S113020080E89FE395D260936C0070936D008093B7
S11302106E0090936F001092760010927500109209
S11302207700109278001092790010927A008091F1
S11302307B00813021F482E080937B0004C0823013
S113024011F410927B00FF91EF91BF91AF919F91B8
S11302508F917F916F915F914F913F912F91FF907B
S1130260EF90DF90CF90BF90AF909F908F900F90C2
S11302700FBE0F901F9018951F920F920FB60F92FA
S113028011248F939F93AF93BF93809177009091A4
S11302907800A0917900B0917A000196A11DB11D5A
S11302A08093770090937800A0937900B0937A00BC
S11302B0BF91AF919F918F910F900FBE0F901F90A0
S11302C01895CF93DF9300D000D000D0CDB7DEB720
S11302D0BA98D39AD59AD49ADB98DD98DC98789416
S11302E0FEDE02DF212C312C1B821C82E12CD12C5E
S11302F0C12C712C412C512C1A821982A12CB12CA5
S113030080917C00811110926A0080916A008111B1
S113031045C126E0A216B10408F40BC180917B000C
S113032081115AC08090700090907100A09072006A
S1130330B090730010917400812F880F21E030E099
S113034040E050E004C0220F331F441F551F8A951C
S1130350D2F7CA01B90180D21B012C019B01AC0167
S1130360C501B4012FD3E62ED72EC82E792EA201B3
S1130370910160916C0070916D0080916E0090917C
S11303806F00D6D11B018B839C8320E030E44CE1C9
S113039056E4C501B40112D3181644F4163030F4EF
S11303A01F5F1093740081E080937B00809177003D
S11303B090917800A0917900B0917A00892B8A2BD2
S11303C08B2B51F080917400882331F081508093FD
S11303D0740081E080937B0020E034E244E759E438
S11303E06E2D7D2D8C2D972DE9D287FD10C020E038
S11303F034E244E759E46E2D7D2D8C2D972D98D150
S11304006E83172F082FF92E412C512C33C020E076
S113041030E040E85FE36E2D7D2D8C2D972DCED2FC
S113042087FF1AC020E030E040E752E4B1018B813D
S11304309C817AD11816BCF420E030E040E752E405
S1130440B1018B819C8174D16E83172F082FF92EF3
S113045033E0432E512C0EC0EE828601F72C442447
S11304604394512C07C02E82132D0B81FC8092E003
S1130470492E512C812C84E2982E84E7A82E89E4FD
S1130480B82E3FEF3D83A50194016E81712F802F1B
S11304909F2D94D287FD03C04D814F3F21F05D8194
S11304A05630C0F501C01D82A50194016E81712FE3
S11304B0802F9F2D3DD1A4D1662E70E080E090E086
S11304C0CBD1A50194017ED29B01AC016E81712F29
S11304D0802F9F2DC4D06E83172F082FF92EE62D61
S11304E0F0E0E05AFF4F608020E030E040E85FE356
S11304F0C501B40119D19D81E92FF0E0E358FF4F04
S1130500882311F0608203C0862D80688083ED818A
S1130510EF5FED8320E030E040E251E4C501B40137
S113052007D14B015C01FD81F63009F0ACCFA12C61
S1130530B12C21E030E00A2C02C0220F331F0A94B0
S1130540E2F70DE648E063E085E087DD2091740082
S113055030E044E063E085E080DD21E030E0042C1D
S113056002C0220F331F0A94E2F744E063E085E0FF
S113057074DDF501E358FF4F208130E048E063E08B
S113058085E06BDDDC98DC9A8FE097E20197F1F768
S113059000C000009FEFA91AB90AB2CEE981FA811E
S11305A0389728F0FFEFAF1ABF0A1A82198226E0A3
S11305B0A216B10428F03FEF431A530AA12CB12C20
S11305C044E04416510410F0412C512C0DE620E077
S11305D030E042E063E085E040DD21E030E00A2CD9
S11305E002C0220F331F0A94E2F746E063E085E07D
S11305F034DD20E030E041E063E085E02EDD209151
S1130600740030E043E063E085E027DD21E030E082
S1130610042C02C0220F331F0A94E2F744E063E083
S113062085E01BDD21E030E0098002C0220F331F8A
S11306300A94E2F748E063E085E00FDDDC98DC9A99
S11306405FE38DE093E0515080409040E1F700C0BB
S11306500000E981FA813196FA83E98351CE50583A
S1130660BB27AA270ED070C161D130F066D120F02B
S113067031F49F3F11F41EF456C10EF4E095E7FBEC
S11306804CC1E92F72D180F3BA176207730784074C
S1130690950718F071F49EF58AC10EF4E0950B2EBF
S11306A0BA2FA02D0B01B90190010C01CA01A001C0
S11306B01124FF27591B99F0593F50F4503E68F11B
S11306C01A16F040A22F232F342F4427585FF3CF5C
S11306D0469537952795A795F0405395C9F77EF42D
S11306E01F16BA0B620B730B840BBAF09150A1F076
S11306F0FF0FBB1F661F771F881FC2F70EC0BA0FFC
S1130700621F731F841F48F4879577956795B79583
S1130710F7959E3F08F0B3CF9395880F08F099277B
S1130720EE0F979587950895D4D008F481E0089545
S11307300CD00AC102D140F0F9D030F021F45F3F6F
S113074019F0EBC0511134C1EEC00FD198F39923C5
S1130750C9F35523B1F3951B550BBB27AA27621781
S11307607307840738F09F5F5F4F220F331F441FC6
S1130770AA1FA9F333D00E2E3AF0E0E830D09150FE
S11307805040E695001CCAF729D0FE2F27D0660FEB
S1130790771F881FBB1F261737074807AB07B0E82A
S11307A009F0BB0B802DBF01FF2793585F4F2AF040
S11307B09E3F510568F0B1C0FBC05F3FECF3983E2B
S11307C0DCF3869577956795B795F7959F5FC9F79D
S11307D0880F911D9695879597F90895E1E0660F26
S11307E0771F881FBB1F621773078407BA0720F09F
S11307F0621B730B840BBA0BEE1F88F7E095089508
S1130800BCD088F09F5790F0B92F9927B751A0F02A
S1130810D1F0660F771F881F991F1AF0BA95C9F790
S113082012C0B13081F0C3D0B1E00895C0C0672FC9
S1130830782F8827B85F39F0B93FCCF38695779540
S11308406795B395D9F73EF4909580957095619529
S11308507F4F8F4F9F4F0895E89409C097FB3EF454
S113086090958095709561957F4F8F4F9F4F9923F9
S1130870A9F0F92F96E9BB279395F6958795779577
S11308806795B795F111F8CFFAF4BB0F11F460FF37
S11308901BC06F5F7F4F8F4F9F4F16C0882311F08F
S11308A096E911C0772321F09EE8872F762F05C0A3
S11308B0662371F096E8862F70E060E02AF09A953E
S11308C0660F771F881FDAF7880F9695879597F933
S11308D00895990F0008550FAA0BE0E8FEEF1616CD
S11308E01706E807F907C0F012161306E407F50720
S11308F098F0621B730B840B950B39F40A2661F094
S1130900232B242B252B21F408950A2609F4A14036
S1130910A6958FEF811D811D089597F99F6780E843
S113092070E060E008959FEF80EC089500240A943D
S11309301616170618060906089500240A941216B6
S11309401306140605060895092E0394000C11F4E9
S1130950882352F0BB0F40F4BF2B11F460FF04C096
S11309606F5F7F4F8F4F9F4F089557FD9058440FEF
S1130970551F59F05F3F71F04795880F97FB991FFA
S113098061F09F3F79F087950895121613061406B7
S1130990551FF2CF4695F1DF08C016161706180644
S11309A0991FF1CF86957105610508940895E8941F
S11309B0BB2766277727CB0197F908958ADF08F4C8
S11309C08FEF08950AD0C0CFB1DF28F0B6DF18F05A
S11309D0952309F0A2CFA7CFEBCFC7DFA8F39923C4
S11309E0D9F35523C9F3950F50E0551FAA27EE27D5
S11309F0FF27BB2700240894679520F4E20FF31F18
S1130A00B41F0A1E220F331F441FAA1F6695A9F79D
S1130A10779530F4F30FB41F0A1E121E08F4639581
S1130A20330F441FAA1F221F769599F7879520F448
S1130A30B40F0A1E121E631F440FAA1F221F331F66
S1130A408695A9F7862F712D602D11249F5750404C
S1130A508AF0E1F088234AF0EE0FFF1FBB1F661FE8
S1130A60771F881F91505040A9F79E3F510570F0A1
S1130A7054CF9ECF5F3FECF3983EDCF38695779599
S1130A806795B795F795E7959F5FC1F7FE2B880F9C
S1110A90911D9695879597F90895F894FFCFD8
S10F0A9E3F065B4F666D7D077F6701001B
S9030000FC
BIN +876 Bytes (120%) FreqCount84/Release/main.o
Binary file not shown.
@@ -55,8 +55,8 @@
#define overflow_period_sec ( (0x10000) / (double)F_CPU )


// this set the target number of clock cycles to find before calculating the frequency.
#define min_clock_cycles_for_freq_calc ( (uint32_t)1000000 ) // 20 Hz period
// this set the target number of clock cycles to find before calculating the input frequency.
#define min_clock_cycles_for_freq_calc ( (uint32_t)1000000 ) // 20 Hz measurement period

// this is the max value of timer1
#define timer1_TOP ((uint16_t)0xffff)
@@ -69,7 +69,7 @@
// this starts the counter with 38 counts already in it. This equates to 1.9 microseconds at 20 MHz.
// NOTE:
#define TCNT1H_reset (0)
#define TCNT1L_reset (38)
#define TCNT1L_reset (38)

//=================================================================
// function definitions
@@ -137,13 +137,22 @@
// in general, if you have an N-digit display, you should make your decade start 10^(N-1) for peak efficiency.
# define DECADE_START ((double)10e5)


//=================================================================
// variable declaration and
// variable declaration
//=================================================================

// this keeps track of whether or not the counter has been triggered for the first time.
// when the counter decides that it needs to change the frequency division, this will be reset to 0.
uint8_t startUp = 1;
// this keeps track of whether or not the device has been triggered at least once using the latest frequency division settings.
uint8_t triggered = 0;
// this keeps track of whether or not the frequency division settings have been changed during the current measurement period.
// 0 indicates the current measurement is valid and has been made with no change to the frequency division settings.
// 1 indicates the current measurement is invalid because the frequency division settings were just changed.
// 2 indicates a measurement is being performed that WILL be valid when it is complete.
uint8_t adjustingFreqDiv = 0;

// this keeps track of how many times Timer1 has overflowed.
// with a clock frequency of 20 MHz, a 16-bit timer, and a 32-bit overflow counter, this program should be able to count periods as long as 162 days.
uint32_t overflows = 0;
@@ -165,14 +174,29 @@ uint16_t freq_in_cycles = 0;
// 6 | 4096 | 2^12
// > 6 | 4096 | 2^12 (max division from the 74**4040)
uint8_t freq_div = 0;

// this is the maximum valid frequency division setting
#define freq_div_max ((uint8_t)6)

// this is the maximum frequency that *should* be applied to the ATtiny84A.
// the device will tolerate frequencies higher than this, but the display operation will suffer past the 35 kHz mark.
// therefore, the frequency input should be divided down to something below this max setting.
#define freq_meas_max ( (double) 10e3 ) // if the frequency applied to the input of the device goes above this frequency, the freq-div should be increased.
// the minimum frequency division is set just by checking if timer1 has overflowed.

//-----------------------------------------------------------------
// these variables keep track of the frequency measured at the ATtiny84 input pin.
// NOTE: this may not be the actual frequency! This could be a divided-down version of the input frequency.
// the "real" frequency that we want to measure is the frequency that is being applied to the input of the binary counter.
// this program controls the frequency division (see above).
// from the frequency division settings, the real input frequency is calculated.
//-----------------------------------------------------------------
// these two variables record the state of the timer and overflow counter at the moment when
//uint16_t OFF_time_timer = 12345;
//volatile uint32_t OFF_time_overflows = 0;
// this is updated with measurements of the input frequency
double freq_in_measurement_Hz = 0;
// this is the calcualted period based on the frequency
double period_measurement_s = 0;
double freq_meas_Hz = 0;
// this is the calculated period based on the freq_meas_Hz
double period_meas_s = 0;
// this is updated with measurements of the duty cycle (%)
//volatile double freq_in_duty_cycle = 0;

@@ -253,6 +277,7 @@ ISR(PCINT1_vect)
// read from low byte then add the high byte (low byte first)
uint16_t currentTimer1 = TCNT1L;
currentTimer1 += TCNT1H<<8;
uint16_t currentOverflows = overflows;

//-----------------------------------------------------------------
// Next up: figure out what the state of the pin is
@@ -268,19 +293,23 @@ ISR(PCINT1_vect)
// record that the input signal DID, in fact, have a (possibly another) falling edge.
freq_in_cycles++;

// if the current sample has been going for at least the number of cycles needed to get 1 ppm resolution,
if( ((uint32_t)overflows<<16) + (uint16_t)currentTimer1 >= min_clock_cycles_for_freq_calc)
{
// calculate the number of cycles that have taken place since the beginning of the measurement period
uint32_t timer1_cycles = ((uint32_t)currentOverflows<<16) + (uint32_t)currentTimer1;

// if the current sample has been going for the necessary amount of time
// (or if the frequency division settings were just changed)
if( timer1_cycles >= min_clock_cycles_for_freq_calc || (adjustingFreqDiv == 1) )
{
// start your next sample by resetting Timer1.
TCNT1H = TCNT1H_reset; // reset the timer1 count (both the high and low bytes)
TCNT1L = TCNT1L_reset; // this is a non zero value. see definitions of the reset values for better information

// calculate the period over which this sampled was performed.
double period_sec = (currentTimer1*clock_period_sec) + (overflows *overflow_period_sec);
// record the frequency
freq_in_measurement_Hz = freq_in_cycles/period_sec;
freq_meas_Hz = freq_in_cycles/period_sec;
// calculate the period
period_measurement_s = 1/freq_in_measurement_Hz;
period_meas_s = 1/freq_meas_Hz;
// calculate the OFF_time in seconds
//double OFF_time_sec = (OFF_time_timer*clock_period_sec) + (OFF_time_overflows*overflow_period_sec);
// record the duty cycle
@@ -293,6 +322,19 @@ ISR(PCINT1_vect)
//OFF_time_overflows = 0;
}

// if the frequency division settings were just changed,
if(adjustingFreqDiv == 1)
{
// record that the next measurement will be valid
adjustingFreqDiv = 2;
}
// if the current measurement was supposed to be a valid one
else if(adjustingFreqDiv == 2)
{
// record that this measurement was made without changing the frequency division settings.
adjustingFreqDiv = 0;
}

}
else
{
@@ -354,47 +396,79 @@ int main(void)
// 2 = Seconds
// 3 = Minutes

double currentFreq = 0; // this keeps track of the current frequency that will be displayed
double currentPeriod = 0; // this keeps track of the current period that will be displayed
double currentFreqIn = 0; // this keeps track of the current frequency that will be displayed
double currentPeriodIn = 0; // this keeps track of the current period that will be displayed
double dispNumber = 0; // this keeps track of what number we want to display (frequency/period gets shoved in here and the number gets encoded for the 7-segment display the same way in both cases.)


//-----------------------------------------------------------------
// the LED displays are handled in this while loop.
//-----------------------------------------------------------------
while(1)
{
// if the unit is EVER triggered, it will no longer be in start up mode.
if(triggered)
{
startUp = 0;
}

// if you are not in start-up mode (i.e. you are making measurements)
if(!startUp)
{
// check if we are starting a new frame (a new set of six display digits)
if(digit >= NUMBER_OF_DIGITS)
{
digit = 0;
double decade;

// grab the current frequency and period
currentFreq = freq_in_measurement_Hz;
currentPeriod = period_measurement_s;


// if the last frequency measurement was done without any change in frequency division setting
if(adjustingFreqDiv == 0)
{

// grab the current frequency and period
currentFreqIn = freq_meas_Hz * (double)( (uint32_t)1 << 2*freq_div );
currentPeriodIn = period_meas_s / (double)( (uint32_t)1 << 2*freq_div );

// if the frequency applied to the ATtiny84 is too high,
if( (freq_meas_Hz > freq_meas_max) && (freq_div < freq_div_max) )
{
// try to decrease freq-meas (increase the frequency division)
freq_div++;
// record that you are adjusting frequency division settings.
adjustingFreqDiv = 1;
}

// if timer1 has overflowed,
if( overflows && (freq_div > 0) )
{
// try to increase freq-meas (decrease the frequency division)
freq_div--;
// record that you are adjusting frequency division settings.
adjustingFreqDiv = 1;
}
}

// determine what unit we want to use
if (currentFreq >= 1e6)
if (currentFreqIn >= 1e6)
{
unit = 0; // use units of MHz
dispNumber = currentFreq/1.0e6; // display MHz
dispNumber = currentFreqIn/1.0e6; // display MHz
}
else if(currentFreq >= 1)
else if(currentFreqIn >= 1)
{
unit = 1; // use units of Hz
dispNumber = currentFreq; // display hertz
dispNumber = currentFreqIn; // display hertz
}
else if(currentPeriod <= 60)
else if(currentPeriodIn <= 60)
{
unit = 2; // use units of Seconds
dispNumber = currentPeriod; // display seconds
dispNumber = currentPeriodIn; // display seconds
}
else
{
unit = 3; // use units of Minutes
dispNumber = currentPeriod/60.0; // display minutes
dispNumber = currentPeriodIn/60.0; // display minutes
}

// default is a bogus value to indicate that the first significant figure has not been found yet
@@ -460,7 +534,7 @@ int main(void)
}


// if you have not triggered yet,
// if you have just started up and have not seen any transitions,
// (this is basically just something to do when the unit first starts up)
else
{