ak96 4 Posted May 6, 2016 Share Posted May 6, 2016 The code is for a heartbeat sensor using the MSP430. Which part is responsible for actually counting the pulses? lcd (1).h main.txt Quote Link to post Share on other sites
chicken 630 Posted May 6, 2016 Share Posted May 6, 2016 The code in main.txt sets up interrupts that are triggered when pins change from high to low (falling edge). A counter J is increased by some of these interrupts. That being said, the code has quite a few issues. If this is not your code, I would look for a better example as this one will cause a lot of grief to get working. If it is your code, I suggest to first think about the structure of the program before reattempting the implementation. A few issues: - the variable j used by the interrupt routine to keep track of the pulses should be declared as volatile. - the setup of interrupts that configure interrupts is very convoluted and without further documentation, it will be hard to figure out how they interact and how the program is supposed to work - there are several interrupt routines that include printing out of date, this is bad practice and almost certainly will create issues. gsutton and tripwire 2 Quote Link to post Share on other sites
chicken 630 Posted May 6, 2016 Share Posted May 6, 2016 PS: If you're new to programming, take a look at Energia. There's a library for Energia, that makes it easy to count pulses with the MSP430. http://forum.43oh.com/topic/8870-energia-library-hardware-counter-library-for-msp430/ gsutton 1 Quote Link to post Share on other sites
ak96 4 Posted May 6, 2016 Author Share Posted May 6, 2016 @@chicken I am new to programming micro controllers. I only started a couple of days ago. I'm kind of uncomfortable using that energia library because it feels like...cheating. The project i'm working on is a heartbeat sensor with a physical circuit and micro controller to count the beats. I want to make this project from scratch as a learning experience, and using a library that does all of the work for me defeats that purpose I think. Also, that is not my code. I found it on an instructable. So far, I've just learned how to blink LED's in different patterns at different speeds using interrupts and timers. What should I focus on learning to be able to make the heart rate monitor? Is there anything in particular I should look into? cubeberg and chicken 2 Quote Link to post Share on other sites
cubeberg 540 Posted May 6, 2016 Share Posted May 6, 2016 At least in the MSP430 line, each mcu family has a bunch of examples that go with it. If you're looking to go lower level than Energia (I prefer code composer for MSP430 as it's a pretty simple chip) - there are some great examples there. There should be some timer examples - which allow you to count the number of ticks between events. They also come with comments at the top of the file that explain what it does. http://www.ti.com/product/MSP430G2553/toolssoftware#softTools - download the "Code Examples". gsutton, Fmilburn and tripwire 3 Quote Link to post Share on other sites
chicken 630 Posted May 6, 2016 Share Posted May 6, 2016 @@ak96 Nothing wrong with preferring bare metal, my preference as well Take a look at the innards of the counter library, even if you don't plan to use Energia. It basically sets up a timer to count up when a pin changes from 0 to 1. Using the timer, you don't need an interrupt for the counting itself. The source code of the library may look a bit cryptic, because it tries to accommodate many different MSP430s. The gist is: 1. Set GPIO pin as input and select it's function (PxSEL) as timer input. The timer input (TxxCLK) is only available on a few pins, consult your MCUs datasheet. 2. Configure timer for external clock and continuous mode 3. Functions to start, stop and reset the timer as well as reading out the current timer value. Run the timer for a known time, and the number of pulses will allow to determine the rate. That being said, not sure if that's the best approach for a heart rate monitor. Measuring the time between pulses might be more sensible: 1. Start the timer, driven by one of the MSP's internal clocks. Use a divider to avoid overflowing the 16bit timer for the expected heart rate. 2. Wait for a pulse on a pin. A busy loop reading the pin is probably good enough for a beginner project. 3. When a pulse arrives, read the timer value. 4. Calculate the rate using clock frequency, timer divider and measured timer value. I don't know what output signal heart rate monitors provide. If it's an analog wave form, you may need some circuitry to convert it to something that is usable for digital inputs and/or use the built-in comparator or ADC peripherals. tripwire, Fmilburn and gsutton 3 Quote Link to post Share on other sites
dubnet 238 Posted May 6, 2016 Share Posted May 6, 2016 @ak96 Did a google search and came up with a few more that may be helpful in terms of code/design examples. http://www.ti.com/tool/tida-00011 https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/19208 https://e2e.ti.com/support/microcontrollers/msp430/f/166/t/94878 http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/EKG-Based-Heart-Rate-Monitor/1_00_00_00/index_FDS.html Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.