Website URL

Location

Interests

Sparkfun

Github

From time to time, threads pop up where someone tries to count very fast pulses in the hundreds of kHz or even MHz range. There is a solution for the hardcore C-coders among us, but to my surprise there was no Energia library for this simple problem.
I herewith present the CounterLib for Energia
Download
Source code and detailed instructions are also available on GitHub:
https://github.com/astuder/CounterLib-Energia
Currently the library supports MSP430G2553, MSP430F5529 and MSP430FR5969.
To create an instance of the counter, simply declare it as a global variable like this:
Counter<> MyCounter; // create a counter that counts pulses on pin P1.0Once created, the counter has 5 functions:start() initializes the timer peripheral and I/O pin and starts the counter
stop() stops the counter, but does not reset the counter value
read() reads the current value of the counter
reset() resets the counter to 0, the counter keeps running
readAndReset() reads the current value and resets the counter to 0
And a basic example, which should work for signals lower than 65 kHz:
Counter<> MyCounter; // create counter that counts pulses on pin P1.0
void setup()
{
Serial.begin(9600);
MyCounter.start(); // start counter
}
void loop()
{
MyCounter.reset(); // reset counter to zero
delay(1000); // wait one second
Serial.println(MyCounter.read()); // read number of pulses during the last second
delay(1000); // wait another second
}
The library also supports dividers to measure much faster signals. For more detailed instructions see GitHub.
The library uses the external clock input of the timer peripheral. This enables the library to measure very fast signals (MHz range). On the downside, each timer only has a specific pin assigned, and the G2553 only has one timer with an external pin. It is also possible, that other Energia libraries or built-in functionality use the same timer, which won't work.
Here's a list of the timers supported by the library and their pins:
| Timer | G2553,| | | |
| | G2452,| F5529 | FR5969 | FR6989 |
| | G2231 | | | |
|------------|-------|-------|--------|--------|
| CL_TimerA0 | P1.0 | P1.0 | P1.2 | P1.2* |
| CL_TimerA1 | n/a | P1.6 | P1.1* | P1.1* |
| CL_TimerA2 | n/a | P2.2 | n/a | n/a |
| CL_TimerB0 | n/a | P7.7*| P2.0* | P2.0 |Pins marked with * are not broken out on the LaunchPad or are difficult to access.
The library probably works on many other MSP430's, but you'll need to adjust the #defines in the library. Please report back if you successfully tested with other devices, so that I can extend the library.
Please report any bugs.
And also let me know if you break any speed records. So far I only tested it up to 750 kHz.
Edit 9/3/15: Added support for FR5969. Thanks @@Fmilburn
Edit 9/4/15: Refactored to make it easier to add more MCUs. Several bug fixes, thanks to all the eagle-eyed members of 43oh
Edit 3/13/16: Replaced attached ZIP file with link to GitHub to always give up-to-date version

This is a heart beat counter, which displays the result on an LCD, it amplifies the signal by a dual op amp IC, and passes it to msp, as an interupt to count the number of pulse for 15 secs, it uses internal clock, so its not so accurate, but it will give you a good precised result...
i have given all the neccassary information, including the schematic, the video link, and the code, with the header file..
here is its video...
see the instructions to build it at
http://www.instructables.com/id/Heart-Beat-Counter-using-MSP430/
lcd.h
main.c