CAN I read 100Khz frequency using MC9S12XHZ512 Micro-controller ?
Hi,
I would like to add. There are two methods of frequency measurement.
1) Counting of BUSCLK/PRESCALER periods of internal timer between two incoming external pulses. This is suitable for lower frequencies. For higher frequencies it is not suitable because there is to high difference between two measurable frequencies.
The measurement precision is df which can be expressed as: df = BUSCLK / ((n^2 + n) * PRESCALER); n = measured number of TCNT periods
For example: BUSCLK = 16MHz, PRESCALER = 1
n | f | df | n | f | df | n | f | df | n | f | df | n | f | df |
1 | 8000000 | 5333333 | 26 | 22792,02 | 1628,002 | 51 | 6033,183 | 227,6673 | 76 | 2734,108 | 70,10533 | 101 | 1553,096 | 30,15721 |
2 | 2666667 | 1333333 | 27 | 21164,02 | 1459,588 | 52 | 5805,515 | 215,0191 | 77 | 2664,003 | 67,44311 | 102 | 1522,939 | 29,28729 |
3 | 1333333 | 533333,3 | 28 | 19704,43 | 1313,629 | 53 | 5590,496 | 203,2908 | 78 | 2596,56 | 64,91399 | 103 | 1493,652 | 28,45051 |
4 | 800000 | 266666,7 | 29 | 18390,8 | 1186,504 | 54 | 5387,205 | 192,4002 | 79 | 2531,646 | 62,50977 | 104 | 1465,201 | 27,64531 |
5 | 533333,3 | 152381 | 30 | 17204,3 | 1075,269 | 55 | 5194,805 | 182,2739 | 80 | 2469,136 | 60,22282 | 105 | 1437,556 | 26,87021 |
6 | 380952,4 | 95238,1 | 31 | 16129,03 | 977,5171 | 56 | 5012,531 | 172,8459 | 81 | 2408,913 | 58,0461 | 106 | 1410,686 | 26,12381 |
7 | 285714,3 | 63492,06 | 32 | 15151,52 | 891,2656 | 57 | 4839,685 | 164,0571 | 82 | 2350,867 | 55,97302 | 107 | 1384,562 | 25,40481 |
8 | 222222,2 | 44444,44 | 33 | 14260,25 | 814,8714 | 58 | 4675,628 | 155,8543 | 83 | 2294,894 | 53,9975 | 108 | 1359,157 | 24,71195 |
9 | 177777,8 | 32323,23 | 34 | 13445,38 | 746,9655 | 59 | 4519,774 | 148,1893 | 84 | 2240,896 | 52,11387 | 109 | 1334,445 | 24,04406 |
10 | 145454,5 | 24242,42 | 35 | 12698,41 | 686,4007 | 60 | 4371,585 | 141,0189 | 85 | 2188,782 | 50,31684 | 110 | 1310,401 | 23,40002 |
11 | 121212,1 | 18648,02 | 36 | 12012,01 | 632,2112 | 61 | 4230,566 | 134,3037 | 86 | 2138,466 | 48,60149 | 111 | 1287,001 | 22,77878 |
12 | 102564,1 | 14652,01 | 37 | 11379,8 | 583,5795 | 62 | 4096,262 | 128,0082 | 87 | 2089,864 | 46,96324 | 112 | 1264,223 | 22,17934 |
13 | 87912,09 | 11721,61 | 38 | 10796,22 | 539,8111 | 63 | 3968,254 | 122,1001 | 88 | 2042,901 | 45,3978 | 113 | 1242,043 | 21,60075 |
14 | 76190,48 | 9523,81 | 39 | 10256,41 | 500,3127 | 64 | 3846,154 | 116,5501 | 89 | 1997,503 | 43,90117 | 114 | 1220,442 | 21,04211 |
15 | 66666,67 | 7843,137 | 40 | 9756,098 | 464,5761 | 65 | 3729,604 | 111,3315 | 90 | 1953,602 | 42,46961 | 115 | 1199,4 | 20,50257 |
16 | 58823,53 | 6535,948 | 41 | 9291,521 | 432,1638 | 66 | 3618,272 | 106,4198 | 91 | 1911,132 | 41,09962 | 116 | 1178,898 | 19,98132 |
17 | 52287,58 | 5503,956 | 42 | 8859,358 | 402,6981 | 67 | 3511,853 | 101,7928 | 92 | 1870,033 | 39,78793 | 117 | 1158,916 | 19,47759 |
18 | 46783,63 | 4678,363 | 43 | 8456,66 | 375,8515 | 68 | 3410,06 | 97,43028 | 93 | 1830,245 | 38,53147 | 118 | 1139,439 | 18,99065 |
19 | 42105,26 | 4010,025 | 44 | 8080,808 | 351,3395 | 69 | 3312,629 | 93,3135 | 94 | 1791,713 | 37,32736 | 119 | 1120,448 | 18,5198 |
20 | 38095,24 | 3463,203 | 45 | 7729,469 | 328,9136 | 70 | 3219,316 | 89,42544 | 95 | 1754,386 | 36,17291 | 120 | 1101,928 | 18,0644 |
21 | 34632,03 | 3011,481 | 46 | 7400,555 | 308,3565 | 71 | 3129,89 | 85,75042 | 96 | 1718,213 | 35,06557 | 121 | 1083,864 | 17,6238 |
22 | 31620,55 | 2635,046 | 47 | 7092,199 | 289,4775 | 72 | 3044,14 | 82,27405 | 97 | 1683,147 | 34,00298 | 122 | 1066,24 | 17,19742 |
23 | 28985,51 | 2318,841 | 48 | 6802,721 | 272,1088 | 73 | 2961,866 | 78,98309 | 98 | 1649,145 | 32,98289 | 123 | 1049,043 | 16,78468 |
24 | 26666,67 | 2051,282 | 49 | 6530,612 | 256,1024 | 74 | 2882,883 | 75,86534 | 99 | 1616,162 | 32,0032 | 124 | 1032,258 | 16,38505 |
25 | 24615,38 | 1823,362 | 50 | 6274,51 | 241,3273 | 75 | 2807,018 | 72,90955 | 100 | 1584,158 | 31,06193 | 125 | 1015,873 | 15,998 |
2) counting incoming external pulses during defined period. It is clear that this measurement is not suitable for low frequencies which require long test period.
So you have to do some compromise if you want to measure wide frequency range or create more complex solution.
The MCU busclock can work up to 40MHz. You need minimally 2busclocks to recognize edge. So, if I think about 2 clocks for rising edge and 2 clocks for falling edge then maximum frequency you can measure is 40MHz/4 = 10MHz. The issue is how you want to calculate it. Let's consider 100.000kHz frequency of rising edges. In this case you have 10us to process the value which means 400buscycles @ 40MHz busclk.
In dependence on processing time you can:
As an example I have attached two example project for another MCU but the same approach.
BTW; please do not ask me how to do it in Processor Expert. I do not use it.
If you see this answer as correct answer please mark it as correct and helpful to help others to find good answers faster. Thank you in advance.
Best Regards, Ladislav