TI E2E Community
MSP430 Ultra-Low Power 16-bit Microcontroller Forum
Timer_A frequency counter
I'm currently a student at UTD and I plan to use the MSP 430 as part of my project. The plan was to use the MSP to calculate the speed of a vehicle from the input feeding from a motion sensor attached on the wheel. Can anyone show me how to implement a frequency counter like in the MSP430FG4618 on the MSP430FG4618/F2013 experimental board? I got all the input/output parts and got the MSP 4618 to recognize the signal on and off but I have trouble with calculating the frequency of input signal using the timer_A module. Thank you and best regards,
There are several possible solution for this. It all depends on expected data range and required resolution
The best but most complex way is to go with the capture/compare features.
Set up the timer to run at a speed that is high enough for your wanted resolution. So if you want to detect the wheel turnaround time on 1µs resolution, set the timer to an input frequency of 1Mhz. Let the timer free-running in up mode.
Next is setting an interrupt function that detects a timer overrun and increases a counter. This way the timer is extended to 24, 32 or 48 bit resolution.
Another ISR is attached as capture interrupt for the input where your signal comes in. In the very moemnt the signal arrives, the capture ISR is called and you can read the accurate timer value (16 bit) in the moment of your signal. Together with the counter of timer overruns you can build a difference between lat time and this time and thus the frequency of wheel rotation and the resulting speed (based on wheel diameter).
If your sensor gives more than one signal per rotation period, you can also set up one timer as a counter and calculate the number of pulses in a given time period (based on another timer). This is better if you only need to know how many impulses you got per second/display update. As you don't need the processor in the meantime, you can set it to sleep as the counter will continue and you only need to wake up if a second has passed. This preserves much energy compared to the first approach and is best for battery use, but you only get an average speed per second/interval instead of the momentary speed per rotation. And if the wheel rotates so slow that it gives less than an impulse per interval, you will get zero speed in one and a too high reading in the next.
In my car they used the second method, so the display goes off below ~5km/h as the fuel consumption calculation would give a division by zero error.
Thjere's a third method where you start the timer with the raising/fallign edge of the signal and stop if with the other, read the timer count of passed clock cycles and know the wavelength of your input signal. but depending on the expected value range, this might be a problem on the edges. E.g. if the wheel stopped, the timer will run and run and you'll never get an information update, so you'll need to implement a timeout,e.g. at timer overrun. And if the wheel stops in the 'other' half of the signal cycle, you'll never start a measurement and never get an updated frequency information.
it's not easy to do things 'right' including the border conditions.
_____________________________________Before posting bug reports or ask for help, do at least quick scan over this article. It applies to any kind of problem reporting. On any forum. And/or look here.If you cannot discuss your problem in the public, feel free to start a private conversation: click on my name and then 'start conversation'. But please do so only if you really cannot do it in a public thread, as I usually read all threads. And I prefer to answer where others can profit from it (or contribute to it) too.
Hi thanks for your post. I also have similar project to do in my coursework. I was told to design a counter that will counter the rotation of a car engine in one second. An 8051 microcontroller is to act as the counter. the results is to be displayed on a 4 digit seven segment. I have finished my hardware but I don't know how to the program in C that will make the microcontroller act as the counter. All this are very new to me I am only in my first year. I will be very appreciative if you can help me with the code thanks
Well, it's quite some time (~25 years) since I last worked with an 8051 and I didn't code in C back then.So I cannot give you more help than the general description above.(btw, you noticed that his is an MSP430 forum?)
All content and materials on this site are provided "as is". TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with regard to these materials, including but not limited to all implied warranties and conditions of merchantability, fitness for a particular purpose, title and non-infringement of any third party intellectual property right. TI and its respective suppliers and providers of content make no representations about the suitability of these materials for any purpose and disclaim all warranties and conditions with respect to these materials. No license, either express or implied, by estoppel or otherwise, is granted by TI. Use of the information on this site may require a license from a third party, or a license from TI.
TI is a global semiconductor design and manufacturing company. Innovate with 100,000+ analog ICs andembedded processors, along with software, tools and the industry’s largest sales/support staff.