+ Post New Thread
Results 1 to 8 of 8

24th January 2020, 06:26 #1
 Join Date
 Jan 2020
 Posts
 3
 Helped
 0 / 0
 Points
 24
 Level
 1
Freq computation without DIV instruction for 8bit MCU
I am using 8bit MCU.
Configuration: Timer Capture to measure pulse width.
S/W Computation:  Using pulse width calculate Frequency using formula  (Clock frequency/pulse width) << 2
Problem: The division instruction is taking 40usec which is too much overhead for the kind of application I am working on.
Probable Remedy: I was thinking to work out any alternative where I should not use DIV instruction and yet should be able to compute the frequency.
Mandatory/What can't be changed: MCU and timer capture is fixed. the clock source can be modified with prescalar.
Any help?

Advertisement

24th January 2020, 08:11 #2
Awards:
 Join Date
 Apr 2014
 Posts
 16,449
 Helped
 3731 / 3731
 Points
 81,102
 Level
 69
Re: Freq computation without DIV instruction for 8bit MCU
Hi,
40us?? Why that much time?
Floating point? > try integer solutions (what input values range, what expected calculation resolution and accuracy?)
What microcontroller, what clock frequency, what language, libraries and compiler do you use?
KlausPlease donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.
1 members found this post helpful.

24th January 2020, 11:01 #3
 Join Date
 Apr 2011
 Location
 Minneapolis, Minnesota, USA
 Posts
 13,105
 Helped
 2614 / 2614
 Points
 53,754
 Level
 56
Re: Freq computation without DIV instruction for 8bit MCU
Consider creating a lookup table. Say you want two digits of precision... Then you need an array of 100 elements. Exponents are a simple matter of reversing the sign (positive to negative, negative to positive).
1 members found this post helpful.

Advertisement

24th January 2020, 13:14 #4
 Join Date
 Jan 2020
 Posts
 3
 Helped
 0 / 0
 Points
 24
 Level
 1

24th January 2020, 13:15 #5
 Join Date
 Jan 2020
 Posts
 3
 Helped
 0 / 0
 Points
 24
 Level
 1
Re: Freq computation without DIV instruction for 8bit MCU
Thought of doing that too.... but since it is low end 8bit MCU... the available RAM is only 2K... I can't afford to use LUT.

24th January 2020, 20:28 #6
Awards:
 Join Date
 Apr 2014
 Posts
 16,449
 Helped
 3731 / 3731
 Points
 81,102
 Level
 69
Re: Freq computation without DIV instruction for 8bit MCU
Hi,
LUT does not neccessarily be in SRAM.
But an integer division should be fast. But without ranges...accuracy, resolution...
KlausPlease donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.

25th January 2020, 01:48 #7
 Join Date
 Nov 2006
 Location
 Brazil
 Posts
 8,984
 Helped
 1138 / 1138
 Points
 30,107
 Level
 42
 Blog Entries
 9
Re: Freq computation without DIV instruction for 8bit MCU
Mandatory/What can't be changed: MCU and timer capture is fixed. the clock source can be modified with prescalar.
For example, by setting timer period as 1,024s, the division operation can be made by rightshifting 10 digits, so if e.g 512 pulses are accounted during this time, the computed frequency is 500Hz with a reasonable resolution.
Needless to say that a timer with the largest magnitude should be choosen; many 8 bit MCU's have either 8 and 16 bits timers available.
Part of the world that you live in, You are the part that you're giving ( Renaissance )

Advertisement

25th January 2020, 11:49 #8
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 46,168
 Helped
 14041 / 14041
 Points
 264,236
 Level
 100
Re: Freq computation without DIV instruction for 8bit MCU
For example, by setting timer period as 1,024s, the division operation can be made by rightshifting 10 digits
Although the specification is incomplete (didn't mention measurement rate, resolution, minimal input frequency), I presume long unsigned (uint32) arithmetic is used here. Thus tables are hardly an option. However, if you choose a rate equal to the maximum input frequency of 200 Hz, what's the problem with spending 40 ĩs for the calculation?
+ Post New Thread
Please login