Author Topic: Minimalist frequency meter  (Read 12888 times)

0 Members and 1 Guest are viewing this topic.

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Minimalist frequency meter
« on: April 20, 2014, 01:16:28 pm »
In a separate thread, I talked about the use of a 4-digit 7segment led display on the back of a 16F1936 for other uses, including a frequency meter.

I went ahead and put this together: a 4-digit frequency meter that utilizes, at minimal, 3 parts: a 16F1936, a 4-digit 7segment led display, and a crystal (not shown on the schematic).

R1 is the (optional) protection resistor (of low value, less than 470ohm).

Cannot get any simpler than this, unless you go the uart route.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #1 on: April 20, 2014, 01:22:55 pm »
My version runs off a 4Mhz crystal.

Output format:

The meter outputs its frequency readings in four ranges:

1) > 10Mhz: XX.YY (Mhz)
2) 1Mhz - 10Mhz: X.YYY (Mhz)
3) 100K - 1Mhz: XXX.Y (Khz)
4) 1K - 100Khz: XXXX (Khz)
5) <1Khz: XXXX. (Hz)

Gate time is 1 second.

The simulation shows it measuring a 12Khz source.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #2 on: April 20, 2014, 01:23:25 pm »
Here is the meter measuring its own oscillator (4Mhz):

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #3 on: April 20, 2014, 01:24:42 pm »
The meter measuring its own instruction clock (1Mhz)

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #4 on: April 20, 2014, 01:26:00 pm »
Measuring a 16.128Mhz crystal

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #5 on: April 20, 2014, 01:27:19 pm »
Measuring a 32Mhz crystal
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #6 on: April 20, 2014, 01:28:44 pm »
Measuring a 20Mhz crystal
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #7 on: April 20, 2014, 01:29:31 pm »
Here is the hex code:

Code: [Select]
:0400000080316B28B8
:10000800803120007F08F600111C0B280C281628C8
:1000180011100030BA070030BB3D0130BC3D003044
:10002800BD3D1628911C19281A285E289110013008
:10003800BE070030BF3D01303F06031D2528F430C0
:100048003E06031D282829285E282A281708F200BA
:100058007208F8001608F2007208F7001708780608
:10006800031D372838282A2839283D08B9003C08B4
:10007800B8003B08B7003A08B6007708F2007808DD
:10008800F300F401F5017208B6047308B7047408A4
:10009800B8047508B904960197010030BD00003016
:1000A800BC000030BB000030BA001110BE01BF0117
:1000B8005E285E280B1D6128622867280B1186318F
:1000C8006E268031672876082000FF0009008031FD
:1000D8009A2800345F347C3458345E34793471346F
:1000E8006F34073474340E340034383400345434E4
:1000F8005C347334673477346D3400341C34003422
:10010800003400346E34003400343F3406345B3439
:100118004F3466346D347D3407347F346F345F3444
:100128007C3458345E34793471340034F901FA017E
:10013800FB01FC01FD01B601B701B801B901BA0123
:10014800BB01BC01BD01BE01BF01C001C1018031BD
:10015800E0208031C2008031E1208031C30080314D
:10016800E2208031C4002000813103292000A3004F
:100178001C11FE30A1002108C1009A012308A1002A
:100188000130A136890BC52878302105A200230843
:100198000239220404389C00210091140B17200016
:1001A8002008FF3E9B00080023008C018D012200DF
:0E01B800910193019D010800FF34FF34FF34D4
:100200008131820702298031D82081318731E4276A
:100210008131C8302000AE002E08A00003308731A5
:10022000BB278131C8302000AE002E08A0009030DE
:100230008031BA208131C8302000A0000030A100F8
:1002400003308731902781318B1726292000390808
:10025000B5003808B4003708B3003608B2003208D9
:10026000AE003308AF003408B0003508B1000330E9
:10027000AE35AF0DB00DB10D890B38293108B50081
:100280003008B4002F08B3002E08B2000030350249
:10029000031D542998303402031D5429963033022B
:1002A000031D542980303202031C57295829562A2D
:1002B0000030A3000030A2002730A1001030A000C1
:1002C0003508A7003408A6003308A5003208A400AA
:1002D0008631DC26813120002308B5002208B400D5
:1002E0002108B3002008B2000030A3000030A200B3
:1002F0000030A1000A30A0003508A7003408A6008D
:100300003308A5003208A40087313E278131200040
:100310002008893E80310A008131AE002E08FC00A1
:100320000030A3000030A2000030A1000A30A0007D
:100330003508A7003408A6003308A5003208A40039
:100340008631DC26813120002308B5002208B40064
:100350002108B3002008B2000030A3000030A20042
:100360000030A1000A30A0003508A7003408A6001C
:100370003308A5003208A40087313E2781312000D0
:100380002008893E80310A008131AE002E08FB0032
:100390000030A3000030A2000030A1000A30A0000D
:1003A0003508A7003408A6003308A5003208A400C9
:1003B0008631DC26813120002308B5002208B400F4
:1003C0002108B3002008B2000030A3000030A200D2
:1003D0000030A1000A30A0003508A7003408A600AC
:1003E0003308A5003208A40087313E278131200060
:1003F0002008893E80310A0081318038AE002E0805
:10040000FA000030A3000030A2000030A1000A3042
:10041000A0003508A7003408A6003308A50032085C
:10042000A4008631DC26813120002308B500220893
:10043000B4002108B3002008B2000030A30000304F
:10044000A2000030A1000A30A0003508A70034083F
:10045000A6003308A5003208A40087313E27813169
:1004600020002008893E80310A008231AE002E082B
:10047000F9000030A3000030A2000030A1000A30D3
:10048000A0003508A7003408A6003308A5003208EC
:10049000A4008631DC26813120002308B500220823
:1004A000B4002108B3002008B2002629003035022C
:1004B000031D642A0F303402031D642A42303302C4
:1004C000031D642A40303202031C672A682A662B07
:1004D0000030A3000030A2000330A100E830A000EB
:1004E0003508A7003408A6003308A5003208A40088
:1004F0008631DC26813120002308B5002208B400B3
:100500002108B3002008B2000030A3000030A20090
:100510000030A1000A30A0003508A7003408A6006A
:100520003308A5003208A40087313E27813120001E
:100530002008893E80310A008231AE002E08FC007E
:100540000030A3000030A2000030A1000A30A0005B
:100550003508A7003408A6003308A5003208A40017
:100560008631DC26813120002308B5002208B40042
:100570002108B3002008B2000030A3000030A20020
:100580000030A1000A30A0003508A7003408A600FA
:100590003308A5003208A40087313E2781312000AE
:1005A0002008893E80310A008231AE002E08FB000F
:1005B0000030A3000030A2000030A1000A30A000EB
:1005C0003508A7003408A6003308A5003208A400A7
:1005D0008631DC26813120002308B5002208B400D2
:1005E0002108B3002008B2000030A3000030A200B0
:1005F0000030A1000A30A0003508A7003408A6008A
:100600003308A5003208A40087313E27813120003D
:100610002008893E80310A008331AE002E08FA009E
:100620000030A3000030A2000030A1000A30A0007A
:100630003508A7003408A6003308A5003208A40036
:100640008631DC26813120002308B5002208B40061
:100650002108B3002008B2000030A3000030A2003F
:100660000030A1000A30A0003508A7003408A60019
:100670003308A5003208A40087313E2781312000CD
:100680002008893E80310A0083318038AE002E0870
:10069000F9000030A3000030A2000030A1000A30B1
:1006A000A0003508A7003408A6003308A5003208CA
:1006B000A4008631DC26813120002308B500220801
:1006C000B4002108B3002008B2002629003035020A
:1006D000031D742B01303402031D742B863033024A
:1006E000031D742BA0303202031C772B782B762C41
:1006F0000030A3000030A2000030A1006430A00050
:100700003508A7003408A6003308A5003208A40065
:100710008631DC26813120002308B5002208B40090
:100720002108B3002008B2000030A3000030A2006E
:100730000030A1000A30A0003508A7003408A60048
:100740003308A5003208A40087313E2781312000FC
:100750002008893E80310A008331AE002E08FC005B
:100760000030A3000030A2000030A1000A30A00039
:100770003508A7003408A6003308A5003208A400F5
:100780008631DC26813120002308B5002208B40020
:100790002108B3002008B2000030A3000030A200FE
:1007A0000030A1000A30A0003508A7003408A600D8
:1007B0003308A5003208A40087313E27813120008C
:1007C0002008893E80310A0083318038AE002E082F
:1007D000FB000030A3000030A2000030A1000A306E
:1007E000A0003508A7003408A6003308A500320889
:1007F000A4008631DC26813120002308B5002208C0
:10080000B4002108B3002008B2000030A30000307B
:10081000A2000030A1000A30A0003508A70034086B
:10082000A6003308A5003208A40087313E27813195
:1008300020002008893E80310A008431AE002E0855
:10084000FA000030A3000030A2000030A1000A30FE
:10085000A0003508A7003408A6003308A500320818
:10086000A4008631DC26813120002308B50022084F
:10087000B4002108B3002008B2000030A30000300B
:10088000A2000030A1000A30A0003508A7003408FB
:10089000A6003308A5003208A40087313E27813125
:1008A00020002008893E80310A008431AE002E08E5
:1008B000F9000030A3000030A2000030A1000A308F
:1008C000A0003508A7003408A6003308A5003208A8
:1008D000A4008631DC26813120002308B5002208DF
:1008E000B4002108B3002008B200262900303502E8
:1008F000031D842C00303402031D842C033033028A
:10090000031D842CE8303202031C872C882C852D93
:100910000030A3000030A2000330A100E830A000A6
:100920003508A7003408A6003308A5003208A40043
:100930008631DC26813120002308B5002208B4006E
:100940002108B3002008B2000030A3000030A2004C
:100950000030A1000A30A0003508A7003408A60026
:100960003308A5003208A40087313E2781312000DA
:100970002008893E80310A008431AE002E08FC0038
:100980000030A3000030A2000030A1000A30A00017
:100990003508A7003408A6003308A5003208A400D3
:1009A0008631DC26813120002308B5002208B400FE
:1009B0002108B3002008B2000030A3000030A200DC
:1009C0000030A1000A30A0003508A7003408A600B6
:1009D0003308A5003208A40087313E27813120006A
:1009E0002008893E80310A008431AE002E08FB00C9
:1009F0000030A3000030A2000030A1000A30A000A7
:100A00003508A7003408A6003308A5003208A40062
:100A10008631DC26813120002308B5002208B4008D
:100A20002108B3002008B2000030A3000030A2006B
:100A30000030A1000A30A0003508A7003408A60045
:100A40003308A5003208A40087313E2781312000F9
:100A50002008893E80310A008531AE002E08FA0058
:100A60000030A3000030A2000030A1000A30A00036
:100A70003508A7003408A6003308A5003208A400F2
:100A80008631DC26813120002308B5002208B4001D
:100A90002108B3002008B2000030A3000030A200FB
:100AA0000030A1000A30A0003508A7003408A600D5
:100AB0003308A5003208A40087313E278131200089
:100AC0002008893E80310A008531AE002E08F900E9
:100AD0000030A3000030A2000030A1000A30A000C6
:100AE0003508A7003408A6003308A5003208A40082
:100AF0008631DC26813120002308B5002208B400AD
:100B00002108B3002008B20026290030A3000030DD
:100B1000A2000030A1000A30A0003508A700340868
:100B2000A6003308A5003208A40087313E27813192
:100B300020002008893E80310A0085318038AE00CF
:100B40002E08FC000030A3000030A2000030A100FD
:100B50000A30A0003508A7003408A6003308A50015
:100B60003208A4008631DC26813120002308B5003C
:100B70002208B4002108B3002008B2000030A3000E
:100B80000030A2000030A1000A30A0003508A70004
:100B90003408A6003308A5003208A40087313E2798
:100BA000813120002008893E80310A008531AE0065
:100BB0002E08FB000030A3000030A2000030A1008E
:100BC0000A30A0003508A7003408A6003308A500A5
:100BD0003208A4008631DC26813120002308B500CC
:100BE0002208B4002108B3002008B2000030A3009E
:100BF0000030A2000030A1000A30A0003508A70094
:100C00003408A6003308A5003208A40087313E2727
:100C1000813120002008893E80310A008631AE00F3
:100C20002E08FA000030A3000030A2000030A1001E
:100C30000A30A0003508A7003408A6003308A50034
:100C40003208A4008631DC26813120002308B5005B
:100C50002208B4002108B3002008B2000030A3002D
:100C60000030A2000030A1000A30A0003508A70023
:100C70003408A6003308A5003208A40087313E27B7
:100C8000813120002008893E80310A008631AE0083
:100C90002E08F9000030A3000030A2000030A100AF
:100CA0000A30A0003508A7003408A6003308A500C4
:100CB0003208A4008631DC26813120002308B500EB
:100CC0002208B4002108B3002008B20026292629F2
:100CD000262926292629262980316B2820000D1750
:100CE0008D150D158C167D08793E8600870101084B
:100CF000F0007008F100711C7E2E7F2E812E8D1663
:100D0000822E8D12F11C852E862E882E8D14892E12
:100D10008D10711D8C2E8D2E8F2E8C15902E8C117A
:100D2000F11D932E942E962E8C14972E8C10711EDE
:100D30009A2E9B2E9D2E0C149E2E0C10F11EA12E71
:100D4000A22EA42E0D16A52E0D12711FA82EA92EAF
:100D5000AB2E0C16AC2E0C12F11FAF2EB02EB22EF5
:100D60000C15CD2E0C11CD2ECD2E0D13FD01FD0A2F
:100D7000DB2E8D110230F0007008FD00DB2E0D110E
:100D80000330F0007008FD00DB2E8C12FD01DB2E1D
:100D90000D13FD01FD0ADB2EDB2E7D08003A031941
:100DA000B52E013A0319B92E033A0319BF2E013AA1
:100DB0000319C52EC82E080000302000AC000030FA
:100DC000AB000030AA000030A9002308220421044F
:100DD00020040319EC2EED2E342FAD01AD0AFC2EAC
:100DE0000130A035A10DA20DA30D890BF12E01300C
:100DF000A8002808AD07FC2EA31FFF2E002FF02E01
:100E0000022F022F0130A935AA0DAB0DAC0D890BB5
:100E1000032F23082702031D172F22082602031D74
:100E2000172F21082502031D172F20082402031C59
:100E30001A2F1B2F252F2008A4022108A53B2208CA
:100E4000A63B2308A73B2914252F0130A336A20C6B
:100E5000A10CA00C890B262F0130AD02031D312FF0
:100E6000322F022F342F342F2C08A3002B08A2007E
:100E70002A08A1002908A0003D2F0800200023080F
:100E80002204210420040319462F472F862FA9018D
:100E9000A90A562F0130A035A10DA20DA30D890B73
:100EA0004B2F0130A8002808A907562FA31F592F40
:100EB0005A2F4A2F5C2F5C2F23082702031D6A2F0D
:100EC00022082602031D6A2F21082502031D6A2F0E
:100ED00020082402031C6D2F6E2F772F2008A402F8
:100EE0002108A53B2208A63B2308A73B772F01300A
:100EF000A336A20CA10CA00C890B782F0130A902FB
:100F0000031D832F842F5C2F862F862F2708A30095
:100F10002608A2002508A1002408A0008F2F0800A1
:100F20002000A4001810FE30A2002208C000981172
:100F30009817181324080339A2000430A235890B2E
:100F40009E2F1808CF39220498001815210011147B
:100F50000B1720002009A2002109A300A20A0319EF
:100F6000A30A2208C2002308C300430897004208CE
:100F70009600181408002000A200FE30A1002108ED
:100F8000C5002100951220002208FF3A031DC92F39
:100F9000CA2FCD2F21009515DA2F2100951107308A
:100FA00020002205A10021001508F83920002104A5
:100FB0002100950020002003FF3AA1002108C40071
:100FC000440895008B16080020000D178D150D158F
:100FD0008C168D128D108C118C100C100D120C12A1
:100FE0000C11F22FC030A000200821008C058130A8
:0E0FF0002000A000200821008D05FE2F080023
:020000040001F9
:04000E0082C9FFDCC8
:00000001FF

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #8 on: April 20, 2014, 01:32:15 pm »
Some considerations:

1) the code now drives common cathode displays. It can be turned to drive both - when I get time, I will use a pin for the user to specify which type of displays is being driven.

2) I didn't use any load capacitors on the crystal: the pullability is so small that it makes little difference for a 4-digit meter. You can add them if you want.

3) highest frequency: the highest I tried is 32Mhz. The meter is spot on and the display no flickering.

...
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #9 on: April 20, 2014, 01:47:34 pm »
Measuring a 32Khz crystal

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #10 on: April 20, 2014, 01:48:43 pm »
Quote
3) highest frequency: the highest I tried is 32Mhz. The meter is spot on and the display no flickering.

The meter gave fluctuating readings for a 50Mhz crystal. So the high end is somewhere between 32Mhz and 50Mhz.

You probably need to design an AFE if you intend to use the meter.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #11 on: April 26, 2014, 03:53:34 pm »
The highest frequency appears to be 48.6 - 48.7Mhz: beyond which it starts to lose pulses. Increasing the frequency of the PIC helps marginally.

Current consumption is about 60ma.
================================
https://dannyelectronics.wordpress.com/
 

Offline Teemo

  • Regular Contributor
  • *
  • Posts: 58
  • Country: ee
Re: Minimalist frequency meter
« Reply #12 on: April 28, 2014, 10:29:30 am »
Hello dannyf

This is interesting.
I understand you are using Timer1 as a counter. Have you also tried Timer0 with prescaler (maybe this is faster)?
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #13 on: April 28, 2014, 11:14:09 am »
A few considerations in selecting which counter to use in a frequency meter:

- pinout: obviously the input pin has to be available. In this case, the T0CKI pin is used to drive the led display.

- counter width: each time the counter overflows, you update a msw to keep track of the counter. To minimize mcu load you want the counter to be wide. That works in favor of timet1.

- asynchronous vs. Synchronous counter: to count faster than the mcus clock, you want an asynchronous counter. In this example, the mci runs at 1Mhz but counts to 48Mhz, thanks to its asynchronous timer1. This is a remarkable feature of the PIC. An avr can't do this for example.

as to gating, I am doing 1 second. Faster gating is possible.
================================
https://dannyelectronics.wordpress.com/
 

Offline amyk

  • Super Contributor
  • ***
  • Posts: 8275
Re: Minimalist frequency meter
« Reply #14 on: April 28, 2014, 11:27:10 am »
What's the accuracy spec?
 

Offline Teemo

  • Regular Contributor
  • *
  • Posts: 58
  • Country: ee
Re: Minimalist frequency meter
« Reply #15 on: April 28, 2014, 03:12:15 pm »
You always get .99 reading. Could it be the rounding issue:  .999 rounded to .99 (instead 1.00)?
 

Offline leppie

  • Frequent Contributor
  • **
  • Posts: 269
  • Country: za
Re: Minimalist frequency meter
« Reply #16 on: April 28, 2014, 03:25:05 pm »
Off by 1 error? Counting pulses, you should 'generally' minus 1 given you start on an edge trigger and finish on one.

|___|___|___|___|

4 periods, but 5 pulses.
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #17 on: April 28, 2014, 03:57:16 pm »
I have implemented rounding up, by adding 5 to the fifth digit. 3.9995 or high would read 4.000.
================================
https://dannyelectronics.wordpress.com/
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Minimalist frequency meter
« Reply #18 on: April 28, 2014, 05:08:45 pm »
as to gating, I am doing 1 second. Faster gating is possible.

You can make it automatic, changing with the range, just to have enough counts. And use period measurement for low frequencies.

Any chance for open source code?

Edit: you can spice it up with one of these http://r.ebay.com/F9liJ4 .  (I got a 1.3" on order looks like a nice generic addition to projects. Interface is I2C/SPI).
« Last Edit: April 28, 2014, 05:15:12 pm by zapta »
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1999
  • Country: us
    • netstuff
Re: Minimalist frequency meter
« Reply #19 on: April 28, 2014, 05:17:17 pm »
I've been using kerry wong's frequency counter code (source avail) for the arduino for a while, now.  it does not go too high (3 or 4 mhz max, iirc) but you can always prescale it if you need to.

just search on arduino frequency counter and if you see kerry, that's a place to start.

I know nothing about PIC and they are not open-source (free) friendly so I'd rather point people toward truly free things, like arduinos and atmel.

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #20 on: April 28, 2014, 06:32:46 pm »
-it does not go too high (3 or 4 mhz max, iirc) but you can always prescale it if you need to.-

the limitation there is the avr hardware: its counter is synchronous and has no prescaler. So the most you can do is mcu frequency / 2.
================================
https://dannyelectronics.wordpress.com/
 

Offline Thor-Arne

  • Supporter
  • ****
  • Posts: 500
  • Country: no
  • tinker - tinker, little noob.....
Re: Minimalist frequency meter
« Reply #21 on: April 28, 2014, 07:14:37 pm »
This Arduino frequency counter claim to work up to 8MHz when the duty cycle is 50%.

I have tested it up to 5 MHz a while back.

I guess some clever input circuit/prescaler is needed if better performance is needed.
 

Offline linux-works

  • Super Contributor
  • ***
  • Posts: 1999
  • Country: us
    • netstuff
Re: Minimalist frequency meter
« Reply #22 on: April 28, 2014, 07:26:57 pm »
you'd want a prescaler ANYWAY since, no matter what the cpu is, it will not be high enough for 'real freq counter' use.

for my needs, the avr solution is great (although it does waste a full 28pin 328 arduino).  my app is to count the freq of spdif word-clock so that I can show audio sample rate, directly.  that's 192khz, max (more or less) and its easy to count that, directly, with the arduino.  if I had to count mhz, I would divide it down and you can use pic-div chips to do some pretty high amounts of 'zeroes' in the division.  while I dont' do PIC myself, those chips could be considered hardware solutions on their own with just 8 pins and not much else needed for support.

now, an 8 pin chip that can directly count freq and output it via req/response over serial would be neat, indeed!

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #23 on: April 28, 2014, 11:18:22 pm »
I took out the 4Mhz crystal and used the internal oscillator (at 4Mhz, +/- 1% per the datasheet). A 16.128Mhz source read 16.12Mhz - 16.13Mhz.

So if that's acceptable to you, you can basically shrink the frequency meter down to just the 4-digit led + the mcu. Nothing else.

If you take uart output, you don't even need the 4-digit led, :).
================================
https://dannyelectronics.wordpress.com/
 

Offline zapta

  • Super Contributor
  • ***
  • Posts: 6190
  • Country: us
Re: Minimalist frequency meter
« Reply #24 on: April 29, 2014, 12:11:20 am »
So if that's acceptable to you, you can basically shrink the frequency meter down to just the 4-digit led + the mcu. Nothing else.

If you take uart output, you don't even need the 4-digit led, :).

And if the frequency is fixed, you don't even need the mcu, just the pcb. ;-)
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #25 on: April 29, 2014, 12:30:30 am »
The firmware now can accomodate both internal oscillator and a crystal: if the crystal is fitted, it would use the crystal; otherwise, it uses the internal oscillator.

It also drives both common anode or common cathode leds.

On internal oscillator, the meter reads 16.14 - 16.15Mhz after being heated by a hairdryer, when fed a 16.128Mhz signal.
================================
https://dannyelectronics.wordpress.com/
 

Offline neslekkim

  • Super Contributor
  • ***
  • Posts: 1305
  • Country: no
Re: Minimalist frequency meter
« Reply #26 on: April 30, 2014, 09:19:16 pm »
I know nothing about PIC and they are not open-source (free) friendly so I'd rather point people toward truly free things, like arduinos and atmel.

Not opensource friendly?, Based on?
 

Offline scientist

  • Frequent Contributor
  • **
  • !
  • Posts: 317
  • Country: 00
  • User banned.
Re: Minimalist frequency meter
« Reply #27 on: April 30, 2014, 11:39:46 pm »
I know nothing about PIC and they are not open-source (free) friendly so I'd rather point people toward truly free things, like arduinos and atmel.

Not opensource friendly?, Based on?

Based on what arduino.cc says ;)
 

Offline Teemo

  • Regular Contributor
  • *
  • Posts: 58
  • Country: ee
Re: Minimalist frequency meter
« Reply #28 on: May 01, 2014, 10:19:02 pm »
Hello dannyf

Do the PIC heat up when running? I notice you do not have any current limiting resistors for the led display. Or are there resistors already inside led panel?
Or is the current limited only by PIC output port internal resistance?
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #29 on: May 01, 2014, 11:05:20 pm »
No current limiting resistors, other than the pin's output resistance.

The current consumption is about 60ma @ 5v (20ma @ 3.3v). The display is slightly dimmer at 3.3v - you would know only if someone had told you so. Running for hours at 5.0v, the chip is not noticeably warmer via finger touch. The surface of the led is slightly warmer.

I used 0.56" leds. So presummably a smaller one will yield lower current consumption, particularly at 3.3v. or lower if you run the LF version.

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #30 on: May 01, 2014, 11:12:34 pm »
Here is the brightness comparison, between 3.3v  (on the left) and 5v (on the right).
================================
https://dannyelectronics.wordpress.com/
 

Offline scientist

  • Frequent Contributor
  • **
  • !
  • Posts: 317
  • Country: 00
  • User banned.
Re: Minimalist frequency meter
« Reply #31 on: May 03, 2014, 03:28:44 am »
Did you use the same exposure/white balance settings?
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #32 on: May 03, 2014, 02:38:29 pm »
The meter works down to 2.1v at least.

At 2.1v, current consumption is 6ma, the led is still readable;
At 2.5v, current consumption is 12ma, and the led looks identical to when it was driven at 3.3v

Quote
Did you use the same exposure/white balance settings?

Same setting, same lighting and the same focus area.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #33 on: May 05, 2014, 11:07:23 pm »
Looks like someone has tried it before: http://www.swharden.com/blog/2014-02-27-directly-driving-7-segment-display-with-avr-io-pins/

The basic hardware arrangement is the same: no current limiting resistors.

His code structure is less flexible, however.
================================
https://dannyelectronics.wordpress.com/
 

Offline Stonent

  • Super Contributor
  • ***
  • Posts: 3824
  • Country: us
Re: Minimalist frequency meter
« Reply #34 on: May 07, 2014, 12:03:08 am »
Looks like someone has tried it before: http://www.swharden.com/blog/2014-02-27-directly-driving-7-segment-display-with-avr-io-pins/

The basic hardware arrangement is the same: no current limiting resistors.

His code structure is less flexible, however.

I built my wife an animated Christmas necklace with a 5x7 LED display directly soldered to an ATTiny2313.

The larger the government, the smaller the citizen.
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #35 on: May 07, 2014, 12:35:18 am »
That's interesting.

I also have an 8-digit version of the code - it drives 8-digit 7-segment led displays. That can be easily remapped to drive a 8x8 led matrix.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #36 on: July 02, 2014, 09:21:16 pm »
Coming back to this meter again.

Since I have only four digits, I thought I would save on the external crystal and go with the internal rc oscillator, running the PIC at 16Mhz.

Here is the meter measuring a 19.44Mhz TCXO (TCO-919R3, 2.5ppm), with the default factory calibration value.

The error rate is 19.46 - 19.44 / 19.44 = 0.10%, not bad for a frequency meter with just two parts (the PIC + LED).
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #37 on: July 02, 2014, 09:32:07 pm »
This particular chip, as well as many other PIC, allows the factory calibration value to be fine-tuned, through OSCTUNE.

I did a series of experiment and here is what I got, again, measuring the same 19.44Mhz oscillator output:

OSCTUNE - Frequency Reading (Mhz)
-3          - 19.53
-2          - 19.52
-1          - 19.50
0          - 19.47
1          - 19.44
2          - 19.43
3          - 19.41

So the default oscillator runs a little bit too slow (-> higher readings). So by trimming the oscillator a little bit faster, we can get more accurate readings.

OSCTUNE = 1 looks to be the right number.

I will revise the firmware so that the osctune value is read off eeprom. This allows the user to calibrate the value to his own oscillator / chip.

Here is a picture of the meter running with OSCTUNE = 1.

The green arrow points to a led that blinks at 1pps -> it indicates gate time / operation of the meter, but more importantly, allows the meter to be trained, in the future, by a high quality reference source, like a gps: with minimal modification, we can make this meter, plus the vctcxo and a gps with 1pps output, into a gps-disciplined oscillator, thus beating the 2.5ppm spec of the tco-919 oscillator we are using.

More on that later.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #38 on: July 02, 2014, 09:57:01 pm »
Here is the simplified schematic.

The led (7 segment 4-digit) sits right on top of the chip. No current limiting resistors.

The code can drive both common anode or common cathode displays: you can leave PB0 either float (for common cathode) or tie it to ground (for common anode).

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #39 on: July 02, 2014, 09:58:24 pm »
Here is the firm ware, compiled by XC8 1.12.

Save it as a .hex file and burn it to the chip.

Code: [Select]
:0400000080314D28D6
:1000080080312000111C0C281110B70A0319B80AF6
:10001800911C47289110BB0A0319BC0A3C08033AF3
:10002800E83003193B06031D472818101708F60087
:100038001608F70096019701181411103808B40033
:100048003708B3003608B2003508B1007708F20067
:100058007608F300F401F5017208B1047308B204DC
:100068007408B3047508B4040330B135B20DB30D88
:10007800B40D890B3928B501B601B701B801803034
:10008800BB01BC018E060B1D09000B118331D12366
:10009800090080314F28FF30F801F901FA01FB010E
:1000A800FC01FD01B101B201B301B401B501B60112
:1000B800B701B801B901BA01BB01BC01BD002000FC
:1000C80065289422803100304A2280313F3A00303E
:1000D800031D7228A6015322803100304A22803144
:1000E8003F3921009800951324000D140A30200090
:1000F800A300A4014923803121008E130E13ED22A1
:100108008031003020000D1C0130FC000530A001BA
:10011800CE228031C830A00041307E2280310330A9
:10012800A001A1015A2280318B1762292730A3012F
:10013800A201A1001030A00088302D07A4001330C0
:10014800C5228031D5218031A12280311422200896
:10015800C13E84310A008031FB00B7228031D521AD
:100168008031A122803114222008C13E84310A0046
:100178008031FA00B7228031D5218031A122803127
:1001880014222008C13E84310A0080318038F900E9
:10019800B7228031D5218031A12280311422200854
:1001A800C13E84310A00803155290330A301A201E0
:1001B800A100E830A000F4302D07A4000130C522CA
:1001C8008031D5218031A122803114222008C13EFE
:1001D80084310A008031FB00B7228031D52180317B
:1001E800A122803114222008C13E84310A008031C6
:1001F800FA00B7228031D5218031A1228031142222
:100208002008C13E84310A008131F900B7228031CB
:10021800D5218031A122803114222008C13E8431A9
:100228000A008131803855296430A0003230A1019C
:10023800A201A3012D07A4000030C5228031D521D9
:100248008031A122803114222008C13E84310A0065
:100258008131FB00B7228031D5218031A122803144
:1002680014222008C13E84310A0081318038FA0006
:10027800B7228031D5218031A12280311422200873
:10028800C13E84310A008131F900B7228031D5217D
:100298008031A122803114222008C13E84310A0015
:1002A8008131F800B7228031D52180312308B00090
:1002B8002208AF002108AE002008AD003408B000C5
:1002C8003308AF003208AE003108AD00003030020C
:1002D800031D782998302F02031D782996302E02A5
:1002E800031D782980302D0203189A280030300227
:1002F800031D88290F302F02031D882942302E0242
:10030800031D882940302D020318D92800303002F7
:10031800031D982900302F02031D982927302E022B
:10032800031D982910302D02031818290A30A0003F
:10033800A101A201A3013008A7002F08A6002E08DA
:10034800A5002D08A40014222008C13E84310A000B
:100358008131FB00B7228031D5218031A122803143
:1003680014222008C13E84310A008131FA00B722E4
:100378008031D5218031A122803114222008C13E4C
:1003880084310A008131F900B7228031D5218031CA
:10039800A122803114222008C13E84310A00813113
:1003A8005529A801A901AA01AB01230822042104A7
:1003B800200403190B2AAC01AC0AA31BE829A035B9
:1003C800A10DA20DA30DE029A835A90DAA0DAB0D0D
:1003D80023082702031DFA2922082602031DFA29E9
:1003E80021082502031DFA2920082402031C052AD6
:1003F8002008A4022108A53B2208A63B2308A73B06
:100408002814A336A20CA10CA00CAC0BE8292B08CD
:10041800A3002A08A2002908A1002808A0000800B3
:1004280023082204210420040319412AA801A80A48
:10043800A31B232AA035A10DA20DA30D1B2A230857
:100448002702031D312A22082602031D312A21080A
:100458002502031D312A20082402031C3B2A2008F8
:10046800A4022108A53B2208A63B2308A73BA336E4
:10047800A20CA10CA00CA80B232A2708A30026086D
:10048800A2002508A1002408A00008002000A4005C
:10049800A0002530A101A10AAD2325080800A70066
:1004A8002630A000A101A10A2708722BA400181069
:1004B8009811981718130339A200220EF039A200D8
:1004C8001808CF39220498001815111021001114AA
:1004D8000B1720002009A2002109A300A20A031972
:1004E800A30A2208B9002308BA0097003908960021
:1004F80018140800A3001C119A01A1007830A13635
:100508002105A2002308033922049C009110210030
:1005180091140B1720002008FF3E9B001C150800B3
:100528002100191799161916991523008C018D01A8
:100538002200910193019D0108002308B0002208C0
:10054800AF002108AE002008AD000A30A000A101CC
:10055800A201A3013008A7002F08A6002E08A500B5
:100568002D08A40008000A30A000A101A201A301DF
:100578003008A7002F08A6002E08A5002D08A40003
:1005880008002E3DA50000302F3DA6000030303D6C
:10059800A7000800A2002100951220002208FF3AB7
:1005A800031DD92A21009515E62A21009511073047
:1005B80020002205A10021001508F8392000210497
:1005C8002100950020002003FF3ABD0095008B16FE
:1005D80008007C08003A0030031901302000A00010
:1005E800A00EA00DA00D0D082006BF3940238031B4
:1005F800A00DA00DA00D0D082006F739402380316D
:10060800A00DA00D0D082006FB3940238031A00E57
:10061800A00D0C082006DF3920068C007C08031D7D
:100628008D1603198D127C08031D8D1403198D1066
:100638007C08031D8C1503198C117C08031D8C1470
:1006480003198C107C08031D0C1403190C107C086A
:10065800031D0D1603190D127C08031D0C16031932
:100668000C127C08031D0C1503190C11C030210055
:100678008C0581308D05080020068D007C08003A25
:10068800003003190130A00008000130A302003037
:10069800A43B230A0319240A03190800E430A10023
:1006A800A20158238031492B21086B23803122086D
:1006B800A100A2010130A1020030A23B210A0319C6
:1006C800220A03190800FF306B2380315E2BA0003B
:1006D800A0032008FF3A031908006C2BA400200887
:1006E800A50023009518752B20002408FF3EA200C2
:1006F800FF3003180030A3002208230091002000D7
:1007080023082300920095132000A1032108FF3A33
:1007180003190800230095188E2B20002508860051
:1007280087010108230093002000A50A2300910AED
:100738000319920A03108B1B03148B1315155530DC
:100748009600AA30960095141511031C882B8B1758
:10075800882BA2002208A30023009518B02B2000A4
:1007680020082300910092012000A1032108FF3AEC
:100778000319080023009518BE2B951315142000A3
:100788002308860087012300130881002000A30A9C
:100798002300910A0319920AB82B7C08BA248331E2
:1007A800F00EF00DF00D0D087006BF3970068D00C3
:1007B8007C08BA248331F00DF00DF00D0D08700699
:1007C800F73970068D007C08BA248331F00DF00DDE
:1007D8000D087006FB3970068D007C08BA24833139
:1007E800F00EF00D0C087006DF3970068C007D08DD
:1007F800783E860087010108F100711C0E2C7C08E8
:10080800BA248331F00EF00D0D087006DF3970063A
:100818008D00132C7C08031D8D1603198D12F11CF5
:100828001F2C7C08BA248331F00D0D087006FD39A1
:1008380070068D00242C7C08031D8D1403198D105F
:10084800711D322C7C08BA248331F00DF00DF00DA7
:100858000C087006F73970068C00372C7C08031DCD
:100868008C1503198C11F11D432C7C08BA24833193
:10087800F00D0C087006FD3970068C00482C7C08B9
:10088800031D8C1403198C10711E522C7C08BA2479
:1008980083310C06FE3970068C00572C7C08031D2A
:1008A8000C1403190C10F11E632C7C08BA24833134
:1008B800F00E0D087006EF3970068D00682C7C0864
:1008C800031D0D1603190D12711F742C7C08BA2410
:1008D8008331F00E0C087006EF3970068C00792C05
:1008E8007C08031D0C1603190C12F11F862C7C08BA
:1008F800BA248331F00DF00D0C087006FB39700630
:100908008C00AB2C7C08031D0C1503190C11AB2CA7
:100918007C08031D0D1703190D13FD01FD0A0800BE
:100928007C08031D8D1503198D110230FD00080088
:100938007C08031D0D1503190D110330FD00080077
:100948007C08031D8C1603198C12FD0108007D0814
:10095800003A03198C2C013A0319942C033A031911
:100968009C2C013A0319A42C8C2C0800003A003066
:1009780003190130F000080000343F3406345B34BA
:100988004F3466346D347D3407347F346F345F34CC
:0C0998007C3458345E34793471340034FF
:020000040001F9
:04000E0084C9FFDCC6
:02E0000000001E
:00000001FF
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #40 on: July 02, 2014, 10:05:38 pm »
Burning the hex code:

when you burn the code, you can burn the desired value of OSCTUNE (in 2's compliment) into 0x00 of the eeprom - see the picture below for an example of burning OSCTUNE = 0x01.

In this case, my intosc is too slow so I have to tune it faster -> a positive value.

If your intosc is too fast, you have to tune it down  a little bit -> use a negative value (in 2's compliment, so -1 = 0b111111 = 0x3f, -2 = 0b111110 = 0x3e, ...).

Calibration:

On a virgin chip (eeprom 0x00 has a value of 0xff), the firmware will zero it (so eeprom 0x00 has a value of 0x00), and the default factory calibration is used (1% accuracy per Microchip but typically better than that, as we saw earlier).

If you have a high stability oscillator, you can use the meter to measure the frequency.

Based on the frequency reading from the meter, you can reburn the same firmware, with different values in eeprom 0x00 to get the ferquency reading as close to the known frequency of the reference oscillator as possible.

Then you are done.

================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #41 on: July 04, 2014, 11:39:45 am »
One small improvement.

When running on a high stability clock (like the TCO-919R3 I am experimenting with now), it would be helpful to display more than 4 digits. In fact, 8 digits would be nice.

So here is one version of the minimalist meter running on the TCO-919R3 (19.44Mhz) measuring its own clock. In this case, the meter is alternating showing its highest 4 digits and then lowest 4 digits on a 4-digit led display. To signify the lowest 4 digits, the last digit has its dot segment turned on.

Here the reading should be exactly 1944,0000. Instead, we got 1943,9997. The difference of 3Hz is due to our inability to truly synchronize the time base and the pulse counter.
================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #42 on: July 04, 2014, 01:58:28 pm »
A couple more examples.

1) a 16.128Mhz +/- 100ppm oscillator (EC1100 by Ecliptek).

16,128,000Hz spec vs. 16,127,893Hz actual.

100ppm spec vs. 6.6ppm actual.


================================
https://dannyelectronics.wordpress.com/
 

Offline dannyfTopic starter

  • Super Contributor
  • ***
  • Posts: 8221
  • Country: 00
Re: Minimalist frequency meter
« Reply #43 on: July 04, 2014, 02:01:17 pm »
Example 3: a 8Mhz Epson crystal

8,000,000Hz spec vs. 7,999,792Hz.

20ppm (likely spec) vs. 26ppm.

Maybe the load capacitance was too high.
================================
https://dannyelectronics.wordpress.com/
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf