Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Freq computation without DIV instruction for 8bit MCU

Status
Not open for further replies.

Harmonica

Newbie level 3
Joined
Jan 24, 2020
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
29
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?
 

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?

Klaus
 
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).
 
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?

Klaus

8Bit STM8S MCU, 16MHz clock, Timer clock - 250KHz, Expected freq input to the Timer Capture unit is 0-200Hz.
I haven't used Float variables and no Math or standard libraries. C language Cosmic Compiler.
 

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.
 

Hi,

LUT does not neccessarily be in SRAM.

But an integer division should be fast. But without ranges...accuracy, resolution...

Klaus
 

Mandatory/What can't be changed:- MCU and timer capture is fixed. the clock source can be modified with prescalar.

Your requirements are restrictive; you could consider setting timer scaler to a interval between acquisitions as a rational number power of two, so that division could be replaced by a simple right shift (>>) operation.

For example, by setting timer period as 1,024s, the division operation can be made by right-shifting 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.
 

For example, by setting timer period as 1,024s, the division operation can be made by right-shifting 10 digits
If you perform only 1 measurement per second, 40 µs division time (0.004 %) would be absolutely no issue. But I guess 1 Hz is too slow. For reasonable measurement rate and resolution, you are tied to (multi-)periode measurement method and hence need division step.

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?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top